[MSBuild] Fix minor assembly resolution issue
[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 test_nunit_lib = nunit.framework.dll nunit.core.dll nunit.util.dll nunit.mocks.dll
22 test_nunit_dep = $(test_nunit_lib:%=$(topdir)/class/lib/$(PROFILE)/%)
23 test_nunit_ref = $(test_nunit_dep:%=-r:%)
24 tests_CLEAN_FILES += TestResult*.xml
25
26 test_lib = $(ASSEMBLY:$(ASSEMBLY_EXT)=_test_$(PROFILE).dll)
27 test_sourcefile = $(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll.sources)
28 test_pdb = $(test_lib:.dll=.pdb)
29 test_response = $(depsdir)/$(test_lib).response
30 test_makefrag = $(depsdir)/$(test_lib).makefrag
31 test_flags = -r:$(the_assembly) $(test_nunit_ref) $(TEST_MCS_FLAGS)
32 tests_CLEAN_FILES += $(ASSEMBLY:$(ASSEMBLY_EXT)=_test*.dll) $(ASSEMBLY:$(ASSEMBLY_EXT)=_test*.pdb) $(test_response) $(test_makefrag)
33
34 ifndef HAVE_CS_TESTS
35 HAVE_CS_TESTS := $(wildcard $(test_sourcefile))
36 endif
37
38 endif
39
40 ifndef NO_TEST
41 $(test_nunit_dep): $(topdir)/build/deps/nunit-$(PROFILE).stamp
42         @if test -f $@; then :; else rm -f $<; $(MAKE) $<; fi
43 $(topdir)/build/deps/nunit-$(PROFILE).stamp:
44         cd ${topdir}/nunit24 && $(MAKE)
45         echo "stamp" >$@
46 tests_CLEAN_FILES += $(topdir)/build/deps/nunit-$(PROFILE).stamp
47 endif
48
49 test_assemblies :=
50
51 ifdef HAVE_CS_TESTS
52 test_assemblies += $(test_lib)
53 endif
54
55 ifdef test_assemblies
56 check: run-test
57 test-local: $(test_assemblies)
58 run-test-local: run-test-lib
59 run-test-ondotnet-local: run-test-ondotnet-lib
60
61 TEST_HARNESS_EXCLUDES = -exclude=$(PLATFORM_TEST_HARNESS_EXCLUDES)NotWorking,ValueAdd,CAS,InetAccess
62 TEST_HARNESS_EXCLUDES_ONDOTNET = /exclude:$(PLATFORM_TEST_HARNESS_EXCLUDES)NotDotNet,CAS
63
64 ifdef TEST_HARNESS_VERBOSE
65 TEST_HARNESS_OUTPUT = -labels
66 TEST_HARNESS_OUTPUT_ONDOTNET = -labels
67 TEST_HARNESS_POSTPROC = :
68 TEST_HARNESS_POSTPROC_ONDOTNET = :
69 else
70 TEST_HARNESS_OUTPUT = -output=TestResult-$(PROFILE).log
71 TEST_HARNESS_OUTPUT_ONDOTNET = -output=TestResult-ondotnet-$(PROFILE).log
72 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
73 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
74 endif
75
76 ifdef FIXTURE
77 FIXTURE_ARG = -fixture=MonoTests.$(FIXTURE)
78 endif
79
80 ifdef TESTNAME
81 TESTNAME_ARG = -run=MonoTests.$(TESTNAME)
82 endif
83
84 ## FIXME: i18n problem in the 'sed' command below
85 run-test-lib: test-local
86         ok=:; \
87         PATH="$(TEST_RUNTIME_WRAPPERS_PATH):$(PATH)" MONO_REGISTRY_PATH="$(HOME)/.mono/registry" MONO_TESTS_IN_PROGRESS="yes" $(TEST_RUNTIME) $(RUNTIME_FLAGS) $(TEST_HARNESS) $(test_assemblies) -noshadow $(TEST_HARNESS_FLAGS) $(LOCAL_TEST_HARNESS_FLAGS) $(TEST_HARNESS_EXCLUDES) $(TEST_HARNESS_OUTPUT) -xml=TestResult-$(PROFILE).xml $(FIXTURE_ARG) $(TESTNAME_ARG)|| ok=false; \
88         if [ ! -f "TestResult-$(PROFILE).xml" ]; then echo "<?xml version='1.0' encoding='utf8'?><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; \
89         $(TEST_HARNESS_POSTPROC) ; $$ok
90
91 ## Instructs compiler to compile to target .net execution, it can be usefull in rare cases when runtime detection is not possible
92 run-test-ondotnet-lib: LOCAL_TEST_COMPILER_ONDOTNET_FLAGS:=-d:RUN_ONDOTNET
93 run-test-ondotnet-lib: test-local
94         ok=:; \
95         $(TEST_HARNESS) $(test_assemblies) -noshadow $(TEST_HARNESS_FLAGS) $(LOCAL_TEST_HARNESS_ONDOTNET_FLAGS) $(TEST_HARNESS_EXCLUDES_ONDOTNET) $(TEST_HARNESS_OUTPUT_ONDOTNET) -xml=TestResult-ondotnet-$(PROFILE).xml $(FIXTURE_ARG) $(TESTNAME_ARG) || ok=false; \
96         $(TEST_HARNESS_POSTPROC_ONDOTNET) ; $$ok
97
98
99 endif # test_assemblies
100
101 TEST_FILES =
102
103 ifdef HAVE_CS_TESTS
104 TEST_FILES += `sed -e '/^$$/d' -e 's,^../,,' -et -e 's,^,Test/,' $(test_sourcefile)`
105 endif
106
107 ifdef HAVE_CS_TESTS
108
109 $(test_lib): $(the_assembly) $(test_response) $(test_nunit_dep)
110         $(TEST_COMPILE) $(LIBRARY_FLAGS) -target:library -out:$@ $(test_flags) $(LOCAL_TEST_COMPILER_ONDOTNET_FLAGS) @$(test_response)
111
112 $(test_response): $(test_sourcefile)
113 #       @echo Creating $@ ...
114         @sed -e '/^$$/d' -e 's,^,Test/,' $(test_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
115
116 $(test_makefrag): $(test_response)
117 #       @echo Creating $@ ...
118         @sed 's,^,$(test_lib): ,' $< >$@
119
120 -include $(test_makefrag)
121
122 endif
123