3 # Rules for building unit tests.
5 # Includers of this file must define the following values:
14 TEST_COMPILE = $(subst $(test_remove),,$(CSCOMPILE))
17 TEST_RUNTIME_WRAPPERS_PATH = $(shell dirname $(RUNTIME))/_tmpinst/bin
23 test_nunit_lib = nunitlite.dll
25 test_nunit_lib = nunit.framework.dll nunit.core.dll nunit.util.dll nunit.mocks.dll
28 TEST_LIB_MCS_FLAGS = $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/%.dll,$(TEST_LIB_REFS))
30 test_nunit_dep = $(test_nunit_lib:%=$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)%)
31 test_nunit_ref = $(test_nunit_dep:%=-r:%)
32 tests_CLEAN_FILES += TestResult*.xml
34 test_sourcefile = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll.sources)
36 ifeq ($(wildcard $(test_sourcefile)),)
37 test_sourcefile = $(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll.sources)
40 test_lib = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll)
41 test_sourcefile_excludes = $(test_lib).exclude.sources
43 test_pdb = $(test_lib:.dll=.pdb)
44 test_response = $(depsdir)/$(test_lib).response
45 test_makefrag = $(depsdir)/$(test_lib).makefrag
46 test_flags = -r:$(the_assembly) $(test_nunit_ref) $(TEST_MCS_FLAGS) $(TEST_LIB_MCS_FLAGS)
47 tests_CLEAN_FILES += $(ASSEMBLY:$(ASSEMBLY_EXT)=_test*.dll) $(ASSEMBLY:$(ASSEMBLY_EXT)=_test*.pdb) $(test_response) $(test_makefrag)
50 HAVE_CS_TESTS := $(wildcard $(test_sourcefile))
53 HAVE_SOURCE_EXCLUDES := $(wildcard $(test_sourcefile_excludes))
58 $(test_nunit_dep): $(topdir)/build/deps/nunit-$(PROFILE).stamp
59 @if test -f $@; then :; else rm -f $<; $(MAKE) $<; fi
62 $(topdir)/build/deps/nunit-$(PROFILE).stamp:
64 cd ${topdir}/tools/nunit-lite && $(MAKE)
68 $(topdir)/build/deps/nunit-$(PROFILE).stamp:
70 cd ${topdir}/nunit24 && $(MAKE)
75 tests_CLEAN_FILES += $(topdir)/build/deps/nunit-$(PROFILE).stamp
81 test_assemblies += $(test_lib)
86 test-local: $(test_assemblies)
87 run-test-local: run-test-lib
88 run-test-ondotnet-local: run-test-ondotnet-lib
90 TEST_HARNESS_EXCLUDES = -exclude=$(PLATFORM_TEST_HARNESS_EXCLUDES)$(PROFILE_TEST_HARNESS_EXCLUDES)NotWorking,ValueAdd,CAS,InetAccess
91 TEST_HARNESS_EXCLUDES_ONDOTNET = /exclude:$(PLATFORM_TEST_HARNESS_EXCLUDES)$(PROFILE_TEST_HARNESS_EXCLUDES)NotDotNet,CAS
95 NUNIT_XML_FLAG = -format:nunit2 -result:
98 OUTPUT_FILE_FLAG=-output
99 NOSHADOW_FLAG = -noshadow
100 NUNIT_XML_FLAG = -xml=
105 NUNIT_XML_FLAG = -format:nunit2 -result:
106 OUTPUT_FILE_FLAG=-out
108 OUTPUT_FILE_FLAG=-output
109 NOSHADOW_FLAG = -noshadow
110 NUNIT_XML_FLAG = -xml=
113 ifdef TEST_HARNESS_VERBOSE
114 TEST_HARNESS_OUTPUT = -labels
115 TEST_HARNESS_OUTPUT_ONDOTNET = -labels
116 TEST_HARNESS_POSTPROC = :
117 TEST_HARNESS_POSTPROC_ONDOTNET = :
119 TEST_HARNESS_OUTPUT = $(OUTPUT_FILE_FLAG)=TestResult-$(PROFILE).log
120 TEST_HARNESS_OUTPUT_ONDOTNET = $(OUTPUT_FILE_FLAG)=TestResult-ondotnet-$(PROFILE).log
121 TEST_HARNESS_POSTPROC = (echo ''; cat TestResult-$(PROFILE).log) | sed '1,/^Tests run: /d'; xsltproc $(topdir)/build/nunit-summary.xsl TestResult-$(PROFILE).xml >> TestResult-$(PROFILE).log
122 TEST_HARNESS_POSTPROC_ONDOTNET = (echo ''; cat TestResult-ondotnet-$(PROFILE).log) | sed '1,/^Tests run: /d'; xsltproc $(topdir)/build/nunit-summary.xsl TestResult-ondotnet-$(PROFILE).xml >> TestResult-ondotnet-$(PROFILE).log
127 FIXTURE_ARG = -test=MonoTests.$(FIXTURE)
129 FIXTURE_ARG = -fixture=MonoTests.$(FIXTURE)
135 TESTNAME_ARG = -test=MonoTests.$(TESTNAME)
137 TESTNAME_ARG = -run=MonoTests.$(TESTNAME)
142 test-local-aot-compile: $(topdir)/build/deps/nunit-$(PROFILE).stamp
143 PATH="$(TEST_RUNTIME_WRAPPERS_PATH):$(PATH)" MONO_REGISTRY_PATH="$(HOME)/.mono/registry" MONO_TESTS_IN_PROGRESS="yes" $(TEST_RUNTIME) $(RUNTIME_FLAGS) $(AOT_BUILD_FLAGS) $(test_assemblies)
146 test-local-aot-compile: $(topdir)/build/deps/nunit-$(PROFILE).stamp
150 ## FIXME: i18n problem in the 'sed' command below
151 run-test-lib: test-local test-local-aot-compile
153 PATH="$(TEST_RUNTIME_WRAPPERS_PATH):$(PATH)" MONO_REGISTRY_PATH="$(HOME)/.mono/registry" MONO_TESTS_IN_PROGRESS="yes" $(TEST_RUNTIME) $(RUNTIME_FLAGS) $(AOT_RUN_FLAGS) $(TEST_HARNESS) $(test_assemblies) $(NOSHADOW_FLAG) $(TEST_HARNESS_FLAGS) $(LOCAL_TEST_HARNESS_FLAGS) $(TEST_HARNESS_EXCLUDES) $(TEST_HARNESS_OUTPUT) $(NUNIT_XML_FLAG)TestResult-$(PROFILE).xml $(FIXTURE_ARG) $(TESTNAME_ARG)|| ok=false; \
154 if [ ! -f "TestResult-$(PROFILE).xml" ]; then echo "<?xml version='1.0' encoding='utf-8'?><test-results failures='1' total='1' not-run='0' name='bcl-tests' date='$$(date +%F)' time='$$(date +%T)'><test-suite name='$(strip $(test_assemblies))' success='False' time='0'><results><test-case name='crash' executed='True' success='False' time='0'><failure><message>The test runner didn't produce a test result XML, probably due to a crash of the runtime. Check the log for more details.</message><stack-trace></stack-trace></failure></test-case></results></test-suite></test-results>" > TestResult-$(PROFILE).xml; fi; \
155 $(TEST_HARNESS_POSTPROC) ; $$ok
157 ## Instructs compiler to compile to target .net execution, it can be usefull in rare cases when runtime detection is not possible
158 run-test-ondotnet-lib: LOCAL_TEST_COMPILER_ONDOTNET_FLAGS:=-d:RUN_ONDOTNET
159 run-test-ondotnet-lib: test-local
161 $(TEST_HARNESS) $(test_assemblies) $(NOSHADOW_FLAG) $(TEST_HARNESS_FLAGS) $(LOCAL_TEST_HARNESS_ONDOTNET_FLAGS) $(TEST_HARNESS_EXCLUDES_ONDOTNET) $(TEST_HARNESS_OUTPUT_ONDOTNET) $(NUNIT_XML_FLAG)=TestResult-ondotnet-$(PROFILE).xml $(FIXTURE_ARG) $(TESTNAME_ARG) || ok=false; \
162 $(TEST_HARNESS_POSTPROC_ONDOTNET) ; $$ok
165 endif # test_assemblies
170 TEST_FILES += `sed -e '/^$$/d' -e 's,^../,,' -et -e 's,^,Test/,' $(test_sourcefile)`
175 $(test_lib): $(the_assembly) $(test_response) $(test_nunit_dep)
176 $(TEST_COMPILE) $(LIBRARY_FLAGS) -target:library -out:$@ $(test_flags) $(LOCAL_TEST_COMPILER_ONDOTNET_FLAGS) @$(test_response)
178 test_response_preprocessed = $(test_response)_preprocessed
180 # This handles .excludes/.sources pairs, as well as resolving the
181 # includes that occur in .sources files
182 $(test_response_preprocessed): $(test_sourcefile)
183 $(SHELL) $(topdir)/build/gensources.sh $@ '$(test_sourcefile)' '$(test_sourcefile_excludes)'
185 $(test_response): $(test_response_preprocessed)
186 # @echo Creating $@ ...
187 @sed -e '/^$$/d' -e 's,^,Test/,' $(test_response_preprocessed) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
189 $(test_makefrag): $(test_response)
190 # @echo Creating $@ ...
191 @sed 's,^,$(test_lib): ,' $< >$@
193 -include $(test_makefrag)