| @@ -1,144 +1,154 @@ | | | @@ -1,144 +1,154 @@ |
1 | # $NetBSD: Makefile,v 1.59 2020/06/28 09:42:40 rillig Exp $ | | 1 | # $NetBSD: Makefile,v 1.60 2020/07/04 21:04:25 rillig Exp $ |
2 | # | | 2 | # |
3 | # Unit tests for make(1) | | 3 | # Unit tests for make(1) |
| | | 4 | # |
4 | # The main targets are: | | 5 | # The main targets are: |
5 | # | | | |
6 | # all: run all the tests | | | |
7 | # test: run 'all', and compare to expected results | | | |
8 | # accept: move generated output to expected results | | | |
9 | # | | 6 | # |
10 | # Adding a test case. | | 7 | # all: |
| | | 8 | # run all the tests |
| | | 9 | # test: |
| | | 10 | # run 'all', and compare to expected results |
| | | 11 | # accept: |
| | | 12 | # move generated output to expected results |
| | | 13 | # |
| | | 14 | # |
| | | 15 | # Adding a test case |
| | | 16 | # |
11 | # Each feature should get its own set of tests in its own suitably | | 17 | # Each feature should get its own set of tests in its own suitably |
12 | # named makefile (*.mk), with its own set of expected results (*.exp), | | 18 | # named makefile (*.mk), with its own set of expected results (*.exp), |
13 | # and it should be added to the TESTNAMES list. | | 19 | # and it should be added to the TESTNAMES list. |
14 | # | | 20 | # |
| | | 21 | # Any added files must also be added to src/distrib/sets/lists/tests/mi. |
| | | 22 | # Makefiles that are not added to TESTNAMES must be ignored in |
| | | 23 | # src/tests/usr.bin/make/t_make.sh (example: include-sub). |
| | | 24 | # |
15 | | | 25 | |
16 | .MAIN: all | | 26 | .MAIN: all |
17 | | | 27 | |
18 | UNIT_TESTS:= ${.PARSEDIR} | | 28 | UNIT_TESTS:= ${.PARSEDIR} |
19 | .PATH: ${UNIT_TESTS} | | 29 | .PATH: ${UNIT_TESTS} |
20 | | | 30 | |
21 | # Each test is in a sub-makefile. | | 31 | # Each test is in a sub-makefile. |
22 | # Keep the list sorted. | | 32 | # Keep the list sorted. |
23 | TESTNAMES= \ | | 33 | TESTNAMES= \ |
24 | comment \ | | 34 | comment \ |
25 | cond-late \ | | 35 | cond-late \ |
26 | cond-short \ | | 36 | cond-short \ |
27 | cond1 \ | | 37 | cond1 \ |
28 | cond2 \ | | 38 | cond2 \ |
29 | dollar \ | | 39 | dollar \ |
30 | doterror \ | | 40 | doterror \ |
31 | dotwait \ | | 41 | dotwait \ |
32 | error \ | | 42 | error \ |
33 | export \ | | 43 | export \ |
34 | export-all \ | | 44 | export-all \ |
35 | export-env \ | | 45 | export-env \ |
36 | forloop \ | | 46 | forloop \ |
37 | forsubst \ | | 47 | forsubst \ |
38 | hash \ | | 48 | hash \ |
39 | include-main \ | | 49 | include-main \ |
40 | misc \ | | 50 | misc \ |
41 | moderrs \ | | 51 | moderrs \ |
42 | modmatch \ | | 52 | modmatch \ |
43 | modmisc \ | | 53 | modmisc \ |
44 | modorder \ | | 54 | modorder \ |
45 | modts \ | | 55 | modts \ |
46 | modword \ | | 56 | modword \ |
47 | order \ | | 57 | order \ |
48 | posix \ | | 58 | posix \ |
49 | qequals \ | | 59 | qequals \ |
50 | sunshcmd \ | | 60 | sunshcmd \ |
51 | sysv \ | | 61 | sysv \ |
52 | ternary \ | | 62 | ternary \ |
53 | unexport \ | | 63 | unexport \ |
54 | unexport-env \ | | 64 | unexport-env \ |
55 | varcmd \ | | 65 | varcmd \ |
56 | varmisc \ | | 66 | varmisc \ |
57 | varmod-edge \ | | 67 | varmod-edge \ |
58 | varquote \ | | 68 | varquote \ |
59 | varshell | | 69 | varshell |
60 | | | 70 | |
61 | # these tests were broken by referting POSIX chanegs | | 71 | # these tests were broken by referting POSIX chanegs |
62 | STRICT_POSIX_TESTS = \ | | 72 | STRICT_POSIX_TESTS = \ |
63 | escape \ | | 73 | escape \ |
64 | impsrc \ | | 74 | impsrc \ |
65 | phony-end \ | | 75 | phony-end \ |
66 | posix1 \ | | 76 | posix1 \ |
67 | suffixes | | 77 | suffixes |
68 | | | 78 | |
69 | # Override make flags for certain tests | | 79 | # Override make flags for certain tests |
70 | flags.doterror= | | 80 | flags.doterror= |
71 | flags.order=-j1 | | 81 | flags.order=-j1 |
72 | | | 82 | |
73 | OUTFILES= ${TESTNAMES:S/$/.out/} | | 83 | OUTFILES= ${TESTNAMES:S/$/.out/} |
74 | | | 84 | |
75 | all: ${OUTFILES} | | 85 | all: ${OUTFILES} |
76 | | | 86 | |
77 | CLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp | | 87 | CLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp |
78 | CLEANFILES += obj*.[och] lib*.a # posix1.mk | | 88 | CLEANFILES += obj*.[och] lib*.a # posix1.mk |
79 | CLEANFILES += issue* .[ab]* # suffixes.mk | | 89 | CLEANFILES += issue* .[ab]* # suffixes.mk |
80 | CLEANRECURSIVE += dir dummy # posix1.mk | | 90 | CLEANRECURSIVE += dir dummy # posix1.mk |
81 | | | 91 | |
82 | clean: | | 92 | clean: |
83 | rm -f ${CLEANFILES} | | 93 | rm -f ${CLEANFILES} |
84 | .if !empty(CLEANRECURSIVE) | | 94 | .if !empty(CLEANRECURSIVE) |
85 | rm -rf ${CLEANRECURSIVE} | | 95 | rm -rf ${CLEANRECURSIVE} |
86 | .endif | | 96 | .endif |
87 | | | 97 | |
88 | TEST_MAKE?= ${.MAKE} | | 98 | TEST_MAKE?= ${.MAKE} |
89 | TOOL_SED?= sed | | 99 | TOOL_SED?= sed |
90 | | | 100 | |
91 | # ensure consistent results from sort(1) | | 101 | # ensure consistent results from sort(1) |
92 | LC_ALL= C | | 102 | LC_ALL= C |
93 | LANG= C | | 103 | LANG= C |
94 | .export LANG LC_ALL | | 104 | .export LANG LC_ALL |
95 | | | 105 | |
96 | # the tests are actually done with sub-makes. | | 106 | # the tests are actually done with sub-makes. |
97 | .SUFFIXES: .mk .rawout .out | | 107 | .SUFFIXES: .mk .rawout .out |
98 | .mk.rawout: | | 108 | .mk.rawout: |
99 | @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} | | 109 | @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} |
100 | -@cd ${.OBJDIR} && \ | | 110 | -@cd ${.OBJDIR} && \ |
101 | { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \ | | 111 | { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \ |
102 | 2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp | | 112 | 2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp |
103 | @mv ${.TARGET}.tmp ${.TARGET} | | 113 | @mv ${.TARGET}.tmp ${.TARGET} |
104 | | | 114 | |
105 | # We always pretend .MAKE was called 'make' | | 115 | # We always pretend .MAKE was called 'make' |
106 | # and strip ${.CURDIR}/ from the output | | 116 | # and strip ${.CURDIR}/ from the output |
107 | # and replace anything after 'stopped in' with unit-tests | | 117 | # and replace anything after 'stopped in' with unit-tests |
108 | # so the results can be compared. | | 118 | # so the results can be compared. |
109 | .rawout.out: | | 119 | .rawout.out: |
110 | @echo postprocess ${.TARGET} | | 120 | @echo postprocess ${.TARGET} |
111 | @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \ | | 121 | @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \ |
112 | -e 's,${TEST_MAKE:C/\./\\\./g},make,' \ | | 122 | -e 's,${TEST_MAKE:C/\./\\\./g},make,' \ |
113 | -e '/stopped/s, /.*, unit-tests,' \ | | 123 | -e '/stopped/s, /.*, unit-tests,' \ |
114 | -e 's,${.CURDIR:C/\./\\\./g}/,,g' \ | | 124 | -e 's,${.CURDIR:C/\./\\\./g}/,,g' \ |
115 | -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \ | | 125 | -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \ |
116 | < ${.IMPSRC} > ${.TARGET}.tmp | | 126 | < ${.IMPSRC} > ${.TARGET}.tmp |
117 | @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp | | 127 | @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp |
118 | @mv ${.TARGET}.tmp ${.TARGET} | | 128 | @mv ${.TARGET}.tmp ${.TARGET} |
119 | | | 129 | |
120 | # Compare all output files | | 130 | # Compare all output files |
121 | test: ${OUTFILES} .PHONY | | 131 | test: ${OUTFILES} .PHONY |
122 | @failed= ; \ | | 132 | @failed= ; \ |
123 | for test in ${TESTNAMES}; do \ | | 133 | for test in ${TESTNAMES}; do \ |
124 | diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ | | 134 | diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ |
125 | || failed="$${failed}$${failed:+ }$${test}" ; \ | | 135 | || failed="$${failed}$${failed:+ }$${test}" ; \ |
126 | done ; \ | | 136 | done ; \ |
127 | if [ -n "$${failed}" ]; then \ | | 137 | if [ -n "$${failed}" ]; then \ |
128 | echo "Failed tests: $${failed}" ; false ; \ | | 138 | echo "Failed tests: $${failed}" ; false ; \ |
129 | else \ | | 139 | else \ |
130 | echo "All tests passed" ; \ | | 140 | echo "All tests passed" ; \ |
131 | fi | | 141 | fi |
132 | | | 142 | |
133 | accept: | | 143 | accept: |
134 | @for test in ${TESTNAMES}; do \ | | 144 | @for test in ${TESTNAMES}; do \ |
135 | cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ | | 145 | cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ |
136 | || { echo "Replacing $${test}.exp" ; \ | | 146 | || { echo "Replacing $${test}.exp" ; \ |
137 | cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ | | 147 | cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ |
138 | done | | 148 | done |
139 | | | 149 | |
140 | .if exists(${TEST_MAKE}) | | 150 | .if exists(${TEST_MAKE}) |
141 | ${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE} | | 151 | ${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE} |
142 | .endif | | 152 | .endif |
143 | | | 153 | |
144 | .-include <bsd.obj.mk> | | 154 | .-include <bsd.obj.mk> |