Browse Source

Replaced MBUnit with NUnit.

pull/70/head
Artur Zgodziski 15 years ago
parent
commit
cd200fa504
  1. 10
      ICSharpCode.Decompiler/Tests/CustomAttributes/CustomAttributeTests.cs
  2. 2
      ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs
  3. 21
      ICSharpCode.Decompiler/Tests/DecompilerTestBase.cs
  4. 0
      ICSharpCode.Decompiler/Tests/DelegateConstruction.cs
  5. 13
      ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj
  6. 0
      ICSharpCode.Decompiler/Tests/PropertiesAndEvents.cs
  7. 52
      ICSharpCode.Decompiler/Tests/TestRunner.cs
  8. 8
      ICSharpCode.Decompiler/Tests/Types/EnumTests.cs
  9. 19
      ICSharpCode.Decompiler/Tests/Types/TypeTests.cs
  10. 0
      ICSharpCode.Decompiler/Tests/ValueTypes.cs

10
ICSharpCode.Decompiler/Tests/CustomAttributes/CustomAttributeTests.cs

@ -2,16 +2,16 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using MbUnit.Framework; using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests.CustomAttributes namespace ICSharpCode.Decompiler.Tests.CustomAttributes
{ {
public class CustomAttributeTests : DecompilerTestBase public class CustomAttributeTests : DecompilerTestBase
{ {
[StaticTestFactory] [Test]
public static IEnumerable<Test> CustomAttributeSamples() public void CustomAttributeSamples()
{ {
return GenerateSectionTests(@"CustomAttributes\S_CustomAttributeSamples.cs"); ValidateFileRoundtrip(@"CustomAttributes\S_CustomAttributeSamples.cs");
} }
[Test] [Test]

2
ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs

@ -46,7 +46,7 @@ namespace AttributeWithTypeArgument
[AttributeUsage(AttributeTargets.All)] [AttributeUsage(AttributeTargets.All)]
public class MyTypeAttribute : Attribute public class MyTypeAttribute : Attribute
{ {
public MyTypeAttribute(Type t) public MyTypeAttribute(Type t) : base()
{ {
} }
} }

21
ICSharpCode.Decompiler/Tests/DecompilerTestBase.cs

@ -7,31 +7,12 @@ using System.IO;
using Decompiler; using Decompiler;
using Microsoft.CSharp; using Microsoft.CSharp;
using System.CodeDom.Compiler; using System.CodeDom.Compiler;
using MbUnit.Framework; using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests namespace ICSharpCode.Decompiler.Tests
{ {
public abstract class DecompilerTestBase public abstract class DecompilerTestBase
{ {
protected static IEnumerable<Test> 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) protected static void ValidateFileRoundtrip(string samplesFileName)
{ {
var lines = File.ReadAllLines(Path.Combine(@"..\..\Tests", samplesFileName)); var lines = File.ReadAllLines(Path.Combine(@"..\..\Tests", samplesFileName));

0
ICSharpCode.Decompiler/Tests/Types/S_DelegateConstruction.cs → ICSharpCode.Decompiler/Tests/DelegateConstruction.cs

13
ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj

@ -38,10 +38,7 @@
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Gallio, Version=3.3.0.0, Culture=neutral, PublicKeyToken=eb9cfa67ee6ab36e, processorArchitecture=MSIL"> <Reference Include="nunit.framework, Version=2.5.9.10348, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="MbUnit, Version=3.3.0.0, Culture=neutral, PublicKeyToken=eb9cfa67ee6ab36e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
@ -59,10 +56,10 @@
<Compile Include="Helpers\RemoveCompilerAttribute.cs" /> <Compile Include="Helpers\RemoveCompilerAttribute.cs" />
<Compile Include="Types\EnumTests.cs" /> <Compile Include="Types\EnumTests.cs" />
<Compile Include="Types\TypeTests.cs" /> <Compile Include="Types\TypeTests.cs" />
<None Include="Types\S_DelegateConstruction.cs" /> <Compile Include="DelegateConstruction.cs" />
<None Include="CustomAttributes\S_CustomAttributes.cs" /> <None Include="CustomAttributes\S_CustomAttributes.cs" />
<None Include="Loops.cs" /> <Compile Include="Loops.cs" />
<None Include="Types\S_PropertiesAndEvents.cs" /> <Compile Include="PropertiesAndEvents.cs" />
<None Include="CustomAttributes\S_CustomAttributeSamples.cs" /> <None Include="CustomAttributes\S_CustomAttributeSamples.cs" />
<Compile Include="CodeSampleFileParser.cs" /> <Compile Include="CodeSampleFileParser.cs" />
<Compile Include="CustomAttributes\CustomAttributeTests.cs" /> <Compile Include="CustomAttributes\CustomAttributeTests.cs" />
@ -72,7 +69,7 @@
<Compile Include="Generics.cs" /> <Compile Include="Generics.cs" />
<Compile Include="MultidimensionalArray.cs" /> <Compile Include="MultidimensionalArray.cs" />
<Compile Include="TestRunner.cs" /> <Compile Include="TestRunner.cs" />
<None Include="Types\S_ValueTypes.cs" /> <Compile Include="ValueTypes.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Mono.Cecil\Mono.Cecil.csproj"> <ProjectReference Include="..\..\Mono.Cecil\Mono.Cecil.csproj">

0
ICSharpCode.Decompiler/Tests/Types/S_PropertiesAndEvents.cs → ICSharpCode.Decompiler/Tests/PropertiesAndEvents.cs

52
ICSharpCode.Decompiler/Tests/TestRunner.cs

@ -9,7 +9,6 @@ using System.Text;
using Decompiler; using Decompiler;
using Microsoft.CSharp; using Microsoft.CSharp;
using Mono.Cecil; using Mono.Cecil;
using MbUnit.Framework;
namespace ICSharpCode.Decompiler.Tests namespace ICSharpCode.Decompiler.Tests
{ {
@ -22,24 +21,6 @@ namespace ICSharpCode.Decompiler.Tests
Console.ReadKey(); 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) static void TestFile(string fileName)
{ {
string code = File.ReadAllText(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) static bool Compare(string input1, string input2, StringWriter diff)
{ {
bool ok = true; bool ok = true;

8
ICSharpCode.Decompiler/Tests/Types/EnumTests.cs

@ -2,16 +2,16 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using MbUnit.Framework; using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests.Types namespace ICSharpCode.Decompiler.Tests.Types
{ {
public class EnumTests : DecompilerTestBase public class EnumTests : DecompilerTestBase
{ {
[StaticTestFactory] [Test]
public static IEnumerable<Test> EnumSamples() public void EnumSamples()
{ {
return GenerateSectionTests(@"Types\S_EnumSamples.cs"); ValidateFileRoundtrip(@"Types\S_EnumSamples.cs");
} }
} }
} }

19
ICSharpCode.Decompiler/Tests/Types/TypeTests.cs

@ -2,28 +2,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using MbUnit.Framework; using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests.Types namespace ICSharpCode.Decompiler.Tests.Types
{ {
public class TypeTests : DecompilerTestBase 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");
}
} }
} }

0
ICSharpCode.Decompiler/Tests/Types/S_ValueTypes.cs → ICSharpCode.Decompiler/Tests/ValueTypes.cs

Loading…
Cancel
Save