Browse Source

Upgrade to NUnit 3.9 and enable parallel test execution.

pull/1087/head
Daniel Grunwald 8 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;
namespace ICSharpCode.Decompiler.Tests namespace ICSharpCode.Decompiler.Tests
{ {
[TestFixture] [TestFixture, Parallelizable(ParallelScope.All)]
public class CorrectnessTestRunner public class CorrectnessTestRunner
{ {
const string TestCasePath = DecompilerTestBase.TestCasePath + "/Correctness"; static readonly string TestCasePath = DecompilerTestBase.TestCasePath + "/Correctness";
[Test] [Test]
public void AllFilesHaveTests() public void AllFilesHaveTests()

4
ICSharpCode.Decompiler.Tests/DecompilerTestBase.cs

@ -32,7 +32,9 @@ namespace ICSharpCode.Decompiler.Tests
{ {
public abstract class DecompilerTestBase 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) protected static void ValidateFileRoundtrip(string samplesFileName)
{ {

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

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

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

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

30
ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs

@ -1,18 +1,34 @@
using System; // Copyright (c) AlphaSierraPapa for the SharpDevelop Team
using System.Collections.Generic; //
// 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.IO;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using ICSharpCode.Decompiler.Tests.Helpers; using ICSharpCode.Decompiler.Tests.Helpers;
using NUnit.Framework; using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests namespace ICSharpCode.Decompiler.Tests
{ {
[TestFixture, Parallelizable(ParallelScope.All)]
public class ILPrettyTestRunner public class ILPrettyTestRunner
{ {
const string TestCasePath = DecompilerTestBase.TestCasePath + "/ILPretty"; static readonly string TestCasePath = DecompilerTestBase.TestCasePath + "/ILPretty";
[Test] [Test]
public void AllFilesHaveTests() public void AllFilesHaveTests()
@ -78,13 +94,13 @@ namespace ICSharpCode.Decompiler.Tests
Run(settings: new DecompilerSettings { RemoveDeadCode = true }); Run(settings: new DecompilerSettings { RemoveDeadCode = true });
} }
[Test, Ignore] [Test, Ignore("?")]
public void FSharpLoops_Debug() public void FSharpLoops_Debug()
{ {
Run(settings: new DecompilerSettings { RemoveDeadCode = true }); Run(settings: new DecompilerSettings { RemoveDeadCode = true });
} }
[Test, Ignore] [Test, Ignore("?")]
public void FSharpLoops_Release() public void FSharpLoops_Release()
{ {
Run(settings: new DecompilerSettings { RemoveDeadCode = true }); Run(settings: new DecompilerSettings { RemoveDeadCode = true });

3
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

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

31
ICSharpCode.Decompiler.Tests/RoundtripAssembly.cs

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

6
ICSharpCode.Decompiler.Tests/TestTraceListener.cs

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

3
ICSharpCode.Decompiler.Tests/UglyTestRunner.cs

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

9
ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs

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

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

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

Loading…
Cancel
Save