Browse Source

Add CSharpLanguageTests.

pull/1243/head
Siegfried Pammer 8 years ago
parent
commit
aa26ea2733
  1. 70
      ILSpy.Tests/ILSpy.Tests.csproj
  2. 129
      ILSpy.Tests/Languages/CSharpLanguageTests.cs
  3. 11
      ILSpy.Tests/Stub.cs
  4. 8
      ILSpy.sln
  5. 1
      appveyor.yml

70
ILSpy.Tests/ILSpy.Tests.csproj

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net46</TargetFramework>
<LangVersion>7.3</LangVersion>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<NoWarn>1701;1702;1705,67,169,1058,728,1720,649,168,251</NoWarn>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<EnableDefaultItems>false</EnableDefaultItems>
<OutputType>Exe</OutputType>
<StartupObject>ILSpy.Tests.Stub</StartupObject>
<AutoGenerateBindingRedirects>True</AutoGenerateBindingRedirects>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;DEBUG;NET46;ROSLYN;CS60;CS70</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\ICSharpCode.Decompiler.Tests\TypeSystem\TypeSystemTestCase.cs" Link="TestCases\TypeSystemTestCase.cs" />
<Compile Include="Languages\CSharpLanguageTests.cs" />
<Compile Include="Stub.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DiffLib" Version="2017.7.26.1241" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="2.8.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.3.1" />
<PackageReference Include="NUnit" Version="3.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.csproj" />
<ProjectReference Include="..\ILSpy\ILSpy.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<Folder Include="TestCases\" />
</ItemGroup>
</Project>

129
ILSpy.Tests/Languages/CSharpLanguageTests.cs

@ -0,0 +1,129 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.Tests.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem.Implementation;
using ICSharpCode.ILSpy;
using NUnit.Framework;
namespace ILSpy.Tests.Languages
{
[TestFixture, Parallelizable(ParallelScope.All)]
public class CSharpLanguageTests
{
const string ns = "ICSharpCode.Decompiler.Tests.TypeSystem";
static PEFile LoadAssembly(string filename)
{
return new PEFile(filename, new FileStream(filename, FileMode.Open, FileAccess.Read));
}
static readonly Lazy<PEFile> mscorlib = new Lazy<PEFile>(
delegate {
return LoadAssembly(typeof(object).Assembly.Location);
});
static readonly Lazy<PEFile> systemCore = new Lazy<PEFile>(
delegate {
return LoadAssembly(typeof(System.Linq.Enumerable).Assembly.Location);
});
static readonly Lazy<PEFile> testAssembly = new Lazy<PEFile>(
delegate {
return LoadAssembly(typeof(CSharpLanguageTests).Assembly.Location);
});
public static PEFile Mscorlib { get { return mscorlib.Value; } }
public static PEFile SystemCore { get { return systemCore.Value; } }
public static PEFile TestAssembly { get { return testAssembly.Value; } }
[OneTimeSetUp]
public void FixtureSetUp()
{
compilation = new SimpleCompilation(TestAssembly,
Mscorlib.WithOptions(TypeSystemOptions.Default));
language = new CSharpLanguage();
}
ICompilation compilation;
CSharpLanguage language;
ITypeDefinition GetTypeDefinition(Type type)
{
return compilation.FindType(type).GetDefinition();
}
void TestType(Type t, string ns, string name)
{
var type = GetTypeDefinition(t);
Assert.AreEqual(name, language.TypeToString(type, includeNamespace: false));
Assert.AreEqual(ns + "." + name, language.TypeToString(type, includeNamespace: true));
}
void TestMethod(Type t, Predicate<IMember> filter, string ns, string typeName, string name, string paramListReturnType, string longParamListReturnType = null)
{
var type = GetTypeDefinition(t);
var method = type.GetMembers(filter, GetMemberOptions.IgnoreInheritedMembers).Single() as IMethod;
if (method == null)
throw new ArgumentNullException();
if (longParamListReturnType == null)
longParamListReturnType = paramListReturnType;
Assert.AreEqual(name + paramListReturnType, language.MethodToString(method, includeDeclaringTypeName: false, includeNamespace: false, includeNamespaceOfDeclaringTypeName: false));
Assert.AreEqual(typeName + "." + name + paramListReturnType, language.MethodToString(method, includeDeclaringTypeName: true, includeNamespace: false, includeNamespaceOfDeclaringTypeName: false));
Assert.AreEqual(name + longParamListReturnType, language.MethodToString(method, includeDeclaringTypeName: false, includeNamespace: true, includeNamespaceOfDeclaringTypeName: false));
Assert.AreEqual(typeName + "." + name + longParamListReturnType, language.MethodToString(method, includeDeclaringTypeName: true, includeNamespace: true, includeNamespaceOfDeclaringTypeName: false));
Assert.AreEqual(name + paramListReturnType, language.MethodToString(method, includeDeclaringTypeName: false, includeNamespace: false, includeNamespaceOfDeclaringTypeName: true));
Assert.AreEqual(ns + "." + typeName + "." + name + paramListReturnType, language.MethodToString(method, includeDeclaringTypeName: true, includeNamespace: false, includeNamespaceOfDeclaringTypeName: true));
Assert.AreEqual(name + longParamListReturnType, language.MethodToString(method, includeDeclaringTypeName: false, includeNamespace: true, includeNamespaceOfDeclaringTypeName: true));
Assert.AreEqual(ns + "." + typeName + "." + name + longParamListReturnType, language.MethodToString(method, includeDeclaringTypeName: true, includeNamespace: true, includeNamespaceOfDeclaringTypeName: true));
}
[Test]
public void PrimitiveTypes()
{
TestType(typeof(object), "System", "Object");
TestType(typeof(string), "System", "String");
TestType(typeof(int), "System", "Int32");
}
[Test]
public void ClassTests()
{
TestType(typeof(SimplePublicClass), ns, "SimplePublicClass");
TestType(typeof(GenericClass<,>), ns, "GenericClass<A,B>");
TestType(typeof(OuterGeneric<>), ns, "OuterGeneric<X>");
TestType(typeof(OuterGeneric<>.Inner), ns + ".OuterGeneric<X>", "Inner");
}
[Test]
public void InterfaceTests()
{
TestType(typeof(IBase1), ns, "IBase1");
TestType(typeof(IGenericInterface<>), ns, "IGenericInterface<T>");
}
[Test]
public void EnumTests()
{
TestType(typeof(MyEnum), ns, "MyEnum");
TestType(typeof(GenericClass<,>.NestedEnum), ns + ".GenericClass<A,B>", "NestedEnum");
}
[Test]
public void DelegateTests()
{
TestType(typeof(GenericDelegate<,>), ns, "GenericDelegate<T,S>");
}
[Test]
public void MethodTests()
{
TestMethod(typeof(IMarshalAsTests), x => x.Name == "QueryApplicationFile", ns, "IMarshalAsTests", "QueryApplicationFile", "(string, out string, out string, out bool, out bool, out object[]) : void");
TestMethod(typeof(MyClassWithCtor), x => x is IMethod m && m.IsConstructor, ns, "MyClassWithCtor", "MyClassWithCtor", "(int)");
TestMethod(typeof(OuterGeneric<>), x => x is IMethod m && m.IsConstructor, ns, "OuterGeneric<X>", "OuterGeneric<X>", "()");
}
}
}

11
ILSpy.Tests/Stub.cs

@ -0,0 +1,11 @@
using System;
namespace ILSpy.Tests
{
class Stub
{
static void Main(string[] args)
{
}
}
}

8
ILSpy.sln

@ -31,7 +31,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Rebracer.xml = Rebracer.xml Rebracer.xml = Rebracer.xml
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Decompiler.PdbProvider.Cecil", "ICSharpCode.Decompiler.PdbProvider.Cecil\ICSharpCode.Decompiler.PdbProvider.Cecil.csproj", "{B85A155A-9DD6-43BC-A624-2D8EC773D71F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.Decompiler.PdbProvider.Cecil", "ICSharpCode.Decompiler.PdbProvider.Cecil\ICSharpCode.Decompiler.PdbProvider.Cecil.csproj", "{B85A155A-9DD6-43BC-A624-2D8EC773D71F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy.Tests", "ILSpy.Tests\ILSpy.Tests.csproj", "{B51C6636-B8D1-4200-9869-08F2689DE6C2}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -75,6 +77,10 @@ Global
{B85A155A-9DD6-43BC-A624-2D8EC773D71F}.Debug|Any CPU.Build.0 = Debug|Any CPU {B85A155A-9DD6-43BC-A624-2D8EC773D71F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B85A155A-9DD6-43BC-A624-2D8EC773D71F}.Release|Any CPU.ActiveCfg = Release|Any CPU {B85A155A-9DD6-43BC-A624-2D8EC773D71F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B85A155A-9DD6-43BC-A624-2D8EC773D71F}.Release|Any CPU.Build.0 = Release|Any CPU {B85A155A-9DD6-43BC-A624-2D8EC773D71F}.Release|Any CPU.Build.0 = Release|Any CPU
{B51C6636-B8D1-4200-9869-08F2689DE6C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B51C6636-B8D1-4200-9869-08F2689DE6C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B51C6636-B8D1-4200-9869-08F2689DE6C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B51C6636-B8D1-4200-9869-08F2689DE6C2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

1
appveyor.yml

@ -19,6 +19,7 @@ after_build:
test: test:
assemblies: assemblies:
- 'ICSharpCode.Decompiler.Tests\bin\%configuration%\net46\ICSharpCode.Decompiler.Tests.exe' - 'ICSharpCode.Decompiler.Tests\bin\%configuration%\net46\ICSharpCode.Decompiler.Tests.exe'
- 'ILSpy.Tests\bin\%configuration%\net46\ILSpy.Tests.exe'
- 'ILSpy.BamlDecompiler.Tests\bin\%configuration%\net46\ILSpy.BamlDecompiler.Tests.dll' - 'ILSpy.BamlDecompiler.Tests\bin\%configuration%\net46\ILSpy.BamlDecompiler.Tests.dll'
after_test: after_test:
- python BuildTools\tidy.py - python BuildTools\tidy.py

Loading…
Cancel
Save