From cd200fa5046255ed0794eae360f2db6da6c4e424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Zgodzi=C5=84ski?= Date: Tue, 1 Mar 2011 18:36:22 +0100 Subject: [PATCH] Replaced MBUnit with NUnit. --- .../CustomAttributes/CustomAttributeTests.cs | 10 ++-- .../S_CustomAttributeSamples.cs | 2 +- .../Tests/DecompilerTestBase.cs | 21 +------- ...onstruction.cs => DelegateConstruction.cs} | 0 .../Tests/ICSharpCode.Decompiler.Tests.csproj | 13 ++--- ...iesAndEvents.cs => PropertiesAndEvents.cs} | 0 ICSharpCode.Decompiler/Tests/TestRunner.cs | 52 ------------------- .../Tests/Types/EnumTests.cs | 8 +-- .../Tests/Types/TypeTests.cs | 19 +------ .../{Types/S_ValueTypes.cs => ValueTypes.cs} | 0 10 files changed, 17 insertions(+), 108 deletions(-) rename ICSharpCode.Decompiler/Tests/{Types/S_DelegateConstruction.cs => DelegateConstruction.cs} (100%) rename ICSharpCode.Decompiler/Tests/{Types/S_PropertiesAndEvents.cs => PropertiesAndEvents.cs} (100%) rename ICSharpCode.Decompiler/Tests/{Types/S_ValueTypes.cs => ValueTypes.cs} (100%) diff --git a/ICSharpCode.Decompiler/Tests/CustomAttributes/CustomAttributeTests.cs b/ICSharpCode.Decompiler/Tests/CustomAttributes/CustomAttributeTests.cs index 76608c595..4f040b293 100644 --- a/ICSharpCode.Decompiler/Tests/CustomAttributes/CustomAttributeTests.cs +++ b/ICSharpCode.Decompiler/Tests/CustomAttributes/CustomAttributeTests.cs @@ -2,16 +2,16 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using MbUnit.Framework; +using NUnit.Framework; namespace ICSharpCode.Decompiler.Tests.CustomAttributes { public class CustomAttributeTests : DecompilerTestBase { - [StaticTestFactory] - public static IEnumerable CustomAttributeSamples() - { - return GenerateSectionTests(@"CustomAttributes\S_CustomAttributeSamples.cs"); + [Test] + public void CustomAttributeSamples() + { + ValidateFileRoundtrip(@"CustomAttributes\S_CustomAttributeSamples.cs"); } [Test] diff --git a/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs b/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs index 98b4a403b..aa6d4660a 100644 --- a/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs +++ b/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs @@ -46,7 +46,7 @@ namespace AttributeWithTypeArgument [AttributeUsage(AttributeTargets.All)] public class MyTypeAttribute : Attribute { - public MyTypeAttribute(Type t) + public MyTypeAttribute(Type t) : base() { } } diff --git a/ICSharpCode.Decompiler/Tests/DecompilerTestBase.cs b/ICSharpCode.Decompiler/Tests/DecompilerTestBase.cs index db4368cb7..c1a13b925 100644 --- a/ICSharpCode.Decompiler/Tests/DecompilerTestBase.cs +++ b/ICSharpCode.Decompiler/Tests/DecompilerTestBase.cs @@ -7,31 +7,12 @@ using System.IO; using Decompiler; using Microsoft.CSharp; using System.CodeDom.Compiler; -using MbUnit.Framework; +using NUnit.Framework; namespace ICSharpCode.Decompiler.Tests { public abstract class DecompilerTestBase { - protected static IEnumerable GenerateSectionTests(string samplesFileName) - { - string code = File.ReadAllText(Path.Combine(@"..\..\Tests", samplesFileName)); - foreach (var sectionName in CodeSampleFileParser.ListSections(code)) - { - if (sectionName.EndsWith("(ignored)", StringComparison.OrdinalIgnoreCase)) - continue; - - var testedSectionName = sectionName; - yield return new TestCase(testedSectionName, () => - { - var testCode = CodeSampleFileParser.GetSection(testedSectionName, code); - System.Diagnostics.Debug.WriteLine(testCode); - var decompiledTestCode = RoundtripCode(testCode); - Assert.AreEqual(testCode, decompiledTestCode); - }); - } - } - protected static void ValidateFileRoundtrip(string samplesFileName) { var lines = File.ReadAllLines(Path.Combine(@"..\..\Tests", samplesFileName)); diff --git a/ICSharpCode.Decompiler/Tests/Types/S_DelegateConstruction.cs b/ICSharpCode.Decompiler/Tests/DelegateConstruction.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/Types/S_DelegateConstruction.cs rename to ICSharpCode.Decompiler/Tests/DelegateConstruction.cs diff --git a/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj index 146aca67d..d7b6f327a 100644 --- a/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj @@ -38,10 +38,7 @@ TRACE - - False - - + False @@ -59,10 +56,10 @@ - + - - + + @@ -72,7 +69,7 @@ - + diff --git a/ICSharpCode.Decompiler/Tests/Types/S_PropertiesAndEvents.cs b/ICSharpCode.Decompiler/Tests/PropertiesAndEvents.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/Types/S_PropertiesAndEvents.cs rename to ICSharpCode.Decompiler/Tests/PropertiesAndEvents.cs diff --git a/ICSharpCode.Decompiler/Tests/TestRunner.cs b/ICSharpCode.Decompiler/Tests/TestRunner.cs index d726f91a4..543200603 100644 --- a/ICSharpCode.Decompiler/Tests/TestRunner.cs +++ b/ICSharpCode.Decompiler/Tests/TestRunner.cs @@ -9,7 +9,6 @@ using System.Text; using Decompiler; using Microsoft.CSharp; using Mono.Cecil; -using MbUnit.Framework; namespace ICSharpCode.Decompiler.Tests { @@ -22,24 +21,6 @@ namespace ICSharpCode.Decompiler.Tests Console.ReadKey(); } - public void RoundtripFile(string fileName) - { - string code = File.ReadAllText(fileName); - AssemblyDefinition assembly = Compile(code); - AstBuilder decompiler = new AstBuilder(new DecompilerContext()); - decompiler.AddAssembly(assembly); - StringWriter output = new StringWriter(); - decompiler.GenerateCode(new PlainTextOutput(output)); - - var decompiledCode = output.ToString(); - var onlyCode = "using System;" + Environment.NewLine + StripCodeFileHeader(code); - - File.WriteAllText(Path.ChangeExtension(fileName, ".decomp.cs"), decompiledCode); - File.WriteAllText(Path.ChangeExtension(fileName, ".code.cs"), onlyCode); - - Assert.AreEqual(onlyCode, decompiledCode); - } - static void TestFile(string fileName) { string code = File.ReadAllText(fileName); @@ -55,39 +36,6 @@ namespace ICSharpCode.Decompiler.Tests } } - static string StripCodeFileHeader(string code) - { - var reader = new StringReader(code); - - var buffer = new StringWriter(); - - string line; - var skipBlankLine = false; - while ((line = reader.ReadLine()) != null) - { - if (line.Trim().StartsWith("//")) - { - skipBlankLine = true; - continue; - } - else if (line.StartsWith("using ")) - { - skipBlankLine = true; - continue; - } - else if (skipBlankLine && String.IsNullOrWhiteSpace(line)) - { - continue; - } - - skipBlankLine = false; - - buffer.WriteLine(line); - } - - return buffer.ToString(); - } - static bool Compare(string input1, string input2, StringWriter diff) { bool ok = true; diff --git a/ICSharpCode.Decompiler/Tests/Types/EnumTests.cs b/ICSharpCode.Decompiler/Tests/Types/EnumTests.cs index 07af8968b..b84147082 100644 --- a/ICSharpCode.Decompiler/Tests/Types/EnumTests.cs +++ b/ICSharpCode.Decompiler/Tests/Types/EnumTests.cs @@ -2,16 +2,16 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using MbUnit.Framework; +using NUnit.Framework; namespace ICSharpCode.Decompiler.Tests.Types { public class EnumTests : DecompilerTestBase { - [StaticTestFactory] - public static IEnumerable EnumSamples() + [Test] + public void EnumSamples() { - return GenerateSectionTests(@"Types\S_EnumSamples.cs"); + ValidateFileRoundtrip(@"Types\S_EnumSamples.cs"); } } } diff --git a/ICSharpCode.Decompiler/Tests/Types/TypeTests.cs b/ICSharpCode.Decompiler/Tests/Types/TypeTests.cs index 3875edd1c..56d7db39f 100644 --- a/ICSharpCode.Decompiler/Tests/Types/TypeTests.cs +++ b/ICSharpCode.Decompiler/Tests/Types/TypeTests.cs @@ -2,28 +2,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using MbUnit.Framework; +using NUnit.Framework; namespace ICSharpCode.Decompiler.Tests.Types { public class TypeTests : DecompilerTestBase { - [Test] - public void ValueTypes() - { - ValidateFileRoundtrip(@"Types\S_ValueTypes.cs"); - } - - [Test] - public void PropertiesAndEvents() - { - ValidateFileRoundtrip(@"Types\S_PropertiesAndEvents.cs"); - } - - [Test] - public void DelegateConstruction() - { - ValidateFileRoundtrip(@"Types\S_DelegateConstruction.cs"); - } } } diff --git a/ICSharpCode.Decompiler/Tests/Types/S_ValueTypes.cs b/ICSharpCode.Decompiler/Tests/ValueTypes.cs similarity index 100% rename from ICSharpCode.Decompiler/Tests/Types/S_ValueTypes.cs rename to ICSharpCode.Decompiler/Tests/ValueTypes.cs