Skip to content

Commit

Permalink
Migrate to NUnit 4 (#3132)
Browse files Browse the repository at this point in the history
* Migrate to NUnit 4 based on https://docs.nunit.org/articles/nunit/release-notes/Nunit4.0-MigrationGuide.html. Needed fix for nunit/nunit#4564
* Test 4.1.0-adev.1 from NUnit MyGet feed (works locally in VS)
* Update to bugfix version adev.2 (works on GH)
* NUnit 4.0.1 final
  • Loading branch information
christophwille authored Dec 2, 2023
1 parent 71c3aaf commit fba0dba
Show file tree
Hide file tree
Showing 33 changed files with 1,582 additions and 1,624 deletions.
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageVersion Include="DataGridExtensions" Version="2.5.15" />
<PackageVersion Include="DiffLib" Version="2017.7.26.1241" />
<PackageVersion Include="Dirkster.AvalonDock.Themes.VS2013" Version="4.72.1" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="ILCompiler.Reflection.ReadyToRun.Experimental" Version="8.0.0-rc.2.23471.30" />
<PackageVersion Include="Iced" Version="1.18.0" />
<PackageVersion Include="JunitXml.TestLogger" Version="3.0.134" />
Expand All @@ -29,7 +30,7 @@
<PackageVersion Include="Mono.Cecil" Version="0.11.5" />
<PackageVersion Include="NSubstitute" Version="5.0.0" />
<PackageVersion Include="NSubstitute.Analyzers.CSharp" Version="1.0.16" />
<PackageVersion Include="NUnit" Version="3.14.0" />
<PackageVersion Include="NUnit" Version="4.0.1" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="NuGet.Protocol" Version="6.8.0" />
<PackageVersion Include="PowerShellStandard.Library" Version="5.1.1" />
Expand Down
4 changes: 2 additions & 2 deletions ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void AllFilesHaveTests()
if (file.Extension == ".txt" || file.Extension == ".exe" || file.Extension == ".config")
continue;
var testName = Path.GetFileNameWithoutExtension(file.Name);
Assert.Contains(testName, testNames);
Assert.That(testNames, Has.Member(testName));
}
}

Expand Down Expand Up @@ -486,7 +486,7 @@ async Task RunIL(string testFileName, CompilerOptions options = CompilerOptions.
bool optionsForce32Bit = options.HasFlag(CompilerOptions.Force32Bit);
bool asmOptionsForce32Bit = asmOptions.HasFlag(AssemblerOptions.Force32Bit);

Assert.AreEqual(optionsForce32Bit, asmOptionsForce32Bit, "Inconsistent architecture.");
Assert.That(asmOptionsForce32Bit, Is.EqualTo(optionsForce32Bit), "Inconsistent architecture.");

try
{
Expand Down
8 changes: 4 additions & 4 deletions ICSharpCode.Decompiler.Tests/DataFlowTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public RDTest(ILFunction f, ILVariable v) : base(f, _ => true, CancellationToken

protected internal override void VisitTryFinally(TryFinally inst)
{
Assert.IsTrue(IsPotentiallyUninitialized(state, v));
Assert.That(IsPotentiallyUninitialized(state, v));
base.VisitTryFinally(inst);
Assert.IsTrue(state.IsReachable);
Assert.AreEqual(1, GetStores(state, v).Count());
Assert.IsFalse(IsPotentiallyUninitialized(state, v));
Assert.That(state.IsReachable);
Assert.That(GetStores(state, v).Count(), Is.EqualTo(1));
Assert.That(!IsPotentiallyUninitialized(state, v));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void AllFilesHaveTests()
if (file.Extension.Equals(".il", StringComparison.OrdinalIgnoreCase))
{
var testName = file.Name.Split('.')[0];
Assert.Contains(testName, testNames);
Assert.That(testNames, Has.Member(testName));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static async Task<CompilerResults> CompileVB(string sourceFileName, Compi
{
Console.WriteLine("errors:" + Environment.NewLine + result.StandardError);
}
Assert.AreEqual(0, result.ExitCode, "vbc failed");
Assert.That(result.ExitCode, Is.EqualTo(0), "vbc failed");

return results;
}
Expand Down
14 changes: 7 additions & 7 deletions ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static async Task<string> AssembleIL(string sourceFileName, AssemblerOpti
{
Console.WriteLine("errors:" + Environment.NewLine + result.StandardError);
}
Assert.AreEqual(0, result.ExitCode, "ilasm failed");
Assert.That(result.ExitCode, Is.EqualTo(0), "ilasm failed");

return outputFile;
}
Expand Down Expand Up @@ -251,7 +251,7 @@ public static async Task<string> Disassemble(string sourceFileName, string outpu
{
Console.WriteLine("errors:" + Environment.NewLine + result.StandardError);
}
Assert.AreEqual(0, result.ExitCode, "ildasm failed");
Assert.That(result.ExitCode, Is.EqualTo(0), "ildasm failed");

// Unlike the .imagebase directive (which is a fixed value when compiling with /deterministic),
// the image base comment still varies... ildasm putting a random number here?
Expand Down Expand Up @@ -520,7 +520,7 @@ public static async Task<CompilerResults> CompileCSharp(string sourceFileName, C
Console.WriteLine("errors:" + Environment.NewLine + result.StandardError);
}

Assert.AreEqual(0, result.ExitCode, "csc failed");
Assert.That(result.ExitCode, Is.EqualTo(0), "csc failed");

return results;
}
Expand Down Expand Up @@ -582,7 +582,7 @@ public static async Task<CompilerResults> CompileCSharp(string sourceFileName, C
{
Console.WriteLine("errors:" + Environment.NewLine + result.StandardError);
}
Assert.AreEqual(0, result.ExitCode, "mcs failed");
Assert.That(result.ExitCode, Is.EqualTo(0), "mcs failed");

return results;
}
Expand Down Expand Up @@ -764,8 +764,8 @@ public static async Task RunAndCompareOutput(string testFileName, string outputF
(result2, output2, error2) = await Run(decompiledOutputFile).ConfigureAwait(false);
}

Assert.AreEqual(0, result1, "Exit code != 0; did the test case crash?" + Environment.NewLine + error1);
Assert.AreEqual(0, result2, "Exit code != 0; did the decompiled code crash?" + Environment.NewLine + error2);
Assert.That(result1, Is.EqualTo(0), "Exit code != 0; did the test case crash?" + Environment.NewLine + error1);
Assert.That(result2, Is.EqualTo(0), "Exit code != 0; did the decompiled code crash?" + Environment.NewLine + error2);

if (output1 != output2 || error1 != error2)
{
Expand Down Expand Up @@ -851,7 +851,7 @@ public static async Task SignAssembly(string assemblyPath, string keyFilePath)
.WithValidation(CommandResultValidation.None);

var result = await command.ExecuteBufferedAsync().ConfigureAwait(false);
Assert.AreEqual(0, result.ExitCode, "sn failed");
Assert.That(result.ExitCode, Is.EqualTo(0), "sn failed");

if (!string.IsNullOrWhiteSpace(result.StandardOutput))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="coverlet.collector" />
<PackageReference Include="NUnit" />
<!-- used for xml test result files -->
<PackageReference Include="FluentAssertions" />
<PackageReference Include="JunitXml.TestLogger" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="System.Memory" />
Expand Down
4 changes: 2 additions & 2 deletions ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void AllFilesHaveTests()
if (file.Extension.Equals(".il", StringComparison.OrdinalIgnoreCase))
{
var testName = file.Name.Split('.')[0];
Assert.Contains(testName, testNames);
Assert.IsTrue(File.Exists(Path.Combine(TestCasePath, testName + ".cs")));
Assert.That(testNames, Has.Member(testName));
Assert.That(File.Exists(Path.Combine(TestCasePath, testName + ".cs")));
}
}
}
Expand Down
38 changes: 19 additions & 19 deletions ICSharpCode.Decompiler.Tests/Output/CSharpAmbienceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ITypeDefinition GetDefinition(Type type)
}

var foundType = compilation.FindType(type).GetDefinition();
Assert.IsNotNull(foundType);
Assert.That(foundType, Is.Not.Null);
return foundType;
}

Expand All @@ -76,7 +76,7 @@ public void GenericType(ConversionFlags flags, string expectedOutput)
{
var typeDef = GetDefinition(typeof(Dictionary<,>));
ambience.ConversionFlags = flags;
Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef));
Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput));
}

[TestCase(None, "Object")]
Expand All @@ -92,7 +92,7 @@ public void SimpleType(ConversionFlags flags, string expectedOutput)
{
var typeDef = GetDefinition(typeof(object));
ambience.ConversionFlags = flags;
Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef));
Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput));
}

[TestCase(None, "IEnumerable")]
Expand All @@ -104,7 +104,7 @@ public void GenericInterface(ConversionFlags flags, string expectedOutput)
{
var typeDef = GetDefinition(typeof(IEnumerable<>));
ambience.ConversionFlags = flags;
Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef));
Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput));
}

[TestCase(None, "Enumerator")]
Expand All @@ -121,7 +121,7 @@ public void GenericTypeWithNested(ConversionFlags flags, string expectedOutput)
{
var typeDef = GetDefinition(typeof(List<>.Enumerator));
ambience.ConversionFlags = flags;
Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef));
Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput));
}

[TestCase(None, "StaticClass")]
Expand All @@ -137,7 +137,7 @@ public void StaticClassTest(ConversionFlags flags, string expectedOutput)
{
var typeDef = GetDefinition(typeof(StaticClass));
ambience.ConversionFlags = flags;
Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef));
Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput));
}

[TestCase(None, "SealedClass")]
Expand All @@ -153,7 +153,7 @@ public void SealedClassTest(ConversionFlags flags, string expectedOutput)
{
var typeDef = GetDefinition(typeof(SealedClass));
ambience.ConversionFlags = flags;
Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef));
Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput));
}

[TestCase(None, "RefStruct")]
Expand All @@ -169,7 +169,7 @@ public void RefStructTest(ConversionFlags flags, string expectedOutput)
{
var typeDef = GetDefinition(typeof(RefStruct));
ambience.ConversionFlags = flags;
Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef));
Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput));
}

[TestCase(None, "ReadonlyStruct")]
Expand All @@ -185,7 +185,7 @@ public void ReadonlyStructTest(ConversionFlags flags, string expectedOutput)
{
var typeDef = GetDefinition(typeof(ReadonlyStruct));
ambience.ConversionFlags = flags;
Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef));
Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput));
}

[TestCase(None, "ReadonlyRefStruct")]
Expand All @@ -201,7 +201,7 @@ public void ReadonlyRefStructTest(ConversionFlags flags, string expectedOutput)
{
var typeDef = GetDefinition(typeof(ReadonlyRefStruct));
ambience.ConversionFlags = flags;
Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(typeDef));
Assert.That(ambience.ConvertSymbol(typeDef), Is.EqualTo(expectedOutput));
}
#endregion

Expand All @@ -219,7 +219,7 @@ public void FuncDelegate(ConversionFlags flags, string expectedOutput)
{
var func = GetDefinition(typeof(Func<,>));
ambience.ConversionFlags = flags;
Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(func));
Assert.That(ambience.ConvertSymbol(func), Is.EqualTo(expectedOutput));
}
#endregion

Expand All @@ -232,7 +232,7 @@ public void SimpleField(ConversionFlags flags, string expectedOutput)
var field = GetDefinition(typeof(CSharpAmbienceTests.Program)).GetFields(f => f.Name == "test").Single();
ambience.ConversionFlags = flags;

Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(field));
Assert.That(ambience.ConvertSymbol(field), Is.EqualTo(expectedOutput));
}

[TestCase(All & ~PlaceReturnTypeAfterParameterList, "private const int ICSharpCode.Decompiler.Tests.Output.CSharpAmbienceTests.Program.TEST2;")]
Expand All @@ -242,7 +242,7 @@ public void SimpleConstField(ConversionFlags flags, string expectedOutput)
var field = compilation.FindType(typeof(CSharpAmbienceTests.Program)).GetFields(f => f.Name == "TEST2").Single();
ambience.ConversionFlags = flags;

Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(field));
Assert.That(ambience.ConvertSymbol(field), Is.EqualTo(expectedOutput));
}
#endregion

Expand All @@ -254,7 +254,7 @@ public void EventWithDeclaringType()
ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowDeclaringType;
string result = ambience.ConvertSymbol(ev);

Assert.AreEqual("public event EventHandler Program.ProgramChanged;", result);
Assert.That(result, Is.EqualTo("public event EventHandler Program.ProgramChanged;"));
}

[Test]
Expand All @@ -264,7 +264,7 @@ public void CustomEvent()
ambience.ConversionFlags = ConversionFlags.StandardConversionFlags;
string result = ambience.ConvertSymbol(ev);

Assert.AreEqual("public event EventHandler SomeEvent;", result);
Assert.That(result, Is.EqualTo("public event EventHandler SomeEvent;"));
}
#endregion

Expand All @@ -276,7 +276,7 @@ public void AutomaticProperty(ConversionFlags flags, string expectedOutput)
var prop = compilation.FindType(typeof(CSharpAmbienceTests.Program)).GetProperties(p => p.Name == "Test").Single();
ambience.ConversionFlags = flags;

Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(prop));
Assert.That(ambience.ConvertSymbol(prop), Is.EqualTo(expectedOutput));
}

[TestCase(StandardConversionFlags, "public int this[int index] { get; }")]
Expand All @@ -286,7 +286,7 @@ public void Indexer(ConversionFlags flags, string expectedOutput)
var prop = compilation.FindType(typeof(CSharpAmbienceTests.Program)).GetProperties(p => p.IsIndexer).Single();
ambience.ConversionFlags = flags;

Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(prop));
Assert.That(ambience.ConvertSymbol(prop), Is.EqualTo(expectedOutput));
}
#endregion

Expand All @@ -298,7 +298,7 @@ public void ConstructorTests(ConversionFlags flags, string expectedOutput)
var prop = compilation.FindType(typeof(CSharpAmbienceTests.Program)).GetConstructors().Single();
ambience.ConversionFlags = flags;

Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(prop));
Assert.That(ambience.ConvertSymbol(prop), Is.EqualTo(expectedOutput));
}

[TestCase(StandardConversionFlags, "~Program();")]
Expand All @@ -309,7 +309,7 @@ public void DestructorTests(ConversionFlags flags, string expectedOutput)
.GetMembers(m => m.SymbolKind == SymbolKind.Destructor, GetMemberOptions.IgnoreInheritedMembers).Single();
ambience.ConversionFlags = flags;

Assert.AreEqual(expectedOutput, ambience.ConvertSymbol(dtor));
Assert.That(ambience.ConvertSymbol(dtor), Is.EqualTo(expectedOutput));
}
#endregion

Expand Down
Loading

0 comments on commit fba0dba

Please sign in to comment.