Browse Source

Upgrade to NUnit 3.9 and enable parallel test execution.

pull/1087/head
Daniel Grunwald 7 years ago
parent
commit
d9a28314f9
  1. 4
      ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs
  2. 4
      ICSharpCode.Decompiler.Tests/DecompilerTestBase.cs
  3. 2
      ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
  4. 4
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  5. 30
      ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs
  6. 3
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  7. 31
      ICSharpCode.Decompiler.Tests/RoundtripAssembly.cs
  8. 6
      ICSharpCode.Decompiler.Tests/TestTraceListener.cs
  9. 3
      ICSharpCode.Decompiler.Tests/UglyTestRunner.cs
  10. 9
      ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs
  11. 2
      ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj

4
ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs

@ -26,10 +26,10 @@ using NUnit.Framework; @@ -26,10 +26,10 @@ using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests
{
[TestFixture]
[TestFixture, Parallelizable(ParallelScope.All)]
public class CorrectnessTestRunner
{
const string TestCasePath = DecompilerTestBase.TestCasePath + "/Correctness";
static readonly string TestCasePath = DecompilerTestBase.TestCasePath + "/Correctness";
[Test]
public void AllFilesHaveTests()

4
ICSharpCode.Decompiler.Tests/DecompilerTestBase.cs

@ -32,7 +32,9 @@ namespace ICSharpCode.Decompiler.Tests @@ -32,7 +32,9 @@ namespace ICSharpCode.Decompiler.Tests
{
public abstract class DecompilerTestBase
{
public const string TestCasePath = "../../../TestCases";
public static readonly string TestCasePath = Path.Combine(
Path.GetDirectoryName(typeof(DecompilerTestBase).Assembly.Location),
"../../../TestCases");
protected static void ValidateFileRoundtrip(string samplesFileName)
{

2
ICSharpCode.Decompiler.Tests/Helpers/Tester.cs

@ -219,7 +219,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -219,7 +219,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
} else if (flags.HasFlag(CompilerOptions.UseMcs)) {
CompilerResults results = new CompilerResults(new TempFileCollection());
results.PathToAssembly = outputFileName ?? Path.GetTempFileName();
string testBasePath = Path.GetFullPath("../../../../ILSpy-tests");
string testBasePath = RoundtripAssembly.TestDir;
if (!Directory.Exists(testBasePath)) {
Assert.Ignore($"Compilation with mcs ignored: test directory '{testBasePath}' needs to be checked out separately." + Environment.NewLine +
$"git clone https://github.com/icsharpcode/ILSpy-tests \"{testBasePath}\"");

4
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -38,9 +38,9 @@ @@ -38,9 +38,9 @@
<ItemGroup>
<PackageReference Include="DiffLib" Version="1.0.0.55" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.6.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.3.1" />
<PackageReference Include="NUnit" Version="2.6.3" />
<PackageReference Include="NUnitTestAdapter" Version="2.0.0" />
<PackageReference Include="NUnit" Version="3.9.0" />
</ItemGroup>
<ItemGroup>

30
ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs

@ -1,18 +1,34 @@ @@ -1,18 +1,34 @@
using System;
using System.Collections.Generic;
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using ICSharpCode.Decompiler.Tests.Helpers;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests
{
[TestFixture, Parallelizable(ParallelScope.All)]
public class ILPrettyTestRunner
{
const string TestCasePath = DecompilerTestBase.TestCasePath + "/ILPretty";
static readonly string TestCasePath = DecompilerTestBase.TestCasePath + "/ILPretty";
[Test]
public void AllFilesHaveTests()
@ -78,13 +94,13 @@ namespace ICSharpCode.Decompiler.Tests @@ -78,13 +94,13 @@ namespace ICSharpCode.Decompiler.Tests
Run(settings: new DecompilerSettings { RemoveDeadCode = true });
}
[Test, Ignore]
[Test, Ignore("?")]
public void FSharpLoops_Debug()
{
Run(settings: new DecompilerSettings { RemoveDeadCode = true });
}
[Test, Ignore]
[Test, Ignore("?")]
public void FSharpLoops_Release()
{
Run(settings: new DecompilerSettings { RemoveDeadCode = true });

3
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -26,9 +26,10 @@ using NUnit.Framework; @@ -26,9 +26,10 @@ using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests
{
[TestFixture, Parallelizable(ParallelScope.All)]
public class PrettyTestRunner
{
const string TestCasePath = DecompilerTestBase.TestCasePath + "/Pretty";
static readonly string TestCasePath = DecompilerTestBase.TestCasePath + "/Pretty";
[Test]
public void AllFilesHaveTests()

31
ICSharpCode.Decompiler.Tests/RoundtripAssembly.cs

@ -30,10 +30,11 @@ using NUnit.Framework; @@ -30,10 +30,11 @@ using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests
{
[TestFixture, Parallelizable(ParallelScope.All)]
public class RoundtripAssembly
{
static readonly string testDir = Path.GetFullPath("../../../../ILSpy-tests");
static readonly string nunit = Path.Combine(testDir, "nunit", "nunit3-console.exe");
public static readonly string TestDir = Path.GetFullPath(Path.Combine(DecompilerTestBase.TestCasePath, "../../ILSpy-tests"));
static readonly string nunit = Path.Combine(TestDir, "nunit", "nunit3-console.exe");
[Test]
public void Cecil_net45()
@ -105,26 +106,30 @@ namespace ICSharpCode.Decompiler.Tests @@ -105,26 +106,30 @@ namespace ICSharpCode.Decompiler.Tests
void RunWithTest(string dir, string fileToRoundtrip, string fileToTest)
{
RunInternal(dir, fileToRoundtrip, () => RunTest(Path.Combine(testDir, dir) + "-output", fileToTest));
RunInternal(dir, fileToRoundtrip, outputDir => RunTest(outputDir, fileToTest));
}
void RunWithOutput(string dir, string fileToRoundtrip)
{
string inputDir = Path.Combine(testDir, dir);
string outputDir = inputDir + "-output";
RunInternal(dir, fileToRoundtrip, () => Tester.RunAndCompareOutput(fileToRoundtrip, Path.Combine(inputDir, fileToRoundtrip), Path.Combine(outputDir, fileToRoundtrip)));
string inputDir = Path.Combine(TestDir, dir);
RunInternal(dir, fileToRoundtrip,
outputDir => Tester.RunAndCompareOutput(fileToRoundtrip, Path.Combine(inputDir, fileToRoundtrip), Path.Combine(outputDir, fileToRoundtrip)));
}
void RunInternal(string dir, string fileToRoundtrip, Action testAction)
void RunInternal(string dir, string fileToRoundtrip, Action<string> testAction)
{
if (!Directory.Exists(testDir)) {
Assert.Ignore($"Assembly-roundtrip test ignored: test directory '{testDir}' needs to be checked out separately." + Environment.NewLine +
$"git clone https://github.com/icsharpcode/ILSpy-tests \"{testDir}\"");
if (!Directory.Exists(TestDir)) {
Assert.Ignore($"Assembly-roundtrip test ignored: test directory '{TestDir}' needs to be checked out separately." + Environment.NewLine +
$"git clone https://github.com/icsharpcode/ILSpy-tests \"{TestDir}\"");
}
string inputDir = Path.Combine(testDir, dir);
//RunTest(inputDir, fileToTest);
string inputDir = Path.Combine(TestDir, dir);
string decompiledDir = inputDir + "-decompiled";
string outputDir = inputDir + "-output";
if (inputDir.EndsWith("TestCases")) {
// make sure output dir names are unique so that we don't get trouble due to parallel test execution
decompiledDir += Path.GetFileNameWithoutExtension(fileToRoundtrip);
outputDir += Path.GetFileNameWithoutExtension(fileToRoundtrip);
}
ClearDirectory(decompiledDir);
ClearDirectory(outputDir);
string projectFile = null;
@ -157,7 +162,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -157,7 +162,7 @@ namespace ICSharpCode.Decompiler.Tests
Assert.IsNotNull(projectFile, $"Could not find {fileToRoundtrip}");
Compile(projectFile, outputDir);
testAction();
testAction(outputDir);
}
static void ClearDirectory(string dir)

6
ICSharpCode.Decompiler.Tests/TestTraceListener.cs

@ -17,7 +17,6 @@ @@ -17,7 +17,6 @@
// DEALINGS IN THE SOFTWARE.
using System.Diagnostics;
using NUnit.Core;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests
@ -25,14 +24,13 @@ namespace ICSharpCode.Decompiler.Tests @@ -25,14 +24,13 @@ namespace ICSharpCode.Decompiler.Tests
[SetUpFixture]
public class TestTraceListener : DefaultTraceListener
{
[SetUp]
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
Debug.Listeners.Insert(0, this);
}
[TearDown]
[OneTimeTearDown]
public void RunAfterAnyTests()
{
Debug.Listeners.Remove(this);

3
ICSharpCode.Decompiler.Tests/UglyTestRunner.cs

@ -26,9 +26,10 @@ using NUnit.Framework; @@ -26,9 +26,10 @@ using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests
{
[TestFixture, Parallelizable(ParallelScope.All)]
public class UglyTestRunner
{
const string TestCasePath = DecompilerTestBase.TestCasePath + "/Ugly";
static readonly string TestCasePath = DecompilerTestBase.TestCasePath + "/Ugly";
[Test]
public void AllFilesHaveTests()

9
ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs

@ -14,7 +14,7 @@ using NUnit.Framework; @@ -14,7 +14,7 @@ using NUnit.Framework;
namespace ILSpy.BamlDecompiler.Tests
{
[TestFixture]
[TestFixture, Parallelizable(ParallelScope.All)]
public class BamlTestRunner
{
[Test]
@ -104,12 +104,17 @@ namespace ILSpy.BamlDecompiler.Tests @@ -104,12 +104,17 @@ namespace ILSpy.BamlDecompiler.Tests
#region RunTest
void RunTest(string name)
{
RunTest(name, typeof(BamlTestRunner).Assembly.Location, Path.Combine("..\\..\\..\\..\\ILSpy.BamlDecompiler.Tests", name + ".xaml"));
RunTest(name, typeof(BamlTestRunner).Assembly.Location,
Path.Combine(
Path.GetDirectoryName(typeof(BamlTestRunner).Assembly.Location),
"../../../../ILSpy.BamlDecompiler.Tests", name + ".xaml"));
}
void RunTest(string name, string asmPath, string sourcePath)
{
var resolver = new DefaultAssemblyResolver();
resolver.RemoveSearchDirectory(".");
resolver.AddSearchDirectory(Path.GetDirectoryName(asmPath));
var assembly = AssemblyDefinition.ReadAssembly(asmPath, new ReaderParameters { AssemblyResolver = resolver, InMemory = true });
Resource res = assembly.MainModule.Resources.First();
Stream bamlStream = LoadBaml(res, name + ".baml");

2
ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj

@ -33,7 +33,7 @@ @@ -33,7 +33,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="2.6.3" />
<PackageReference Include="NUnit" Version="3.9.0" />
</ItemGroup>
<ItemGroup>

Loading…
Cancel
Save