From 7b3940a8182a39abafb71d62cd4217c214e7b12b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 9 Nov 2021 21:07:42 +0100 Subject: [PATCH] Add test configuration for mcs 5.23.0 --- .../CorrectnessTestRunner.cs | 16 +++++++------- .../Helpers/Tester.VB.cs | 2 +- .../Helpers/Tester.cs | 21 ++++++++++++------- .../PrettyTestRunner.cs | 6 ++++-- ILSpy-tests | 2 +- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs index 3a4304115d..b9b1d98db7 100644 --- a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs @@ -75,8 +75,10 @@ public void AllFilesHaveTests() CompilerOptions.Optimize | CompilerOptions.UseRoslyn3_11_0, CompilerOptions.UseRoslynLatest, CompilerOptions.Optimize | CompilerOptions.UseRoslynLatest, - CompilerOptions.UseMcs, - CompilerOptions.Optimize | CompilerOptions.UseMcs + CompilerOptions.UseMcs2_6_4, + CompilerOptions.Optimize | CompilerOptions.UseMcs2_6_4, + CompilerOptions.UseMcs5_23, + CompilerOptions.Optimize | CompilerOptions.UseMcs5_23 }; static readonly CompilerOptions[] roslynOnlyOptions = @@ -286,7 +288,7 @@ public void StackTypes([Values(false, true)] bool force32Bit) [Test] public void UnsafeCode([ValueSource(nameof(defaultOptions))] CompilerOptions options) { - if (options.HasFlag(CompilerOptions.UseMcs)) + if (options.HasFlag(CompilerOptions.UseMcs2_6_4)) { Assert.Ignore("Decompiler bug with mono!"); } @@ -314,7 +316,7 @@ public void Capturing([ValueSource(nameof(defaultOptions))] CompilerOptions opti [Test] public void YieldReturn([ValueSource(nameof(defaultOptions))] CompilerOptions options) { - if (options.HasFlag(CompilerOptions.UseMcs)) + if ((options & CompilerOptions.UseMcsMask) != 0) { Assert.Ignore("Decompiler bug with mono!"); } @@ -348,7 +350,7 @@ public void DynamicTests([ValueSource(nameof(noMonoOptions))] CompilerOptions op [Test] public void MiniJSON([ValueSource(nameof(defaultOptions))] CompilerOptions options) { - if (options.HasFlag(CompilerOptions.UseMcs)) + if (options.HasFlag(CompilerOptions.UseMcs2_6_4)) { Assert.Ignore("Decompiler bug with mono!"); } @@ -366,12 +368,12 @@ void RunCS([CallerMemberName] string testName = null, CompilerOptions options = outputFile = Tester.CompileCSharp(Path.Combine(TestCasePath, testFileName), options, outputFileName: Path.Combine(TestCasePath, testOutputFileName)); string decompiledCodeFile = Tester.DecompileCSharp(outputFile.PathToAssembly, Tester.GetSettings(options)); - if (options.HasFlag(CompilerOptions.UseMcs)) + if ((options & CompilerOptions.UseMcsMask) != 0) { // For second pass, use roslyn instead of mcs. // mcs has some compiler bugs that cause it to not accept ILSpy-generated code, // for example when there's unreachable code due to other compiler bugs in the first mcs run. - options &= ~CompilerOptions.UseMcs; + options &= ~CompilerOptions.UseMcsMask; options |= CompilerOptions.UseRoslynLatest; // Also, add an .exe.config so that we consistently use the .NET 4.x runtime. File.WriteAllText(outputFile.PathToAssembly + ".config", @" diff --git a/ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs b/ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs index 24c363e7d7..efff7eba9c 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs @@ -40,7 +40,7 @@ public static CompilerResults CompileVB(string sourceFileName, CompilerOptions f var preprocessorSymbols = GetPreprocessorSymbols(flags).Select(symbol => new KeyValuePair(symbol, 1)).ToList(); - if (!flags.HasFlag(CompilerOptions.UseMcs)) + if ((flags & CompilerOptions.UseMcsMask) == 0) { CompilerResults results = new CompilerResults(new TempFileCollection()); results.PathToAssembly = outputFileName ?? Path.GetTempFileName(); diff --git a/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs b/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs index a86b6c0f3e..d29201f95c 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs @@ -55,7 +55,7 @@ public enum CompilerOptions Force32Bit = 0x4, Library = 0x8, UseRoslyn1_3_2 = 0x10, - UseMcs = 0x20, + UseMcs2_6_4 = 0x20, ReferenceVisualBasic = 0x40, ReferenceCore = 0x80, GeneratePdb = 0x100, @@ -63,6 +63,8 @@ public enum CompilerOptions UseRoslyn2_10_0 = 0x400, UseRoslyn3_11_0 = 0x800, UseRoslynLatest = 0x1000, + UseMcs5_23 = 0x2000, + UseMcsMask = UseMcs2_6_4 | UseMcs5_23, UseRoslynMask = UseRoslyn1_3_2 | UseRoslyn2_10_0 | UseRoslyn3_11_0 | UseRoslynLatest } @@ -335,7 +337,7 @@ public static List GetPreprocessorSymbols(CompilerOptions flags) } } } - else if (flags.HasFlag(CompilerOptions.UseMcs)) + else if ((flags & CompilerOptions.UseMcsMask) != 0) { preprocessorSymbols.Add("MCS"); } @@ -361,7 +363,7 @@ public static CompilerResults CompileCSharp(string sourceFileName, CompilerOptio var preprocessorSymbols = GetPreprocessorSymbols(flags); - if (!flags.HasFlag(CompilerOptions.UseMcs)) + if ((flags & CompilerOptions.UseMcsMask) == 0) { CompilerResults results = new CompilerResults(new TempFileCollection()); results.PathToAssembly = outputFileName ?? Path.GetTempFileName(); @@ -476,7 +478,10 @@ public static CompilerResults CompileCSharp(string sourceFileName, CompilerOptio 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}\""); } - string mcsPath = Path.Combine(testBasePath, @"mcs\2.6.4\bin\gmcs.bat"); + string mcsPath = (flags & CompilerOptions.UseMcsMask) switch { + CompilerOptions.UseMcs5_23 => Path.Combine(testBasePath, @"mcs\5.23\bin\mcs.bat"), + _ => Path.Combine(testBasePath, @"mcs\2.6.4\bin\gmcs.bat") + }; string otherOptions = " -unsafe -o" + (flags.HasFlag(CompilerOptions.Optimize) ? "+ " : "- "); if (flags.HasFlag(CompilerOptions.Library)) @@ -544,7 +549,7 @@ internal static DecompilerSettings GetSettings(CompilerOptions cscOptions) else { var settings = new DecompilerSettings(CSharp.LanguageVersion.CSharp5); - if (cscOptions.HasFlag(CompilerOptions.UseMcs)) + if ((cscOptions & CompilerOptions.UseMcsMask) != 0) { // we don't recompile with mcs but with roslyn, so we can use ref locals settings.UseRefLocalsForAccurateOrderOfEvaluation = true; @@ -609,8 +614,10 @@ internal static string GetSuffix(CompilerOptions cscOptions) suffix += ".roslyn3"; if ((cscOptions & CompilerOptions.UseRoslynLatest) != 0) suffix += ".roslyn"; - if ((cscOptions & CompilerOptions.UseMcs) != 0) - suffix += ".mcs"; + if ((cscOptions & CompilerOptions.UseMcs2_6_4) != 0) + suffix += ".mcs2"; + if ((cscOptions & CompilerOptions.UseMcs5_23) != 0) + suffix += ".mcs5"; return suffix; } diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index 4c817a2336..e01d6dfdc9 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -127,8 +127,10 @@ public void AllFilesHaveTests() CompilerOptions.Optimize | CompilerOptions.UseRoslyn3_11_0, CompilerOptions.UseRoslynLatest, CompilerOptions.Optimize | CompilerOptions.UseRoslynLatest, - CompilerOptions.UseMcs, - CompilerOptions.Optimize | CompilerOptions.UseMcs + CompilerOptions.UseMcs2_6_4, + CompilerOptions.Optimize | CompilerOptions.UseMcs2_6_4, + CompilerOptions.UseMcs5_23, + CompilerOptions.Optimize | CompilerOptions.UseMcs5_23 }; [Test] diff --git a/ILSpy-tests b/ILSpy-tests index aa8f1197e6..6f8860e420 160000 --- a/ILSpy-tests +++ b/ILSpy-tests @@ -1 +1 @@ -Subproject commit aa8f1197e6a513bcc10bcc38ec7d2143d27a2246 +Subproject commit 6f8860e420b54bdfd726ec3c58a4d178416f9156