From 6c57304684cc196b9d4cbd7f9a9db1d2aa1d00c9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 10 Jul 2016 08:36:19 +0900 Subject: [PATCH] Reorganize TestRunner-Tests --- ...TestRunner.cs => CorrectnessTestRunner.cs} | 19 ++------ .../Tests/ICSharpCode.Decompiler.Tests.csproj | 39 ++++++++-------- .../Tests/TestCases/ConvTest.il | 44 ------------------- .../TestCases/{ => Correctness}/BitNot.il | 0 .../{ => Correctness}/Comparisons.cs | 0 .../{ => Correctness}/CompoundAssignment.cs | 0 .../{ => Correctness}/ControlFlow.cs | 0 .../{ => Correctness}/Conversions.cs | 2 +- .../{ => Correctness}/DecimalFields.cs | 0 .../TestCases/{ => Correctness}/Generics.cs | 0 .../TestCases/{ => Correctness}/HelloWorld.cs | 0 .../{ => Correctness}/InitializerTests.cs | 0 .../{ => Correctness}/MemberLookup.cs | 0 .../{ => Correctness}/PropertiesAndEvents.cs | 0 .../TestCases/{ => Correctness}/Readme.txt | 2 +- .../TestCases/{ => Correctness}/Switch.cs | 0 .../UndocumentedExpressions.cs | 0 .../TestCases/{ => Correctness}/UnsafeCode.cs | 0 .../{ => Correctness}/ValueTypeCall.cs | 0 .../Tests/TestCases/ILTest.il | 29 ------------ .../Tests/TestCases/Pretty/Readme.txt | 14 ++++++ 21 files changed, 39 insertions(+), 110 deletions(-) rename ICSharpCode.Decompiler/Tests/{TestRunner.cs => CorrectnessTestRunner.cs} (90%) delete mode 100644 ICSharpCode.Decompiler/Tests/TestCases/ConvTest.il rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/BitNot.il (100%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/Comparisons.cs (100%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/CompoundAssignment.cs (100%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/ControlFlow.cs (100%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/Conversions.cs (97%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/DecimalFields.cs (100%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/Generics.cs (100%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/HelloWorld.cs (100%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/InitializerTests.cs (100%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/MemberLookup.cs (100%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/PropertiesAndEvents.cs (100%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/Readme.txt (89%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/Switch.cs (100%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/UndocumentedExpressions.cs (100%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/UnsafeCode.cs (100%) rename ICSharpCode.Decompiler/Tests/TestCases/{ => Correctness}/ValueTypeCall.cs (100%) delete mode 100644 ICSharpCode.Decompiler/Tests/TestCases/ILTest.il create mode 100644 ICSharpCode.Decompiler/Tests/TestCases/Pretty/Readme.txt diff --git a/ICSharpCode.Decompiler/Tests/TestRunner.cs b/ICSharpCode.Decompiler/Tests/CorrectnessTestRunner.cs similarity index 90% rename from ICSharpCode.Decompiler/Tests/TestRunner.cs rename to ICSharpCode.Decompiler/Tests/CorrectnessTestRunner.cs index fa62dce83..4b1c4fb73 100644 --- a/ICSharpCode.Decompiler/Tests/TestRunner.cs +++ b/ICSharpCode.Decompiler/Tests/CorrectnessTestRunner.cs @@ -11,14 +11,14 @@ using NUnit.Framework; namespace ICSharpCode.Decompiler.Tests { [TestFixture] - public class TestRunner + public class CorrectnessTestRunner { - const string TestCasePath = @"../../Tests/TestCases"; + const string TestCasePath = @"../../Tests/TestCases/Correctness"; [Test] public void AllFilesHaveTests() { - var testNames = typeof(TestRunner).GetMethods() + var testNames = typeof(CorrectnessTestRunner).GetMethods() .Where(m => m.GetCustomAttributes(typeof(TestAttribute), false).Any()) .Select(m => m.Name) .ToArray(); @@ -107,19 +107,6 @@ namespace ICSharpCode.Decompiler.Tests { TestCompileDecompileCompileOutputAll("MemberLookup.cs"); } - - [Test] - public void ILTest() - { - TestAssembleDecompileCompileOutput("ILTest.il"); - } - - [Test] - public void ConvTest() - { - TestAssembleDecompileCompileOutput("ConvTest.il"); - TestAssembleDecompileCompileOutput("ConvTest.il", CompilerOptions.UseDebug | CompilerOptions.Force32Bit, AssemblerOptions.Force32Bit); - } [Test] public void BitNot() diff --git a/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj index 65f8cb6f4..a5ba198ae 100644 --- a/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj @@ -89,9 +89,8 @@ - - - + + @@ -118,21 +117,21 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -145,6 +144,8 @@ - + + + \ No newline at end of file diff --git a/ICSharpCode.Decompiler/Tests/TestCases/ConvTest.il b/ICSharpCode.Decompiler/Tests/TestCases/ConvTest.il deleted file mode 100644 index f8c867cba..000000000 --- a/ICSharpCode.Decompiler/Tests/TestCases/ConvTest.il +++ /dev/null @@ -1,44 +0,0 @@ -.assembly extern mscorlib -{ - .publickeytoken = ( - b7 7a 5c 56 19 34 e0 89 - ) - .ver 4:0:0:0 -} - -.assembly 'ConvTest' -{ - .ver 0:0:0:0 -} - -.module ConvTest.exe -// MVID: {987E1A15-519A-400C-B879-759CFB7F990B} -.corflags 0x00000001 // ILOnly - -.class private auto ansi abstract sealed beforefieldinit Program - extends [mscorlib]System.Object -{ - .method public hidebysig static void Print (native int) cil managed { - ldarg.0 - box [mscorlib]System.IntPtr - call void [mscorlib]System.Console::WriteLine(object) - ret - } - - .method public hidebysig static void Main (string[] args) cil managed { - .entrypoint - .try { - ldc.i4.0 - call void Program::Print(native int) - ldc.i8 7595444518666557374 - conv.i - call void Program::Print(native int) - leave.s eof - } catch [mscorlib]System.Exception { - callvirt instance string [mscorlib]System.Object::ToString() - call void [mscorlib]System.Console::WriteLine(object) - leave.s eof - } - eof: ret - } -} diff --git a/ICSharpCode.Decompiler/Tests/TestCases/BitNot.il b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/BitNot.il similarity index 100% rename from ICSharpCode.Decompiler/Tests/TestCases/BitNot.il rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/BitNot.il diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Comparisons.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Comparisons.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/TestCases/Comparisons.cs rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/Comparisons.cs diff --git a/ICSharpCode.Decompiler/Tests/TestCases/CompoundAssignment.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/CompoundAssignment.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/TestCases/CompoundAssignment.cs rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/CompoundAssignment.cs diff --git a/ICSharpCode.Decompiler/Tests/TestCases/ControlFlow.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/ControlFlow.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/TestCases/ControlFlow.cs rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/ControlFlow.cs diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Conversions.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Conversions.cs similarity index 97% rename from ICSharpCode.Decompiler/Tests/TestCases/Conversions.cs rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/Conversions.cs index fce64996c..2587b2ed0 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Conversions.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Conversions.cs @@ -16,7 +16,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// #include "../../../NRefactory/ICSharpCode.NRefactory/Utils/CSharpPrimitiveCast.cs" +// #include "../../../../NRefactory/ICSharpCode.NRefactory/Utils/CSharpPrimitiveCast.cs" using System; using ICSharpCode.NRefactory.Utils; diff --git a/ICSharpCode.Decompiler/Tests/TestCases/DecimalFields.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/DecimalFields.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/TestCases/DecimalFields.cs rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/DecimalFields.cs diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Generics.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Generics.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/TestCases/Generics.cs rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/Generics.cs diff --git a/ICSharpCode.Decompiler/Tests/TestCases/HelloWorld.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/HelloWorld.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/TestCases/HelloWorld.cs rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/HelloWorld.cs diff --git a/ICSharpCode.Decompiler/Tests/TestCases/InitializerTests.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/InitializerTests.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/TestCases/InitializerTests.cs rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/InitializerTests.cs diff --git a/ICSharpCode.Decompiler/Tests/TestCases/MemberLookup.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/MemberLookup.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/TestCases/MemberLookup.cs rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/MemberLookup.cs diff --git a/ICSharpCode.Decompiler/Tests/TestCases/PropertiesAndEvents.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/PropertiesAndEvents.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/TestCases/PropertiesAndEvents.cs rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/PropertiesAndEvents.cs diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Readme.txt b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Readme.txt similarity index 89% rename from ICSharpCode.Decompiler/Tests/TestCases/Readme.txt rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/Readme.txt index c98b8dc4b..b4f917d13 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Readme.txt +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Readme.txt @@ -1,6 +1,6 @@ The files in this folder are correctness tests for the decompiler. -The NUnit class running these tests is ../TestRunner.cs. +The NUnit class running these tests is ../../CorrectnessTestRunner.cs. We: * compile/assemble a test case (call the result "executable 1") diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Switch.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Switch.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/TestCases/Switch.cs rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/Switch.cs diff --git a/ICSharpCode.Decompiler/Tests/TestCases/UndocumentedExpressions.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/UndocumentedExpressions.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/TestCases/UndocumentedExpressions.cs rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/UndocumentedExpressions.cs diff --git a/ICSharpCode.Decompiler/Tests/TestCases/UnsafeCode.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/UnsafeCode.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/TestCases/UnsafeCode.cs rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/UnsafeCode.cs diff --git a/ICSharpCode.Decompiler/Tests/TestCases/ValueTypeCall.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/ValueTypeCall.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/TestCases/ValueTypeCall.cs rename to ICSharpCode.Decompiler/Tests/TestCases/Correctness/ValueTypeCall.cs diff --git a/ICSharpCode.Decompiler/Tests/TestCases/ILTest.il b/ICSharpCode.Decompiler/Tests/TestCases/ILTest.il deleted file mode 100644 index c238ce524..000000000 --- a/ICSharpCode.Decompiler/Tests/TestCases/ILTest.il +++ /dev/null @@ -1,29 +0,0 @@ -// C:\Users\Siegfried\Documents\SharpDevelop Projects\HelloWorld\HelloWorld\bin\Debug\HelloWorld.exe - -.assembly extern mscorlib -{ - .publickeytoken = ( b7 7a 5c 56 19 34 e0 89 ) - .ver 4:0:0:0 -} -.assembly HelloWorld -{ - .ver 0:0:0:0 -} - -.module HelloWorld.exe -.corflags 0x00000001 // ILOnly - - -.class private auto ansi abstract sealed beforefieldinit Program - extends [mscorlib]System.Object -{ - .method public hidebysig static void Main (string[] args) cil managed - { - .maxstack 8 - .entrypoint - - ldstr "Hello World!" - call void [mscorlib]System.Console::WriteLine(string) - ret - } // end of method Main -} // end of class diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Pretty/Readme.txt b/ICSharpCode.Decompiler/Tests/TestCases/Pretty/Readme.txt new file mode 100644 index 000000000..e48d8f38e --- /dev/null +++ b/ICSharpCode.Decompiler/Tests/TestCases/Pretty/Readme.txt @@ -0,0 +1,14 @@ +The files in this folder are prettiness tests for the decompiler. + +The NUnit class running these tests is ../PrettyTestRunner.cs. +It uses pre-defined IL files in order to avoid test failures in cause of compiler changes. +We test different C# compiler versions as well (in future). + +Each test consists of a C# file for comparing the resulting code and a source IL file used for assembling/decompiling. + +We: +* assemble a test case (call the result "executable 1") +* decompile "executable 1" to C# ("decompiled.cs") +* compare "decompiled.cs" to "source.cs" + +The tests pass if the code looks exactly the same as the input code, ignoring comments, empty lines and preprocessor directives.