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
22 test_nunit_lib = nunitlite.dll
24 TEST_LIB_MCS_FLAGS = $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/%.dll,$(TEST_LIB_REFS))
26 test_nunit_dep = $(test_nunit_lib:%=$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)%)
27 test_nunit_ref = $(test_nunit_dep:%=-r:%)
28 tests_CLEAN_FILES += TestResult*.xml
30 test_sourcefile = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll.sources)
32 ifeq ($(wildcard $(test_sourcefile)),)
33 test_sourcefile = $(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll.sources)
36 test_lib = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll)
37 test_sourcefile_excludes = $(test_lib).exclude.sources
39 test_pdb = $(test_lib:.dll=.pdb)
40 test_response = $(depsdir)/$(test_lib).response
41 test_makefrag = $(depsdir)/$(test_lib).makefrag
42 test_flags = -r:$(the_assembly) $(test_nunit_ref) $(TEST_MCS_FLAGS) $(TEST_LIB_MCS_FLAGS)
43 tests_CLEAN_FILES += $(ASSEMBLY:$(ASSEMBLY_EXT)=_test*.dll) $(ASSEMBLY:$(ASSEMBLY_EXT)=_test*.pdb) $(test_response) $(test_makefrag)
46 HAVE_CS_TESTS := $(wildcard $(test_sourcefile))
49 HAVE_SOURCE_EXCLUDES := $(wildcard $(test_sourcefile_excludes))
54 $(test_nunit_dep): $(topdir)/build/deps/nunit-$(PROFILE).stamp
55 @if test -f $@; then :; else rm -f $<; $(MAKE) $<; fi
57 $(topdir)/build/deps/nunit-$(PROFILE).stamp:
59 cd ${topdir}/tools/nunit-lite && $(MAKE)
63 tests_CLEAN_FILES += $(topdir)/build/deps/nunit-$(PROFILE).stamp
69 test_assemblies += $(test_lib)
74 test-local: $(test_assemblies)
75 run-test-local: run-test-lib
76 run-test-ondotnet-local: run-test-ondotnet-lib
78 TEST_HARNESS_EXCLUDES = -exclude=$(PLATFORM_TEST_HARNESS_EXCLUDES)$(PROFILE_TEST_HARNESS_EXCLUDES)NotWorking,ValueAdd,CAS,InetAccess
79 TEST_HARNESS_EXCLUDES_ONDOTNET = /exclude:$(PLATFORM_TEST_HARNESS_EXCLUDES)$(PROFILE_TEST_HARNESS_EXCLUDES)NotDotNet,CAS
84 FIXTURE_ARG = -test=MonoTests.$(FIXTURE)
88 TESTNAME_ARG = -test=MonoTests.$(TESTNAME)
91 ifdef TEST_HARNESS_VERBOSE
96 test-local-aot-compile: $(topdir)/build/deps/nunit-$(PROFILE).stamp
97 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)
100 test-local-aot-compile: $(topdir)/build/deps/nunit-$(PROFILE).stamp
104 NUNITLITE_CONFIG_FILE=$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)nunit-lite-console.exe.config
106 patch-nunitlite-appconfig:
107 cp -f $(topdir)/tools/nunit-lite/nunit-lite-console/nunit-lite-console.exe.config.tmpl $(NUNITLITE_CONFIG_FILE)
108 ifdef TEST_NUNITLITE_APP_CONFIG_GLOBAL
109 sed -i -e "/__INSERT_CUSTOM_APP_CONFIG_GLOBAL__/r $(TEST_NUNITLITE_APP_CONFIG_GLOBAL)" $(NUNITLITE_CONFIG_FILE)
111 ifdef TEST_NUNITLITE_APP_CONFIG_RUNTIME
112 sed -i -e "/__INSERT_CUSTOM_APP_CONFIG_RUNTIME__/r $(TEST_NUNITLITE_APP_CONFIG_RUNTIME)" $(NUNITLITE_CONFIG_FILE)
115 ## FIXME: i18n problem in the 'sed' command below
116 run-test-lib: test-local test-local-aot-compile patch-nunitlite-appconfig
118 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) $(LABELS_ARG) -format:nunit2 -result:TestResult-$(PROFILE).xml $(FIXTURE_ARG) $(TESTNAME_ARG)|| ok=false; \
119 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; \
122 ## Instructs compiler to compile to target .net execution, it can be usefull in rare cases when runtime detection is not possible
123 run-test-ondotnet-lib: LOCAL_TEST_COMPILER_ONDOTNET_FLAGS:=-d:RUN_ONDOTNET
124 run-test-ondotnet-lib: test-local
126 $(TEST_HARNESS) $(test_assemblies) $(NOSHADOW_FLAG) $(TEST_HARNESS_FLAGS) $(LOCAL_TEST_HARNESS_ONDOTNET_FLAGS) $(TEST_HARNESS_EXCLUDES_ONDOTNET) $(LABELS_ARG) -format:nunit2 -result:TestResult-ondotnet-$(PROFILE).xml $(FIXTURE_ARG) $(TESTNAME_ARG) || ok=false; \
130 endif # test_assemblies
135 TEST_FILES += `sed -e '/^$$/d' -e 's,^../,,' -et -e 's,^,Test/,' $(test_sourcefile)`
140 $(test_lib): $(the_assembly) $(test_response) $(test_nunit_dep)
141 $(TEST_COMPILE) $(LIBRARY_FLAGS) -target:library -out:$@ $(test_flags) $(LOCAL_TEST_COMPILER_ONDOTNET_FLAGS) @$(test_response)
143 test_response_preprocessed = $(test_response)_preprocessed
145 # This handles .excludes/.sources pairs, as well as resolving the
146 # includes that occur in .sources files
147 $(test_response_preprocessed): $(test_sourcefile)
148 $(SHELL) $(topdir)/build/gensources.sh $@ '$(test_sourcefile)' '$(test_sourcefile_excludes)'
150 $(test_response): $(test_response_preprocessed)
151 # @echo Creating $@ ...
152 @sed -e '/^$$/d' -e 's,^,Test/,' $(test_response_preprocessed) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
154 $(test_makefrag): $(test_response)
155 # @echo Creating $@ ...
156 @sed 's,^,$(test_lib): ,' $< >$@
158 -include $(test_makefrag)
162 .PHONY: patch-nunitlite-appconfig