Permalink
Browse files

Test projects now compile for all framework types

  • Loading branch information...
1 parent 1ebb18e commit 9194ce9a4b29fd91afaad04379b3b2ad7145dbea @mgravell mgravell committed Nov 14, 2015
View
@@ -7,4 +7,5 @@ obj/
*.suo
*.bak
*TestResults*
-project.lock.json
+project.lock.json
+.vs/
View
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <packageSources>
+ <clear />
+ <add key="CoreCLR" value="https://www.myget.org/F/dotnet-coreclr/api/v3/index.json" />
+ <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
+ </packageSources>
+</configuration>
View
@@ -7,8 +7,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SigilTests", "SigilTests\Si
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8B252003-1909-4EA3-8BD9-2D20341F9143}"
ProjectSection(SolutionItems) = preProject
- Sigil\global.json = Sigil\global.json
+ global.json = global.json
LICENSE.txt = LICENSE.txt
+ NuGet.Config = NuGet.Config
README.markdown = README.markdown
EndProjectSection
EndProject
@@ -26,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sigil NET45", "Sigil NET45\
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Sigil", "Sigil\Sigil.xproj", "{3F959AB7-A1C2-41DA-A1F3-981EA89A0067}"
EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SigilTests.DNX", "SigilTests.DNX\SigilTests.DNX.xproj", "{AC7E3C9D-9B25-4DA8-9D1D-FD7EE39A6A9E}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -64,6 +67,10 @@ Global
{3F959AB7-A1C2-41DA-A1F3-981EA89A0067}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F959AB7-A1C2-41DA-A1F3-981EA89A0067}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F959AB7-A1C2-41DA-A1F3-981EA89A0067}.Release|Any CPU.Build.0 = Release|Any CPU
+ {AC7E3C9D-9B25-4DA8-9D1D-FD7EE39A6A9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AC7E3C9D-9B25-4DA8-9D1D-FD7EE39A6A9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AC7E3C9D-9B25-4DA8-9D1D-FD7EE39A6A9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AC7E3C9D-9B25-4DA8-9D1D-FD7EE39A6A9E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
@@ -43,9 +43,15 @@ public static MethodInfo GetMethod(Type type, string name, Type[] parameterTypes
if (method.Name != name) continue;
var args = method.GetParameters();
if (args.Length != parameterTypes.Length) continue;
+ bool match = true;
for (int i = 0; i < args.Length; i++)
- if (args[i].ParameterType != parameterTypes[i]) continue;
- return method;
+ {
+ if (args[i].ParameterType != parameterTypes[i]) {
+ match = false;
+ break;
+ }
+ }
+ if(match) return method;
}
return null;
}
@@ -0,0 +1,10 @@
+namespace SigilTests.DNX
+{
+ public class Program
+ {
+ public void Main()
+ {
+ System.Console.WriteLine("please use: dnx test");
+ }
+ }
+}
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+
+ <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>ac7e3c9d-9b25-4da8-9d1d-fd7ee39a6a9e</ProjectGuid>
+ <RootNamespace>SigilTests.DNX</RootNamespace>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project>
@@ -0,0 +1,128 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Threading.Tasks;
+
+namespace SigilTests
+{
+ public static class TypeHelpers
+ {
+ public static MethodInfo GetMethod(this Type type, string name)
+ {
+ return type.GetTypeInfo().GetDeclaredMethod(name);
+ }
+ public static MethodInfo GetMethod(this Type type, string name, Type[] parameterTypes)
+ {
+ if (parameterTypes == null) parameterTypes = Type.EmptyTypes;
+ foreach(var method in type.GetTypeInfo().GetDeclaredMethods(name))
+ {
+ var args = method.GetParameters();
+ if (IsMatch(args, parameterTypes)) return method;
+ }
+ return null;
+ }
+ static bool IsMatch(ParameterInfo[] declared, Type[] expected)
+ {
+ if (expected == null) expected = Type.EmptyTypes;
+ if (declared.Length != expected.Length) return false;
+ for (int i = 0; i < expected.Length; i++)
+ {
+ if (declared[i].ParameterType != expected[i]) return false;
+ }
+ return true;
+ }
+ public static Type MakeGenericType(this Type type, params System.Reflection.Emit.TypeBuilder[] args)
+ {
+ Type[] t = new Type[args.Length];
+ for (int i = 0; i < args.Length; i++)
+ t[i] = args[i].AsType();
+ return type.MakeGenericType(t);
+ }
+ public static ConstructorInfo GetConstructor(this Type type, params Type[] parameterTypes)
+ {
+ if (parameterTypes == null) parameterTypes = Type.EmptyTypes;
+ foreach(var ctor in type.GetTypeInfo().DeclaredConstructors)
+ {
+ var args = ctor.GetParameters();
+ if (IsMatch(args, parameterTypes)) return ctor;
+ }
+ return null;
+ }
+ public static Type CreateType(this System.Reflection.Emit.TypeBuilder type)
+ {
+ return type.AsType();
+ }
+ public static FieldInfo GetField(this Type type, string name)
+ {
+ return type.GetTypeInfo().GetDeclaredField(name);
+ }
+ public static PropertyInfo GetProperty(this Type type, string name)
+ {
+ return type.GetTypeInfo().GetDeclaredProperty(name);
+ }
+ public static MethodInfo GetGetMethod(this PropertyInfo property)
+ {
+ return property.GetMethod;
+ }
+ }
+ public static class Assert
+ {
+ public static void AreEqual<T>(T x, T y)
+ {
+ Xunit.Assert.Equal<T>(x, y);
+ }
+ public static void AreEqual<T>(IEnumerable<T> x, IEnumerable<T> y)
+ {
+ Xunit.Assert.Equal<T>(x, y);
+ }
+ public static void AreNotEqual<T>(T x, T y)
+ {
+ Xunit.Assert.NotEqual<T>(x, y);
+ }
+ public static void AreNotEqual<T>(IEnumerable<T> x, IEnumerable<T> y)
+ {
+ Xunit.Assert.NotEqual<T>(x, y);
+ }
+ public static void IsFalse(bool value)
+ {
+ Xunit.Assert.False(value);
+ }
+ public static void IsTrue(bool value)
+ {
+ Xunit.Assert.True(value);
+ }
+ public static void Fail()
+ {
+ Xunit.Assert.Equal("pass", "fail");
+ }
+ public static void Fail(string message)
+ {
+ string expected = "pass";
+ if (expected == message) expected = "passed"; // unlikely, but!
+ Xunit.Assert.Equal(expected, message);
+ }
+ public static void IsNull(object @object)
+ {
+ Xunit.Assert.Null(@object);
+ }
+ public static void IsNotNull(object @object)
+ {
+ Xunit.Assert.NotNull(@object);
+ }
+ public static void IsInstanceOfType(object @object, Type type)
+ {
+ Xunit.Assert.IsType(type, @object);
+ }
+ }
+}
+namespace Microsoft.VisualStudio.TestTools.UnitTesting
+{
+ class TestClassAttribute : Attribute { }
+ class TestMethodAttribute : Xunit.FactAttribute { }
+}
+
+namespace System.Diagnostics.CodeAnalysis
+{
+ class ExcludeFromCodeCoverageAttribute : Attribute { }
+}
@@ -0,0 +1,32 @@
+{
+ "version": "1.0.0-*",
+ "description": "SigilTests Console Application",
+ "authors": [ "Kevin Montrose" ],
+ "tags": [ "" ],
+ "projectUrl": "",
+ "licenseUrl": "",
+ "compile": [
+ "**/*.cs",
+ "../SigilTests/**/*.cs"
+ ],
+ "dependencies": {
+ "Sigil": { "target": "project" }
+ },
+ "compilationOptions": { "allowUnsafe": true },
+ "commands": {
+ "test": "xunit.runner.dnx"
+ },
+
+ "frameworks": {
+ "dnxcore50": {
+ "compilationOptions": { "define": [ "COREFX", "COREFXTODO" ] },
+ "dependencies": {
+ "Microsoft.CSharp": "4.0.1-beta-23225",
+ "System.Collections": "4.0.11-beta-23409",
+ "System.Console": "4.0.0-beta-23225",
+ "xunit": "2.1.0",
+ "xunit.runner.dnx": "2.1.0-beta6-build191"
+ }
+ }
+ }
+}
View
@@ -25,8 +25,7 @@ public ClassWithCtor(string value)
[TestMethod]
public void CallBaseConstructor()
{
- AssemblyBuilder assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("SigilTests_CallBaseConstructor"),
- AssemblyBuilderAccess.RunAndCollect);
+ AssemblyBuilder assembly = Errors.DefineDynamicAssembly();
ModuleBuilder module = assembly.DefineDynamicModule("RuntimeModule");
@@ -52,8 +51,7 @@ public void CallBaseConstructor()
[TestMethod]
public void CallBaseConstructorNonGeneric()
{
- AssemblyBuilder assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("SigilTests_CallBaseConstructorNonGeneric"),
- AssemblyBuilderAccess.RunAndCollect);
+ AssemblyBuilder assembly = Errors.DefineDynamicAssembly();
ModuleBuilder module = assembly.DefineDynamicModule("RuntimeModule");
@@ -1,4 +1,5 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+#if !COREFXTODO
+using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Reflection.Emit;
using System.Linq;
@@ -567,3 +568,4 @@ public void SingleFloat()
#endif
}
}
+#endif
View
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
+using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
@@ -29,11 +30,7 @@ class _CallNonBaseClassConstructor2 : _CallNonBaseClassConstructor1
[TestMethod]
public void CallNonBaseClassConstructor()
{
- var assembly =
- AppDomain.CurrentDomain.DefineDynamicAssembly(
- new AssemblyName("SigilTests_CallNonBaseClassConstructor"),
- System.Reflection.Emit.AssemblyBuilderAccess.RunAndCollect
- );
+ var assembly = DefineDynamicAssembly();
var module = assembly.DefineDynamicModule("RuntimeModule");
var type = module.DefineType("_CallNonBaseClassConstructor3", TypeAttributes.Class, typeof(_CallNonBaseClassConstructor2));
@@ -56,15 +53,25 @@ public void CallNonBaseClassConstructor()
}
}
- [TestMethod]
- public void CallNonBaseClassConstructorNonGeneric()
+ internal static System.Reflection.Emit.AssemblyBuilder DefineDynamicAssembly([CallerMemberName]string name=null)
{
- var assembly =
- AppDomain.CurrentDomain.DefineDynamicAssembly(
- new AssemblyName("SigilTests_CallNonBaseClassConstructorNonGeneric"),
+#if COREFX
+ return System.Reflection.Emit.AssemblyBuilder.DefineDynamicAssembly(
+ new AssemblyName(name),
System.Reflection.Emit.AssemblyBuilderAccess.RunAndCollect
);
+#else
+ return AppDomain.CurrentDomain.DefineDynamicAssembly(
+ new AssemblyName(name),
+ System.Reflection.Emit.AssemblyBuilderAccess.RunAndCollect
+ );
+#endif
+ }
+ [TestMethod]
+ public void CallNonBaseClassConstructorNonGeneric()
+ {
+ var assembly = DefineDynamicAssembly();
var module = assembly.DefineDynamicModule("RuntimeModule");
var type = module.DefineType("_CallNonBaseClassConstructor3", TypeAttributes.Class, typeof(_CallNonBaseClassConstructor2));
@@ -109,7 +116,7 @@ public void CallContructorFromNonConstructor()
Assert.AreEqual("Constructors may only be called directly from within a constructor, use NewObject to allocate a new object with a specific constructor.", e.Message);
}
}
-
+#if !COREFXTODO
[TestMethod]
public void DisassemblingClosure()
{
@@ -129,7 +136,7 @@ public void DisassemblingClosure()
Assert.AreEqual("Cannot emit this DisassembledOperations object, check CanEmit before calling any Emit methods", e.Message);
}
}
-
+#endif
[TestMethod]
public void BadNonTerminalReturn()
{
@@ -4128,6 +4135,7 @@ public void BranchEmptyStack()
}
}
+#if !COREFXTODO
[TestMethod]
public void CatchInCatch()
{
@@ -4145,7 +4153,7 @@ public void CatchInCatch()
Assert.IsTrue(s.Message.StartsWith("Cannot start a new catch block, "));
}
}
-
+#endif
[TestMethod]
public void NullTryCatch()
{
Oops, something went wrong.

0 comments on commit 9194ce9

Please sign in to comment.