Add support for xunit tests
authorMarek Safar <marek.safar@gmail.com>
Sat, 11 Mar 2017 13:37:01 +0000 (14:37 +0100)
committerMarek Safar <marek.safar@gmail.com>
Fri, 17 Mar 2017 15:01:44 +0000 (16:01 +0100)
.gitmodules
external/xunit-binaries [new submodule]
mcs/build/library.make
mcs/build/tests.make
mcs/class/System.Numerics/Makefile
mcs/class/System.Numerics/System.Numerics_xtest.dll.sources [new file with mode: 0644]
mcs/class/Xunit.NetCore.Extensions/Makefile [new file with mode: 0644]
mcs/class/Xunit.NetCore.Extensions/Microsoft.Xunit.Performance/BenchmarkAttribute.cs [new file with mode: 0644]
mcs/class/Xunit.NetCore.Extensions/Microsoft.Xunit.Performance/BenchmarkDiscover.cs [new file with mode: 0644]
mcs/class/Xunit.NetCore.Extensions/Xunit.NetCore.Extensions.dll.sources [new file with mode: 0644]

index 0ecdafacf2dc89703756c3625c200905f9651cda..942bec22d076328a62a6b76d54437b0c94fb2910 100644 (file)
@@ -55,3 +55,6 @@
 [submodule "external/corert"]
        path = external/corert
        url = git://github.com/mono/corert.git
+[submodule "external/xunit-binaries"]
+       path = external/xunit-binaries
+       url = git://github.com/mono/xunit-binaries.git
diff --git a/external/xunit-binaries b/external/xunit-binaries
new file mode 160000 (submodule)
index 0000000..b8e20d2
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit b8e20d265b368dd6252703d5afd038d0b028e388
index 3ad567a86e05a398f11f26c8fba22cfb0fe3038b..fdb9cdba4d5b305042270b73d87b7f693d4be026 100644 (file)
@@ -266,7 +266,7 @@ endif
 # make dist will collect files in .sources files from all profiles
 dist-local: dist-default
        subs=' ' ; \
-       for f in `$(topdir)/tools/removecomments.sh $(filter-out $(wildcard *_test.dll.sources) $(wildcard *exclude.sources),$(wildcard *.sources))` $(TEST_FILES) ; do \
+       for f in `$(topdir)/tools/removecomments.sh $(filter-out $(wildcard *_test.dll.sources) $(wildcard *_xtest.dll.sources) $(wildcard *exclude.sources),$(wildcard *.sources))` $(TEST_FILES) ; do \
          case $$f in \
          ../*) : ;; \
          *.g.cs) : ;; \
index d9f6a95ff72b5d1653e3a0f809d994029c3ee5cf..cb68f8abddafdeedfebae274606cb1a727e51f0a 100644 (file)
@@ -20,8 +20,18 @@ TEST_RUNTIME_WRAPPERS_PATH = $(shell dirname $(RUNTIME))/_tmpinst/bin
 ifndef NO_TEST
 
 test_nunit_lib = nunitlite.dll
+xunit_core := xunit.core xunit.abstractions xunit.assert
+xunit_deps := System.Runtime
+xunit_class_deps := Xunit.NetCore.Extensions
+
+xunit_libs_ref = $(patsubst %,-r:$(topdir)/../external/xunit-binaries/%.dll,$(xunit_core))
+xunit_libs_ref += $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/Facades/%.dll,$(xunit_deps))
+
+xunit_libs_dep = $(xunit_class_deps:%=$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)%.dll)
+xunit_libs_ref += $(xunit_libs_dep:%=-r:%)
 
 TEST_LIB_MCS_FLAGS = $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/%.dll,$(TEST_LIB_REFS))
+XTEST_LIB_MCS_FLAGS = $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/%.dll,$(XTEST_LIB_REFS))
 
 test_nunit_dep = $(test_nunit_lib:%=$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)%)
 test_nunit_ref = $(test_nunit_dep:%=-r:%)
@@ -34,6 +44,7 @@ test_sourcefile = $(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll.sources)
 endif
 
 test_lib = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll)
+
 test_sourcefile_excludes = $(test_lib).exclude.sources
 
 test_pdb = $(test_lib:.dll=.pdb)
@@ -42,12 +53,26 @@ test_makefrag = $(depsdir)/$(test_lib).makefrag
 test_flags = -r:$(the_assembly) $(test_nunit_ref) $(TEST_MCS_FLAGS) $(TEST_LIB_MCS_FLAGS)
 tests_CLEAN_FILES += $(ASSEMBLY:$(ASSEMBLY_EXT)=_test*.dll) $(ASSEMBLY:$(ASSEMBLY_EXT)=_test*.pdb) $(test_response) $(test_makefrag)
 
+xtest_sourcefile = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_xtest.dll.sources)
+
+ifeq ($(wildcard $(xtest_sourcefile)),)
+xtest_sourcefile = $(ASSEMBLY:$(ASSEMBLY_EXT)=_xtest.dll.sources)
+endif
+
+xunit_test_lib = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_xunit-test.dll)
+
+xtest_response = $(depsdir)/$(xtest_lib).response
+xtest_makefrag = $(depsdir)/$(xtest_lib).makefrag
+xtest_flags = -r:$(the_assembly) $(xunit_libs_ref) $(XTEST_MCS_FLAGS) $(XTEST_LIB_MCS_FLAGS)
+
 ifndef HAVE_CS_TESTS
 HAVE_CS_TESTS := $(wildcard $(test_sourcefile))
 endif
 
 HAVE_SOURCE_EXCLUDES := $(wildcard $(test_sourcefile_excludes))
 
+HAVE_CS_XTESTS := $(wildcard $(xtest_sourcefile))
+
 endif # !NO_TEST
 
 ifndef NO_TEST
@@ -61,6 +86,10 @@ endif
        echo "stamp" >$@
 
 tests_CLEAN_FILES += $(topdir)/build/deps/nunit-$(PROFILE).stamp
+
+$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)Xunit.NetCore.Extensions.dll:
+       $(MAKE) -C $(topdir)/class/Xunit.NetCore.Extensions
+
 endif
 
 test_assemblies :=
@@ -159,4 +188,52 @@ $(test_makefrag): $(test_response)
 
 endif
 
+
+ifdef HAVE_CS_XTESTS
+
+XTEST_HARNESS_PATH = $(topdir)/../external/xunit-binaries
+XTEST_HARNESS = $(XTEST_HARNESS_PATH)/xunit.console.exe
+XTEST_HARNESS_FLAGS := -noappdomain -noshadow -parallel none -nunit TestResult-$(PROFILE)-xunit.xml
+XTEST_TRAIT := -notrait category=failing -notrait category=nonnetcoreapptests -notrait Benchmark=true -notrait category=outerloop
+
+ifdef FIXTURE
+XTEST_HARNESS_FLAGS += -class $(FIXTURE)
+endif
+
+ifdef TESTNAME
+XTEST_HARNESS_FLAGS += -method $(TESTNAME)
+endif
+
+check: run-xunit-test-local
+run-xunit-test: run-xunit-test-local
+xunit-test-local: $(xunit_test_lib)
+run-xunit-test-local: run-xunit-test-lib
+
+# ln -s is a HACK for xunit runner to require xunit.execution.desktop.dll file in local folder on .net only
+run-xunit-test-lib: xunit-test-local
+       @ln -fs $(XTEST_HARNESS_PATH)/xunit.execution.desktop.dll xunit.execution.desktop.dll
+       ok=:; \
+       PATH="$(TEST_RUNTIME_WRAPPERS_PATH):$(PATH)" $(TEST_RUNTIME) $(RUNTIME_FLAGS) $(AOT_RUN_FLAGS) $(XTEST_HARNESS) $(xunit_test_lib) $(XTEST_HARNESS_FLAGS) $(XTEST_TRAIT) || ok=false; \
+       $$ok
+       @rm -f xunit.execution.desktop.dll
+
+$(xunit_test_lib): $(the_assembly) $(xtest_response) $(xunit_libs_dep)
+       $(TEST_COMPILE) $(LIBRARY_FLAGS) $(XTEST_LIB_FLAGS) -target:library -out:$@ $(xtest_flags) @$(xtest_response)
+
+xtest_response_preprocessed = $(xtest_response)_preprocessed
+
+# This handles .excludes/.sources pairs, as well as resolving the
+# includes that occur in .sources files
+$(xtest_response): $(xtest_sourcefile)
+       $(SHELL) $(topdir)/build/gensources.sh $@ '$(xtest_sourcefile)' '$(xtest_sourcefile_excludes)'
+
+$(xtest_makefrag): $(xtest_response)
+       @echo Creating $@ ...
+       @sed 's,^,$(xunit_test_lib): ,' $< >$@
+
+-include $(xtest_makefrag)
+
+endif
+
+
 .PHONY: patch-nunitlite-appconfig
index 19d1e56a543b4ee70e00fe383e04279dc8dd0da3..f13e64122ace5db53316040604935379b3f4c7c7 100644 (file)
@@ -6,6 +6,8 @@ LIBRARY = System.Numerics.dll
 LIB_REFS = System
 LIB_MCS_FLAGS = /unsafe
 TEST_MCS_FLAGS = $(LIB_MCS_FLAGS)
+XTEST_LIB_REFS = System Facades/System.Threading.Tasks System.Runtime.InteropServices.RuntimeInformation System.Core System.Numerics.Vectors Microsoft.CSharp
+XTEST_LIB_FLAGS = -unsafe
 
 RESX_RESOURCE_STRING = \
        ../../../external/corefx/src/System.Runtime.Numerics/src/Resources/Strings.resx \
diff --git a/mcs/class/System.Numerics/System.Numerics_xtest.dll.sources b/mcs/class/System.Numerics/System.Numerics_xtest.dll.sources
new file mode 100644 (file)
index 0000000..a012a0c
--- /dev/null
@@ -0,0 +1,8 @@
+../../../external/corefx/src/Common/tests/System/PlatformDetection.cs
+
+# ../../../external/corefx/src/System.Runtime.Numerics/tests/*.cs
+../../../external/corefx/src/System.Runtime.Numerics/tests/BigInteger/*.cs
+
+../../../external/corefx/src/System.Numerics.Vectors/src/System/Numerics/ConstantHelper.cs
+
+../../../external/corefx/src/System.Numerics.Vectors/tests/*.cs
diff --git a/mcs/class/Xunit.NetCore.Extensions/Makefile b/mcs/class/Xunit.NetCore.Extensions/Makefile
new file mode 100644 (file)
index 0000000..5be627d
--- /dev/null
@@ -0,0 +1,17 @@
+thisdir = class/Xunit.NetCore.Extensions
+SUBDIRS = 
+include ../../build/rules.make
+
+XUNIT_LIBS := xunit.core xunit.abstractions xunit.execution.desktop xunit.assert
+
+LIBRARY = Xunit.NetCore.Extensions.dll
+LIB_REFS = System System.Core System.Runtime.InteropServices.RuntimeInformation Facades/System.Runtime Facades/System.Threading.Tasks
+LIB_MCS_FLAGS = $(patsubst %,-r:$(topdir)/../external/xunit-binaries/%.dll,$(XUNIT_LIBS))
+
+EXTRA_DISTFILES =
+
+NO_TEST = yes
+NO_INSTALL = yes
+NO_SIGN_ASSEMBLY = yes
+
+include ../../build/library.make
diff --git a/mcs/class/Xunit.NetCore.Extensions/Microsoft.Xunit.Performance/BenchmarkAttribute.cs b/mcs/class/Xunit.NetCore.Extensions/Microsoft.Xunit.Performance/BenchmarkAttribute.cs
new file mode 100644 (file)
index 0000000..5697d10
--- /dev/null
@@ -0,0 +1,13 @@
+using System;
+using Xunit;
+using Xunit.Sdk;
+
+namespace Microsoft.Xunit.Performance
+{
+       [TraitDiscoverer("Microsoft.Xunit.Performance.BenchmarkDiscoverer", "Xunit.NetCore.Extensions")]
+       [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
+       public class BenchmarkAttribute : Attribute, ITraitAttribute
+       {
+               public long InnerIterationCount { get; set; }
+       }
+}
diff --git a/mcs/class/Xunit.NetCore.Extensions/Microsoft.Xunit.Performance/BenchmarkDiscover.cs b/mcs/class/Xunit.NetCore.Extensions/Microsoft.Xunit.Performance/BenchmarkDiscover.cs
new file mode 100644 (file)
index 0000000..40d2d8a
--- /dev/null
@@ -0,0 +1,14 @@
+using System.Collections.Generic;
+using Xunit.Sdk;
+using Xunit.Abstractions;
+
+namespace Xunit.NetCore.Extensions
+{
+    public class BenchmarkDiscoverer : ITraitDiscoverer
+    {
+        public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
+        {
+            yield return new KeyValuePair<string, string>("Benchmark", "True");
+        }
+    }
+}
diff --git a/mcs/class/Xunit.NetCore.Extensions/Xunit.NetCore.Extensions.dll.sources b/mcs/class/Xunit.NetCore.Extensions/Xunit.NetCore.Extensions.dll.sources
new file mode 100644 (file)
index 0000000..145dae4
--- /dev/null
@@ -0,0 +1,6 @@
+../../../external/buildtools/src/xunit.netcore.extensions/*.cs
+../../../external/buildtools/src/xunit.netcore.extensions/Attributes/*.cs
+../../../external/buildtools/src/xunit.netcore.extensions/Discoverers/*.cs
+
+Microsoft.Xunit.Performance/BenchmarkAttribute.cs
+Microsoft.Xunit.Performance/BenchmarkDiscover.cs