[bcl] Add patching of nunit-lite-console.exe.config file
[mono.git] / mcs / build / tests.make
1 # -*- makefile -*-
2 #
3 # Rules for building unit tests.
4
5 # Includers of this file must define the following values:
6 #
7 #   ASSEMBLY
8 #   ASSEMBLY_EXT
9 #   the_assembly
10
11 tests_CLEAN_FILES := 
12
13 ifndef TEST_COMPILE
14 TEST_COMPILE = $(subst $(test_remove),,$(CSCOMPILE))
15 endif
16
17 TEST_RUNTIME_WRAPPERS_PATH = $(shell dirname $(RUNTIME))/_tmpinst/bin
18
19 ## Unit test support
20 ifndef NO_TEST
21
22 test_nunit_lib = nunitlite.dll
23
24 TEST_LIB_MCS_FLAGS = $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/%.dll,$(TEST_LIB_REFS))
25
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
29
30 test_sourcefile = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll.sources)
31
32 ifeq ($(wildcard $(test_sourcefile)),)
33 test_sourcefile = $(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll.sources)
34 endif
35
36 test_lib = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll)
37 test_sourcefile_excludes = $(test_lib).exclude.sources
38
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)
44
45 ifndef HAVE_CS_TESTS
46 HAVE_CS_TESTS := $(wildcard $(test_sourcefile))
47 endif
48
49 HAVE_SOURCE_EXCLUDES := $(wildcard $(test_sourcefile_excludes))
50
51 endif # !NO_TEST
52
53 ifndef NO_TEST
54 $(test_nunit_dep): $(topdir)/build/deps/nunit-$(PROFILE).stamp
55         @if test -f $@; then :; else rm -f $<; $(MAKE) $<; fi
56
57 $(topdir)/build/deps/nunit-$(PROFILE).stamp:
58 ifndef PARENT_PROFILE
59         cd ${topdir}/tools/nunit-lite && $(MAKE)
60 endif
61         echo "stamp" >$@
62
63 tests_CLEAN_FILES += $(topdir)/build/deps/nunit-$(PROFILE).stamp
64 endif
65
66 test_assemblies :=
67
68 ifdef HAVE_CS_TESTS
69 test_assemblies += $(test_lib)
70 endif
71
72 ifdef test_assemblies
73 check: run-test
74 test-local: $(test_assemblies)
75 run-test-local: run-test-lib
76 run-test-ondotnet-local: run-test-ondotnet-lib
77
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
80
81 NOSHADOW_FLAG =
82
83 ifdef FIXTURE
84 FIXTURE_ARG = -test=MonoTests.$(FIXTURE)
85 endif
86
87 ifdef TESTNAME
88 TESTNAME_ARG = -test=MonoTests.$(TESTNAME)
89 endif
90
91 ifdef ALWAYS_AOT
92 test-local-aot-compile: $(topdir)/build/deps/nunit-$(PROFILE).stamp
93         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)
94
95 else
96 test-local-aot-compile: $(topdir)/build/deps/nunit-$(PROFILE).stamp
97
98 endif # ALWAYS_AOT
99
100 NUNITLITE_CONFIG_FILE=$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)nunit-lite-console.exe.config
101
102 patch-nunitlite-appconfig:
103         cp -f $(topdir)/tools/nunit-lite/nunit-lite-console/nunit-lite-console.exe.config.tmpl $(NUNITLITE_CONFIG_FILE)
104 ifdef TEST_NUNITLITE_APP_CONFIG_GLOBAL
105         sed -i -e "/__INSERT_CUSTOM_APP_CONFIG_GLOBAL__/r $(TEST_NUNITLITE_APP_CONFIG_GLOBAL)" $(NUNITLITE_CONFIG_FILE)
106 endif
107 ifdef TEST_NUNITLITE_APP_CONFIG_RUNTIME
108         sed -i -e "/__INSERT_CUSTOM_APP_CONFIG_RUNTIME__/r $(TEST_NUNITLITE_APP_CONFIG_RUNTIME)" $(NUNITLITE_CONFIG_FILE)
109 endif
110
111 ## FIXME: i18n problem in the 'sed' command below
112 run-test-lib: test-local test-local-aot-compile patch-nunitlite-appconfig
113         ok=:; \
114         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 -format:nunit2 -result:TestResult-$(PROFILE).xml $(FIXTURE_ARG) $(TESTNAME_ARG)|| ok=false; \
115         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; \
116         $$ok
117
118 ## Instructs compiler to compile to target .net execution, it can be usefull in rare cases when runtime detection is not possible
119 run-test-ondotnet-lib: LOCAL_TEST_COMPILER_ONDOTNET_FLAGS:=-d:RUN_ONDOTNET
120 run-test-ondotnet-lib: test-local
121         ok=:; \
122         $(TEST_HARNESS) $(test_assemblies) $(NOSHADOW_FLAG) $(TEST_HARNESS_FLAGS) $(LOCAL_TEST_HARNESS_ONDOTNET_FLAGS) $(TEST_HARNESS_EXCLUDES_ONDOTNET) -labels -format:nunit2 -result:TestResult-ondotnet-$(PROFILE).xml $(FIXTURE_ARG) $(TESTNAME_ARG) || ok=false; \
123         $$ok
124
125
126 endif # test_assemblies
127
128 TEST_FILES =
129
130 ifdef HAVE_CS_TESTS
131 TEST_FILES += `sed -e '/^$$/d' -e 's,^../,,' -et -e 's,^,Test/,' $(test_sourcefile)`
132 endif
133
134 ifdef HAVE_CS_TESTS
135
136 $(test_lib): $(the_assembly) $(test_response) $(test_nunit_dep)
137         $(TEST_COMPILE) $(LIBRARY_FLAGS) -target:library -out:$@ $(test_flags) $(LOCAL_TEST_COMPILER_ONDOTNET_FLAGS) @$(test_response)
138
139 test_response_preprocessed = $(test_response)_preprocessed
140
141 # This handles .excludes/.sources pairs, as well as resolving the
142 # includes that occur in .sources files
143 $(test_response_preprocessed): $(test_sourcefile)
144         $(SHELL) $(topdir)/build/gensources.sh $@ '$(test_sourcefile)' '$(test_sourcefile_excludes)'
145
146 $(test_response): $(test_response_preprocessed)
147 #       @echo Creating $@ ...
148         @sed -e '/^$$/d' -e 's,^,Test/,' $(test_response_preprocessed) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
149
150 $(test_makefrag): $(test_response)
151 #       @echo Creating $@ ...
152         @sed 's,^,$(test_lib): ,' $< >$@
153
154 -include $(test_makefrag)
155
156 endif
157
158 .PHONY: patch-nunitlite-appconfig