From d986bdc61c798fa54bf1dc93cb135299f9a29532 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 30 Aug 2017 14:33:03 +0200 Subject: [PATCH] Working on #831: Update ICSharpCode.Decompiler.Tests.csproj to new project format. Seems like we cannot make the tests work with .NET Standard/.NET Core because we have some special cases: - tests for UndocumentedExpressions depend on the full framework - the .NET Core Test Runner wants to inject a custom main method and implicitly turns the project into a console app (tooling bug?), which in turn fails to compile because we use a lot of Main methods in our test cases which get compiled during tests. - Needed to update all the Nuget packages: most notably DiffLib --- .../Tests/CorrectnessTestRunner.cs | 2 +- .../Tests/Helpers/CodeAssert.cs | 39 ++- .../Tests/ICSharpCode.Decompiler.Tests.csproj | 264 ++++++------------ .../Tests/PrettyTestRunner.cs | 3 +- .../Tests/RoundtripAssembly.cs | 2 +- .../Tests/TestTraceListener.cs | 12 +- ICSharpCode.Decompiler/Tests/app.config | 15 +- 7 files changed, 127 insertions(+), 210 deletions(-) diff --git a/ICSharpCode.Decompiler/Tests/CorrectnessTestRunner.cs b/ICSharpCode.Decompiler/Tests/CorrectnessTestRunner.cs index 02bdd5f0ed..cce4a01b8e 100644 --- a/ICSharpCode.Decompiler/Tests/CorrectnessTestRunner.cs +++ b/ICSharpCode.Decompiler/Tests/CorrectnessTestRunner.cs @@ -28,7 +28,7 @@ namespace ICSharpCode.Decompiler.Tests [TestFixture] public class CorrectnessTestRunner { - const string TestCasePath = @"../../Tests/TestCases/Correctness"; + const string TestCasePath = @"../../../../TestCases/Correctness"; [Test] public void AllFilesHaveTests() diff --git a/ICSharpCode.Decompiler/Tests/Helpers/CodeAssert.cs b/ICSharpCode.Decompiler/Tests/Helpers/CodeAssert.cs index 65a86d42ec..713a8f3842 100644 --- a/ICSharpCode.Decompiler/Tests/Helpers/CodeAssert.cs +++ b/ICSharpCode.Decompiler/Tests/Helpers/CodeAssert.cs @@ -26,44 +26,43 @@ public static class CodeComparer { public static bool Compare(string input1, string input2, StringWriter diff, Func normalizeLine) { - var differ = new AlignedDiff( - NormalizeAndSplitCode(input1), - NormalizeAndSplitCode(input2), - new CodeLineEqualityComparer(normalizeLine), - new StringSimilarityComparer(), - new StringAlignmentFilter()); + var a = NormalizeAndSplitCode(input1); + var b = NormalizeAndSplitCode(input2); + var sections = Diff.CalculateSections(a, b, new CodeLineEqualityComparer(normalizeLine)); + var elements = Diff.AlignElements(a, b, sections, new StringSimilarityDiffElementAligner()); bool result = true, ignoreChange; int line1 = 0, line2 = 0; - foreach (var change in differ.Generate()) { - switch (change.Change) { - case ChangeType.Same: + foreach (var element in elements) { + switch (element.Operation) { + case DiffOperation.Match: diff.Write("{0,4} {1,4} ", ++line1, ++line2); diff.Write(" "); - diff.WriteLine(change.Element1); + diff.WriteLine(element.ElementFromCollection1.Value); break; - case ChangeType.Added: + case DiffOperation.Insert: diff.Write(" {1,4} ", line1, ++line2); - result &= ignoreChange = ShouldIgnoreChange(change.Element2); + result &= ignoreChange = ShouldIgnoreChange(element.ElementFromCollection2.Value); diff.Write(ignoreChange ? " " : " + "); - diff.WriteLine(change.Element2); + diff.WriteLine(element.ElementFromCollection2.Value); break; - case ChangeType.Deleted: + case DiffOperation.Delete: diff.Write("{0,4} ", ++line1, line2); - result &= ignoreChange = ShouldIgnoreChange(change.Element1); + result &= ignoreChange = ShouldIgnoreChange(element.ElementFromCollection1.Value); diff.Write(ignoreChange ? " " : " - "); - diff.WriteLine(change.Element1); + diff.WriteLine(element.ElementFromCollection1.Value); break; - case ChangeType.Changed: + case DiffOperation.Replace: + case DiffOperation.Modify: diff.Write("{0,4} ", ++line1, line2); result = false; diff.Write("(-) "); - diff.WriteLine(change.Element1); + diff.WriteLine(element.ElementFromCollection1.Value); diff.Write(" {1,4} ", line1, ++line2); diff.Write("(+) "); - diff.WriteLine(change.Element2); + diff.WriteLine(element.ElementFromCollection2.Value); break; } } @@ -114,7 +113,7 @@ private static bool ShouldIgnoreChange(string line) return NormalizeLine(line) == string.Empty; } - private static IEnumerable NormalizeAndSplitCode(string input) + private static IList NormalizeAndSplitCode(string input) { return input.Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries); } diff --git a/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj index 4c24bf1257..3a49316693 100644 --- a/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj @@ -1,189 +1,109 @@ - - + - {FEC0DA52-C4A6-4710-BE36-B484A20C5E22} - Debug - x86 - Library - ICSharpCode.Decompiler.Tests - ICSharpCode.Decompiler.Tests - v4.5 - Properties - True - False - 4 - false - False - 67,169,1058,728,1720,649 - - False - True + net461 + true + true ..\ICSharpCode.Decompiler.snk - False - File - - - - - x86 - False - Auto - 4194304 - 4096 - - - AnyCPU - False - Auto - 4194304 - 4096 - - - ..\bin\Debug\ - true - Full - False - DEBUG;TRACE + Library + false - - ..\bin\Release\ - false - None - True - TRACE + + bin\Debug\net461\ - - ..\..\packages\DiffLib.1.0.0.55\lib\net35-Client\DiffLib.dll - - - ..\..\packages\Microsoft.CodeAnalysis.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.dll - True - - - ..\..\packages\Microsoft.CodeAnalysis.CSharp.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.dll - True - - - - ..\..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll - False - - - ..\..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll - False - - - ..\..\packages\NUnit.2.6.3\lib\nunit.framework.dll - - - - ..\..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll - False - - - ..\..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll - False - - - - ..\..\packages\System.Collections.Immutable.1.3.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - True - - - 3.5 - - - ..\..\packages\System.Reflection.Metadata.1.2.0\lib\portable-net45+win8\System.Reflection.Metadata.dll - True - - - - 3.5 - - - - - - - + + + + + + + + + + + + - - {d68133bd-1e63-496e-9ede-4fbdbf77b486} - Mono.Cecil - - - {984cc812-9470-4a13-aff9-cc44068d666c} - ICSharpCode.Decompiler - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + - - CompoundAssignmentTest.cs - - - HelloWorld.cs - - - InlineAssignmentTest.cs - - + - - + - \ No newline at end of file diff --git a/ICSharpCode.Decompiler/Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler/Tests/PrettyTestRunner.cs index a82bd4fafe..afdd2f7cbc 100644 --- a/ICSharpCode.Decompiler/Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler/Tests/PrettyTestRunner.cs @@ -26,9 +26,10 @@ namespace ICSharpCode.Decompiler.Tests { + [TestFixture] public class PrettyTestRunner { - const string TestCasePath = @"../../Tests/TestCases/Pretty"; + const string TestCasePath = @"../../../../TestCases/Pretty"; [Test] public void AllFilesHaveTests() diff --git a/ICSharpCode.Decompiler/Tests/RoundtripAssembly.cs b/ICSharpCode.Decompiler/Tests/RoundtripAssembly.cs index 561132f512..bb5599a721 100644 --- a/ICSharpCode.Decompiler/Tests/RoundtripAssembly.cs +++ b/ICSharpCode.Decompiler/Tests/RoundtripAssembly.cs @@ -32,7 +32,7 @@ namespace ICSharpCode.Decompiler.Tests { public class RoundtripAssembly { - static readonly string testDir = Path.GetFullPath("../../../ILSpy-tests"); + static readonly string testDir = Path.GetFullPath("../../../../../../ILSpy-tests"); static readonly string nunit = Path.Combine(testDir, "nunit", "nunit3-console.exe"); [Test] diff --git a/ICSharpCode.Decompiler/Tests/TestTraceListener.cs b/ICSharpCode.Decompiler/Tests/TestTraceListener.cs index bc1f83c3bc..26cdaa7606 100644 --- a/ICSharpCode.Decompiler/Tests/TestTraceListener.cs +++ b/ICSharpCode.Decompiler/Tests/TestTraceListener.cs @@ -16,8 +16,9 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +using System; using System.Diagnostics; -using NUnit.Core; +using System.IO; using NUnit.Framework; namespace ICSharpCode.Decompiler.Tests @@ -25,17 +26,18 @@ namespace ICSharpCode.Decompiler.Tests [SetUpFixture] public class TestTraceListener : DefaultTraceListener { - [SetUp] + [OneTimeSetUp] public void RunBeforeAnyTests() { - Debug.Listeners.Insert(0, this); + Environment.CurrentDirectory = Path.GetDirectoryName(typeof(TestTraceListener).Assembly.Location); + Trace.Listeners.Insert(0, this); } - [TearDown] + [OneTimeTearDown] public void RunAfterAnyTests() { - Debug.Listeners.Remove(this); + Trace.Listeners.Remove(this); } public override void Fail(string message, string detailMessage) diff --git a/ICSharpCode.Decompiler/Tests/app.config b/ICSharpCode.Decompiler/Tests/app.config index 95419741bb..fd3b41004a 100644 --- a/ICSharpCode.Decompiler/Tests/app.config +++ b/ICSharpCode.Decompiler/Tests/app.config @@ -1,11 +1,6 @@ - + - - - - - - - - - \ No newline at end of file + + + +