Skip to content

Add simple json file export, do not crash on bad projects #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ _Examine a specific project or solution to make sure there are no pre-release pa
> snitch MyProject.csproj --no-prerelease
```

_Examine a specific project or solution and export the result to a json file

```
> snitch MyProject.csproj --out c:\temp\snitch.json
```

That json file can be also used e.g. to auto-uninstall the detected packages in package manager console in Visual Studio:
```
function Uninstall-FromSnitch { param($filename) (Get-Content $filename | ConvertFrom-Json) | %{ $p = $_.Project; foreach ($c in $_.CanBeRemoved) { Uninstall-Package $c.PackageName -ProjectName $p } } }
Uninstall-FromSnitch C:\temp\snitch.json
```


## Building Snitch from source

```
Expand Down
8 changes: 8 additions & 0 deletions src/Snitch.Tests.Fixtures/FooBar/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace Baz
{
public class Class1
{
}
}
8 changes: 8 additions & 0 deletions src/Snitch.Tests.Fixtures/FooBar/FooBar.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
</PropertyGroup>

</Project>
14 changes: 14 additions & 0 deletions src/Snitch.Tests/Expectations/Baz.Json.verified.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"Project": "Baz",
"CanBeRemoved": [
{
"PackageName": "Autofac",
"PackageVersion": "4.9.4",
"ReferencedBy": "Foo"
}
],
"MightBeRemoved": [],
"PreRelease": []
}
]
6 changes: 6 additions & 0 deletions src/Snitch.Tests/Expectations/FooBar.Default.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Analyzing...
Analyzing FooBar.csproj
Analyzing FooBar...
ERROR: Value cannot be null. (Parameter 'folderName')

Everything looks good!
4 changes: 4 additions & 0 deletions src/Snitch.Tests/Expectations/FooBar.Strict.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Analyzing...
Analyzing FooBar.csproj
Analyzing FooBar...
ERROR: Value cannot be null. (Parameter 'folderName')
87 changes: 87 additions & 0 deletions src/Snitch.Tests/Expectations/Solution.Json.verified.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[
{
"Project": "Bar",
"CanBeRemoved": [
{
"PackageName": "Autofac",
"PackageVersion": "4.9.4",
"ReferencedBy": "Foo"
}
],
"MightBeRemoved": [],
"PreRelease": []
},
{
"Project": "Baz",
"CanBeRemoved": [
{
"PackageName": "Autofac",
"PackageVersion": "4.9.4",
"ReferencedBy": "Foo"
}
],
"MightBeRemoved": [],
"PreRelease": []
},
{
"Project": "Qux",
"CanBeRemoved": [],
"MightBeRemoved": [
{
"PackageName": "Autofac",
"PackageVersion": "4.9.3",
"ReferencedBy": "Foo",
"ReferencePackageVersion": "4.9.4"
}
],
"PreRelease": []
},
{
"Project": "Zap",
"CanBeRemoved": [],
"MightBeRemoved": [
{
"PackageName": "Newtonsoft.Json",
"PackageVersion": "12.0.3",
"ReferencedBy": "Foo",
"ReferencePackageVersion": "12.0.1"
},
{
"PackageName": "Autofac",
"PackageVersion": "4.9.3",
"ReferencedBy": "Foo",
"ReferencePackageVersion": "4.9.4"
}
],
"PreRelease": []
},
{
"Project": "Thud",
"CanBeRemoved": [],
"MightBeRemoved": [],
"PreRelease": [
{
"PackageName": "Newtonsoft.Json",
"PackageVersion": "13.0.2-beta2"
}
]
},
{
"Project": "Thuuud",
"CanBeRemoved": [],
"MightBeRemoved": [
{
"PackageName": "Newtonsoft.Json",
"PackageVersion": "13.0.2-beta2",
"ReferencedBy": "Foo",
"ReferencePackageVersion": "12.0.1"
}
],
"PreRelease": [
{
"PackageName": "Newtonsoft.Json",
"PackageVersion": "13.0.2-beta2"
}
]
}
]
117 changes: 92 additions & 25 deletions src/Snitch.Tests/ProgramTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Shouldly;
using Snitch;
using System;
using System.IO;
using System.Threading.Tasks;
Expand All @@ -9,7 +8,7 @@
using Xunit;
using VerifyXunit;

namespace Sntich.Tests
namespace Snitch.Tests
{
[UsesVerify]
public class ProgramTests
Expand All @@ -19,7 +18,6 @@ public class ProgramTests
public async Task Should_Return_Expected_Result_For_Baz_Not_Specifying_Framework()
{
// Given
var fixture = new Fixture();
var project = Fixture.GetPath("Baz/Baz.csproj");

// When
Expand All @@ -30,12 +28,27 @@ public async Task Should_Return_Expected_Result_For_Baz_Not_Specifying_Framework
await Verifier.Verify(output);
}

[Fact]
[Expectation("Baz", "Json")]
public async Task Should_Return_Expected_Json_For_Baz_Not_Specifying_Framework()
{
// Given
var project = Fixture.GetPath("Baz/Baz.csproj");

// When
using var tempFileScope = new TempFileScope();
var (exitCode, _) = await Fixture.Run(project, "--out", tempFileScope.FileName);

// Then
exitCode.ShouldBe(0);
await Verifier.VerifyFile(tempFileScope.FileName);
}

[Fact]
[Expectation("Solution", "Default")]
public async Task Should_Return_Expected_Result_For_Solution_Not_Specifying_Framework()
{
// Given
var fixture = new Fixture();
var solution = Fixture.GetPath("Snitch.Tests.Fixtures.sln");

// When
Expand All @@ -46,12 +59,27 @@ public async Task Should_Return_Expected_Result_For_Solution_Not_Specifying_Fram
await Verifier.Verify(output);
}

[Fact]
[Expectation("Solution", "Json")]
public async Task Should_Return_Expected_Json_For_Solution_Not_Specifying_Framework()
{
// Given
var solution = Fixture.GetPath("Snitch.Tests.Fixtures.sln");

// When
using var tempFileScope = new TempFileScope();
var (exitCode, _) = await Fixture.Run(solution, "--out", tempFileScope.FileName);

// Then
exitCode.ShouldBe(0);
await Verifier.VerifyFile(tempFileScope.FileName);
}

[Fact]
[Expectation("Baz", "netstandard2.0")]
public async Task Should_Return_Expected_Result_For_Baz_Specifying_Framework()
{
// Given
var fixture = new Fixture();
var project = Fixture.GetPath("Baz/Baz.csproj");

// When
Expand All @@ -67,7 +95,6 @@ public async Task Should_Return_Expected_Result_For_Baz_Specifying_Framework()
public async Task Should_Return_Non_Zero_Exit_Code_For_Baz_When_Running_With_Strict()
{
// Given
var fixture = new Fixture();
var project = Fixture.GetPath("Baz/Baz.csproj");

// When
Expand All @@ -83,7 +110,6 @@ public async Task Should_Return_Non_Zero_Exit_Code_For_Baz_When_Running_With_Str
public async Task Should_Return_Expected_Result_For_Baz_When_Excluding_Library()
{
// Given
var fixture = new Fixture();
var project = Fixture.GetPath("Baz/Baz.csproj");

// When
Expand All @@ -99,7 +125,6 @@ public async Task Should_Return_Expected_Result_For_Baz_When_Excluding_Library()
public async Task Should_Return_Expected_Result_For_Baz_When_Skipping_Project()
{
// Given
var fixture = new Fixture();
var project = Fixture.GetPath("Baz/Baz.csproj");

// When
Expand All @@ -115,7 +140,6 @@ public async Task Should_Return_Expected_Result_For_Baz_When_Skipping_Project()
public async Task Should_Return_Expected_Result_For_Baz_When_Skipping_Project_And_NoReleases()
{
// Given
var fixture = new Fixture();
var project = Fixture.GetPath("Baz/Baz.csproj");

// When
Expand All @@ -131,7 +155,6 @@ public async Task Should_Return_Expected_Result_For_Baz_When_Skipping_Project_An
public async Task Should_Return_Non_Zero_Exit_Code_For_Baz_When_Running_With_Strict_And_NoPreRelease()
{
// Given
var fixture = new Fixture();
var project = Fixture.GetPath("Baz/Baz.csproj");

// When
Expand All @@ -147,7 +170,6 @@ public async Task Should_Return_Non_Zero_Exit_Code_For_Baz_When_Running_With_Str
public async Task Should_Return_Non_Zero_Exit_Code_For_Thud_When_Running_With_Strict_And_NoPreRelease()
{
// Given
var fixture = new Fixture();
var project = Fixture.GetPath("Thud/Thud.csproj");

// When
Expand All @@ -163,7 +185,6 @@ public async Task Should_Return_Non_Zero_Exit_Code_For_Thud_When_Running_With_St
public async Task Should_Return_Non_Zero_Exit_Code_For_Thuuud_When_Running_With_Strict_And_NoPreRelease()
{
// Given
var fixture = new Fixture();
var project = Fixture.GetPath("Thuuud/Thuuud.csproj");

// When
Expand All @@ -179,7 +200,6 @@ public async Task Should_Return_Non_Zero_Exit_Code_For_Thuuud_When_Running_With_
public async Task Should_Return_Zero_Exit_Code_For_Thuuud_When_Running_With_NoPreRelease()
{
// Given
var fixture = new Fixture();
var project = Fixture.GetPath("Thuuud/Thuuud.csproj");

// When
Expand All @@ -190,7 +210,52 @@ public async Task Should_Return_Zero_Exit_Code_For_Thuuud_When_Running_With_NoPr
await Verifier.Verify(output);
}

public sealed class Fixture
[Fact]
[Expectation("FooBar", "Default")]
public async Task Should_Print_Error_For_FooBar()
{
// Given
var project = Fixture.GetPath("FooBar/FooBar.csproj");

// When
var (exitCode, output) = await Fixture.Run(project);

// Then
exitCode.ShouldBe(0);
await Verifier.Verify(output);
}

[Fact]
[Expectation("FooBar", "Strict")]
public async Task Should_Return_NonZero_Exit_Code_For_FooBar_When_Running_With_Strict()
{
// Given
var project = Fixture.GetPath("FooBar/FooBar.csproj");

// When
var (exitCode, output) = await Fixture.Run(project, "--strict");

// Then
exitCode.ShouldBe(-1);
await Verifier.Verify(output);
}

[Fact]
[Expectation("FSharp", "Default")]
public async Task Should_Return_Expected_Result_For_FSharp_Not_Specifying_Framework()
{
// Given
var project = Fixture.GetPath("FSharp/FSharp.fsproj");

// When
var (exitCode, output) = await Fixture.Run(project);

// Then
exitCode.ShouldBe(0);
await Verifier.Verify(output);
}

private static class Fixture
{
public static string GetPath(string path)
{
Expand All @@ -207,20 +272,22 @@ public static string GetPath(string path)
}
}

[Fact]
[Expectation("FSharp", "Default")]
public async Task Should_Return_Expected_Result_For_FSharp_Not_Specifying_Framework()
private sealed class TempFileScope : IDisposable
{
// Given
var fixture = new Fixture();
var project = Fixture.GetPath("FSharp/FSharp.fsproj");
public TempFileScope()
{
this.FileName = Path.GetTempFileName() + ".json";
}

// When
var (exitCode, output) = await Fixture.Run(project);
public string FileName { get; }

// Then
exitCode.ShouldBe(0);
await Verifier.Verify(output);
public void Dispose()
{
if (File.Exists(this.FileName))
{
File.Delete(this.FileName);
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Snitch.Tests/VerifyConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Runtime.CompilerServices;
using VerifyTests;

namespace Sntich.Tests
namespace Snitch.Tests
{
public static class VerifyConfiguration
{
Expand Down
Loading