Skip to content
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

Migrate to NUnit 4 #3132

Merged
merged 7 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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.1.0-adev.2" />
<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.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like that overly verbose syntax.... what's wrong with AreEqual?

Copy link
Member

@siegfriedpammer siegfriedpammer Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.nunit.org/articles/nunit/writing-tests/assertions/assertions.html... why not keep the classic model for all the existing tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess what will happen if we keep classic. It will be copy pasted forever.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no problem with that... :D the short forms are more intuitive...


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
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
Loading