From c56f5e8491716006d64d3f0cbe0b1a87ff9200ae Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 24 Sep 2017 21:53:51 +0200 Subject: [PATCH] Move some test-cases to Patterns.cs --- .../TestCases/Correctness/Patterns.cs | 48 +++++++++++- .../TestCases/Pretty/Using.cs | 25 ------ .../TestCases/Pretty/Using.il | 77 +------------------ .../TestCases/Pretty/Using.opt.il | 65 +--------------- .../TestCases/Pretty/Using.opt.roslyn.il | 61 +-------------- .../TestCases/Pretty/Using.roslyn.il | 71 +---------------- 6 files changed, 59 insertions(+), 288 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Patterns.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Patterns.cs index 57a4e479b..fdb281baa 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Patterns.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Patterns.cs @@ -9,16 +9,36 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness /// /// This file contains special cases of some patterns that cannot be tested in pretty tests. /// - class Patterns + static class Patterns { + #region Test Helpers + class PrintOnDispose : IDisposable + { + private string v; + + public PrintOnDispose(string v) + { + this.v = v; + } + + public void Dispose() + { + Console.WriteLine(this.v); + } + } + #endregion + static void Main() { SimpleUsingNullStatement(); + NoUsing(); + NoUsing2(); ForWithMultipleVariables(); DoubleForEachWithSameVariable(new[] { "a", "b", "c" }); ForeachExceptForNameCollision(new[] { 42, 43, 44, 45 }); } + #region Using /// /// Special case: Roslyn eliminates the try-finally altogether. /// @@ -31,6 +51,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness Console.WriteLine("after using"); } + public static void NoUsing() + { + PrintOnDispose printOnDispose = new PrintOnDispose("Wrong"); + try { + printOnDispose = new PrintOnDispose("Correct"); + } finally { + printOnDispose.Dispose(); + } + } + + public static void NoUsing2() + { + object printOnDispose = new PrintOnDispose("NoUsing(): Wrong"); + try { + printOnDispose = new PrintOnDispose("NoUsing(): Correct"); + } finally { + IDisposable disposable = printOnDispose as IDisposable; + if (disposable != null) { + disposable.Dispose(); + } + } + } + #endregion + + #region Loops public static void ForWithMultipleVariables() { int x, y; @@ -68,5 +113,6 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness current = 1; Console.WriteLine(current); } + #endregion } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs index fc041f2c1..d8f1a79b8 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs @@ -39,21 +39,6 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } - private class PrintOnDispose : IDisposable - { - private string v; - - public PrintOnDispose(string v) - { - this.v = v; - } - - public void Dispose() - { - Console.WriteLine(this.v); - } - } - #if LEGACY_CSC public void SimpleUsingNullStatement() { @@ -121,15 +106,5 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine(t); } } - - public void NoUsing() - { - PrintOnDispose printOnDispose = new PrintOnDispose("Wrong"); - try { - printOnDispose = new PrintOnDispose("Correct"); - } finally { - printOnDispose.Dispose(); - } - } } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.il index 875fbf181..f7b338a69 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly vu3cz5gg +.assembly dybef0h5 { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module vu3cz5gg.dll -// MVID: {FD1D14F2-B901-4ADC-A6BA-6844964F643A} +.module dybef0h5.dll +// MVID: {469DF7ED-3C07-4983-A672-891B2A428600} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x00F10000 +// Image base: 0x003C0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -67,42 +67,6 @@ } // end of class UsingStruct - .class auto ansi nested private beforefieldinit PrintOnDispose - extends [mscorlib]System.Object - implements [mscorlib]System.IDisposable - { - .field private string v - .method public hidebysig specialname rtspecialname - instance void .ctor(string v) cil managed - { - // Code size 17 (0x11) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void [mscorlib]System.Object::.ctor() - IL_0006: nop - IL_0007: nop - IL_0008: ldarg.0 - IL_0009: ldarg.1 - IL_000a: stfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v - IL_000f: nop - IL_0010: ret - } // end of method PrintOnDispose::.ctor - - .method public hidebysig newslot virtual final - instance void Dispose() cil managed - { - // Code size 14 (0xe) - .maxstack 8 - IL_0000: nop - IL_0001: ldarg.0 - IL_0002: ldfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v - IL_0007: call void [mscorlib]System.Console::WriteLine(string) - IL_000c: nop - IL_000d: ret - } // end of method PrintOnDispose::Dispose - - } // end of class PrintOnDispose - .method public hidebysig instance void SimpleUsingNullStatement() cil managed { @@ -452,39 +416,6 @@ IL_0030: ret } // end of method Using::GenericClassUsing - .method public hidebysig instance void - NoUsing() cil managed - { - // Code size 39 (0x27) - .maxstack 1 - .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose V_0) - IL_0000: nop - IL_0001: ldstr "Wrong" - IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string) - IL_000b: stloc.0 - .try - { - IL_000c: nop - IL_000d: ldstr "Correct" - IL_0012: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string) - IL_0017: stloc.0 - IL_0018: nop - IL_0019: leave.s IL_0025 - - } // end .try - finally - { - IL_001b: nop - IL_001c: ldloc.0 - IL_001d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::Dispose() - IL_0022: nop - IL_0023: nop - IL_0024: endfinally - } // end handler - IL_0025: nop - IL_0026: ret - } // end of method Using::NoUsing - .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.il index 968f4cf3e..7560b8e76 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly vexl0swc +.assembly nwychzte { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module vexl0swc.dll -// MVID: {EB6E7617-FC1E-4784-86CC-81DA71679C35} +.module nwychzte.dll +// MVID: {142BA3BD-C0CA-4005-A426-112E6C543819} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x00BE0000 +// Image base: 0x025B0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -64,37 +64,6 @@ } // end of class UsingStruct - .class auto ansi nested private beforefieldinit PrintOnDispose - extends [mscorlib]System.Object - implements [mscorlib]System.IDisposable - { - .field private string v - .method public hidebysig specialname rtspecialname - instance void .ctor(string v) cil managed - { - // Code size 14 (0xe) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void [mscorlib]System.Object::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v - IL_000d: ret - } // end of method PrintOnDispose::.ctor - - .method public hidebysig newslot virtual final - instance void Dispose() cil managed - { - // Code size 12 (0xc) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v - IL_0006: call void [mscorlib]System.Console::WriteLine(string) - IL_000b: ret - } // end of method PrintOnDispose::Dispose - - } // end of class PrintOnDispose - .method public hidebysig instance void SimpleUsingNullStatement() cil managed { @@ -358,32 +327,6 @@ IL_0025: ret } // end of method Using::GenericClassUsing - .method public hidebysig instance void - NoUsing() cil managed - { - // Code size 32 (0x20) - .maxstack 1 - .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose V_0) - IL_0000: ldstr "Wrong" - IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string) - IL_000a: stloc.0 - .try - { - IL_000b: ldstr "Correct" - IL_0010: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string) - IL_0015: stloc.0 - IL_0016: leave.s IL_001f - - } // end .try - finally - { - IL_0018: ldloc.0 - IL_0019: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::Dispose() - IL_001e: endfinally - } // end handler - IL_001f: ret - } // end of method Using::NoUsing - .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.roslyn.il index dc2834015..470b006c8 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Using.dll -// MVID: {6ACE0D07-2500-4E79-B8A5-908F446B5708} +// MVID: {F795B575-6F0C-4E56-817C-B7689ECEE4A6} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x01950000 +// Image base: 0x003F0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -68,37 +68,6 @@ } // end of class UsingStruct - .class auto ansi nested private beforefieldinit PrintOnDispose - extends [mscorlib]System.Object - implements [mscorlib]System.IDisposable - { - .field private string v - .method public hidebysig specialname rtspecialname - instance void .ctor(string v) cil managed - { - // Code size 14 (0xe) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void [mscorlib]System.Object::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v - IL_000d: ret - } // end of method PrintOnDispose::.ctor - - .method public hidebysig newslot virtual final - instance void Dispose() cil managed - { - // Code size 12 (0xc) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v - IL_0006: call void [mscorlib]System.Console::WriteLine(string) - IL_000b: ret - } // end of method PrintOnDispose::Dispose - - } // end of class PrintOnDispose - .method public hidebysig instance void SimpleUsingExpressionStatement() cil managed { @@ -335,32 +304,6 @@ IL_0023: ret } // end of method Using::GenericClassUsing - .method public hidebysig instance void - NoUsing() cil managed - { - // Code size 32 (0x20) - .maxstack 1 - .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose V_0) - IL_0000: ldstr "Wrong" - IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string) - IL_000a: stloc.0 - .try - { - IL_000b: ldstr "Correct" - IL_0010: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string) - IL_0015: stloc.0 - IL_0016: leave.s IL_001f - - } // end .try - finally - { - IL_0018: ldloc.0 - IL_0019: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::Dispose() - IL_001e: endfinally - } // end handler - IL_001f: ret - } // end of method Using::NoUsing - .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.roslyn.il index d5252c315..07172f093 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.roslyn.il @@ -25,14 +25,14 @@ .ver 0:0:0:0 } .module Using.dll -// MVID: {01A69772-54AF-4C5E-875F-47130AC714FC} +// MVID: {297FC1D9-B0EF-4868-95FD-EA7385BE32F8} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x02BE0000 +// Image base: 0x027F0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -71,41 +71,6 @@ } // end of class UsingStruct - .class auto ansi nested private beforefieldinit PrintOnDispose - extends [mscorlib]System.Object - implements [mscorlib]System.IDisposable - { - .field private string v - .method public hidebysig specialname rtspecialname - instance void .ctor(string v) cil managed - { - // Code size 16 (0x10) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void [mscorlib]System.Object::.ctor() - IL_0006: nop - IL_0007: nop - IL_0008: ldarg.0 - IL_0009: ldarg.1 - IL_000a: stfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v - IL_000f: ret - } // end of method PrintOnDispose::.ctor - - .method public hidebysig newslot virtual final - instance void Dispose() cil managed - { - // Code size 14 (0xe) - .maxstack 8 - IL_0000: nop - IL_0001: ldarg.0 - IL_0002: ldfld string ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::v - IL_0007: call void [mscorlib]System.Console::WriteLine(string) - IL_000c: nop - IL_000d: ret - } // end of method PrintOnDispose::Dispose - - } // end of class PrintOnDispose - .method public hidebysig instance void SimpleUsingExpressionStatement() cil managed { @@ -383,38 +348,6 @@ IL_0028: ret } // end of method Using::GenericClassUsing - .method public hidebysig instance void - NoUsing() cil managed - { - // Code size 38 (0x26) - .maxstack 1 - .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose V_0) - IL_0000: nop - IL_0001: ldstr "Wrong" - IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string) - IL_000b: stloc.0 - .try - { - IL_000c: nop - IL_000d: ldstr "Correct" - IL_0012: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::.ctor(string) - IL_0017: stloc.0 - IL_0018: nop - IL_0019: leave.s IL_0025 - - } // end .try - finally - { - IL_001b: nop - IL_001c: ldloc.0 - IL_001d: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Using/PrintOnDispose::Dispose() - IL_0022: nop - IL_0023: nop - IL_0024: endfinally - } // end handler - IL_0025: ret - } // end of method Using::NoUsing - .method public hidebysig specialname rtspecialname instance void .ctor() cil managed {