| @@ -1,187 +1,188 @@ | | | @@ -1,187 +1,188 @@ |
1 | # $NetBSD: Makefile,v 1.68 2020/07/27 19:23:12 rillig Exp $ | | 1 | # $NetBSD: Makefile,v 1.69 2020/07/27 19:45:56 rillig Exp $ |
2 | # | | 2 | # |
3 | # Unit tests for make(1) | | 3 | # Unit tests for make(1) |
4 | # | | 4 | # |
5 | # The main targets are: | | 5 | # The main targets are: |
6 | # | | 6 | # |
7 | # all: | | 7 | # all: |
8 | # run all the tests | | 8 | # run all the tests |
9 | # test: | | 9 | # test: |
10 | # run 'all', and compare to expected results | | 10 | # run 'all', and compare to expected results |
11 | # accept: | | 11 | # accept: |
12 | # move generated output to expected results | | 12 | # move generated output to expected results |
13 | # | | 13 | # |
14 | # Settable variables | | 14 | # Settable variables |
15 | # | | 15 | # |
16 | # TEST_MAKE | | 16 | # TEST_MAKE |
17 | # The make program to be tested. | | 17 | # The make program to be tested. |
18 | # | | 18 | # |
19 | # | | 19 | # |
20 | # Adding a test case | | 20 | # Adding a test case |
21 | # | | 21 | # |
22 | # Each feature should get its own set of tests in its own suitably | | 22 | # Each feature should get its own set of tests in its own suitably |
23 | # named makefile (*.mk), with its own set of expected results (*.exp), | | 23 | # named makefile (*.mk), with its own set of expected results (*.exp), |
24 | # and it should be added to the TESTS list. | | 24 | # and it should be added to the TESTS list. |
25 | # | | 25 | # |
26 | # Any added files must also be added to src/distrib/sets/lists/tests/mi. | | 26 | # Any added files must also be added to src/distrib/sets/lists/tests/mi. |
27 | # Makefiles that are not added to TESTS must be ignored in | | 27 | # Makefiles that are not added to TESTS must be ignored in |
28 | # src/tests/usr.bin/make/t_make.sh (example: include-sub). | | 28 | # src/tests/usr.bin/make/t_make.sh (example: include-sub). |
29 | # | | 29 | # |
30 | | | 30 | |
31 | # Each test is in a sub-makefile. | | 31 | # Each test is in a sub-makefile. |
32 | # Keep the list sorted. | | 32 | # Keep the list sorted. |
33 | TESTS+= archive | | 33 | TESTS+= archive |
34 | TESTS+= comment | | 34 | TESTS+= comment |
35 | TESTS+= cond-late | | 35 | TESTS+= cond-late |
36 | TESTS+= cond-short | | 36 | TESTS+= cond-short |
37 | TESTS+= cond1 | | 37 | TESTS+= cond1 |
38 | TESTS+= cond2 | | 38 | TESTS+= cond2 |
39 | TESTS+= dollar | | 39 | TESTS+= dollar |
40 | TESTS+= doterror | | 40 | TESTS+= doterror |
41 | TESTS+= dotwait | | 41 | TESTS+= dotwait |
42 | TESTS+= envfirst | | 42 | TESTS+= envfirst |
43 | TESTS+= error | | 43 | TESTS+= error |
44 | TESTS+= # escape # broken by reverting POSIX changes | | 44 | TESTS+= # escape # broken by reverting POSIX changes |
45 | TESTS+= export | | 45 | TESTS+= export |
46 | TESTS+= export-all | | 46 | TESTS+= export-all |
47 | TESTS+= export-env | | 47 | TESTS+= export-env |
48 | TESTS+= forloop | | 48 | TESTS+= forloop |
49 | TESTS+= forsubst | | 49 | TESTS+= forsubst |
50 | TESTS+= hash | | 50 | TESTS+= hash |
51 | TESTS+= # impsrc # broken by reverting POSIX changes | | 51 | TESTS+= # impsrc # broken by reverting POSIX changes |
52 | TESTS+= include-main | | 52 | TESTS+= include-main |
53 | TESTS+= misc | | 53 | TESTS+= misc |
54 | TESTS+= moderrs | | 54 | TESTS+= moderrs |
55 | TESTS+= modmatch | | 55 | TESTS+= modmatch |
56 | TESTS+= modmisc | | 56 | TESTS+= modmisc |
57 | TESTS+= modorder | | 57 | TESTS+= modorder |
58 | TESTS+= modts | | 58 | TESTS+= modts |
59 | TESTS+= modword | | 59 | TESTS+= modword |
60 | TESTS+= order | | 60 | TESTS+= order |
61 | TESTS+= # phony-end # broken by reverting POSIX changes | | 61 | TESTS+= # phony-end # broken by reverting POSIX changes |
62 | TESTS+= posix | | 62 | TESTS+= posix |
63 | TESTS+= # posix1 # broken by reverting POSIX changes | | 63 | TESTS+= # posix1 # broken by reverting POSIX changes |
64 | TESTS+= qequals | | 64 | TESTS+= qequals |
65 | TESTS+= # suffixes # broken by reverting POSIX changes | | 65 | TESTS+= # suffixes # broken by reverting POSIX changes |
66 | TESTS+= sunshcmd | | 66 | TESTS+= sunshcmd |
67 | TESTS+= sysv | | 67 | TESTS+= sysv |
68 | TESTS+= ternary | | 68 | TESTS+= ternary |
69 | TESTS+= unexport | | 69 | TESTS+= unexport |
70 | TESTS+= unexport-env | | 70 | TESTS+= unexport-env |
71 | TESTS+= varcmd | | 71 | TESTS+= varcmd |
72 | TESTS+= vardebug | | 72 | TESTS+= vardebug |
73 | TESTS+= varfind | | 73 | TESTS+= varfind |
74 | TESTS+= varmisc | | 74 | TESTS+= varmisc |
75 | TESTS+= varmod-edge | | 75 | TESTS+= varmod-edge |
76 | TESTS+= varparse-dynamic | | 76 | TESTS+= varparse-dynamic |
77 | TESTS+= varquote | | 77 | TESTS+= varquote |
78 | TESTS+= varshell | | 78 | TESTS+= varshell |
79 | | | 79 | |
80 | # Override environment variables for some of the tests. | | 80 | # Override environment variables for some of the tests. |
81 | ENV.envfirst= FROM_ENV=value-from-env | | 81 | ENV.envfirst= FROM_ENV=value-from-env |
| | | 82 | ENV.export= -i PATH=${PATH:Q} |
82 | ENV.varmisc= FROM_ENV=env | | 83 | ENV.varmisc= FROM_ENV=env |
83 | ENV.varmisc+= FROM_ENV_BEFORE=env | | 84 | ENV.varmisc+= FROM_ENV_BEFORE=env |
84 | ENV.varmisc+= FROM_ENV_AFTER=env | | 85 | ENV.varmisc+= FROM_ENV_AFTER=env |
85 | | | 86 | |
86 | # Override make flags for some of the tests; default is -k. | | 87 | # Override make flags for some of the tests; default is -k. |
87 | FLAGS.doterror= # none | | 88 | FLAGS.doterror= # none |
88 | FLAGS.envfirst= -e | | 89 | FLAGS.envfirst= -e |
89 | FLAGS.order= -j1 | | 90 | FLAGS.order= -j1 |
90 | FLAGS.vardebug= -k -dv FROM_CMDLINE= | | 91 | FLAGS.vardebug= -k -dv FROM_CMDLINE= |
91 | | | 92 | |
92 | # Some tests need extra post-processing. | | 93 | # Some tests need extra post-processing. |
93 | SED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),' | | 94 | SED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),' |
94 | SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,' | | 95 | SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,' |
95 | SED_CMDS.varshell+= -e '/command/s,No such.*,not found,' | | 96 | SED_CMDS.varshell+= -e '/command/s,No such.*,not found,' |
96 | | | 97 | |
97 | # Some tests need an additional round of postprocessing. | | 98 | # Some tests need an additional round of postprocessing. |
98 | POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' | | 99 | POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' |
99 | | | 100 | |
100 | # End of the configuration section. | | 101 | # End of the configuration section. |
101 | | | 102 | |
102 | .MAIN: all | | 103 | .MAIN: all |
103 | | | 104 | |
104 | UNIT_TESTS:= ${.PARSEDIR} | | 105 | UNIT_TESTS:= ${.PARSEDIR} |
105 | .PATH: ${UNIT_TESTS} | | 106 | .PATH: ${UNIT_TESTS} |
106 | | | 107 | |
107 | OUTFILES= ${TESTS:=.out} | | 108 | OUTFILES= ${TESTS:=.out} |
108 | | | 109 | |
109 | all: ${OUTFILES} | | 110 | all: ${OUTFILES} |
110 | | | 111 | |
111 | CLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp | | 112 | CLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp |
112 | CLEANFILES+= obj*.[och] lib*.a # posix1.mk | | 113 | CLEANFILES+= obj*.[och] lib*.a # posix1.mk |
113 | CLEANFILES+= issue* .[ab]* # suffixes.mk | | 114 | CLEANFILES+= issue* .[ab]* # suffixes.mk |
114 | CLEANRECURSIVE+= dir dummy # posix1.mk | | 115 | CLEANRECURSIVE+= dir dummy # posix1.mk |
115 | | | 116 | |
116 | clean: | | 117 | clean: |
117 | rm -f ${CLEANFILES} | | 118 | rm -f ${CLEANFILES} |
118 | .if !empty(CLEANRECURSIVE) | | 119 | .if !empty(CLEANRECURSIVE) |
119 | rm -rf ${CLEANRECURSIVE} | | 120 | rm -rf ${CLEANRECURSIVE} |
120 | .endif | | 121 | .endif |
121 | | | 122 | |
122 | TEST_MAKE?= ${.MAKE} | | 123 | TEST_MAKE?= ${.MAKE} |
123 | TOOL_SED?= sed | | 124 | TOOL_SED?= sed |
124 | | | 125 | |
125 | # ensure consistent results from sort(1) | | 126 | # ensure consistent results from sort(1) |
126 | LC_ALL= C | | 127 | LC_ALL= C |
127 | LANG= C | | 128 | LANG= C |
128 | .export LANG LC_ALL | | 129 | .export LANG LC_ALL |
129 | | | 130 | |
130 | # the tests are actually done with sub-makes. | | 131 | # the tests are actually done with sub-makes. |
131 | .SUFFIXES: .mk .rawout .out | | 132 | .SUFFIXES: .mk .rawout .out |
132 | .mk.rawout: | | 133 | .mk.rawout: |
133 | @echo testing ${.IMPSRC} | | 134 | @echo testing ${.IMPSRC} |
134 | @set -eu; \ | | 135 | @set -eu; \ |
135 | cd ${.OBJDIR}; \ | | 136 | cd ${.OBJDIR}; \ |
136 | ${ENV.${.TARGET:R}} ${TEST_MAKE} \ | | 137 | env ${ENV.${.TARGET:R}} ${TEST_MAKE} \ |
137 | ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \ | | 138 | ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \ |
138 | > ${.TARGET}.tmp 2>&1 \ | | 139 | > ${.TARGET}.tmp 2>&1 \ |
139 | && status=$$? || status=$$?; \ | | 140 | && status=$$? || status=$$?; \ |
140 | echo $$status > ${.TARGET:R}.status | | 141 | echo $$status > ${.TARGET:R}.status |
141 | @mv ${.TARGET}.tmp ${.TARGET} | | 142 | @mv ${.TARGET}.tmp ${.TARGET} |
142 | | | 143 | |
143 | # Post-process the test output so that the results can be compared. | | 144 | # Post-process the test output so that the results can be compared. |
144 | # | | 145 | # |
145 | # always pretend .MAKE was called 'make' | | 146 | # always pretend .MAKE was called 'make' |
146 | _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' | | 147 | _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' |
147 | _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' | | 148 | _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' |
148 | # replace anything after 'stopped in' with unit-tests | | 149 | # replace anything after 'stopped in' with unit-tests |
149 | _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' | | 150 | _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' |
150 | # strip ${.CURDIR}/ from the output | | 151 | # strip ${.CURDIR}/ from the output |
151 | _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' | | 152 | _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' |
152 | _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' | | 153 | _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' |
153 | | | 154 | |
154 | .rawout.out: | | 155 | .rawout.out: |
155 | @echo postprocess ${.TARGET} | | 156 | @echo postprocess ${.TARGET} |
156 | @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \ | | 157 | @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \ |
157 | < ${.IMPSRC} > ${.TARGET}.tmp1 | | 158 | < ${.IMPSRC} > ${.TARGET}.tmp1 |
158 | @${POSTPROC.${.TARGET:R}:U${TOOL_SED}} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 | | 159 | @${POSTPROC.${.TARGET:R}:U${TOOL_SED}} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 |
159 | @rm ${.TARGET}.tmp1 | | 160 | @rm ${.TARGET}.tmp1 |
160 | @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 | | 161 | @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 |
161 | @mv ${.TARGET}.tmp2 ${.TARGET} | | 162 | @mv ${.TARGET}.tmp2 ${.TARGET} |
162 | | | 163 | |
163 | # Compare all output files | | 164 | # Compare all output files |
164 | test: ${OUTFILES} .PHONY | | 165 | test: ${OUTFILES} .PHONY |
165 | @failed= ; \ | | 166 | @failed= ; \ |
166 | for test in ${TESTS}; do \ | | 167 | for test in ${TESTS}; do \ |
167 | diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ | | 168 | diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ |
168 | || failed="$${failed}$${failed:+ }$${test}" ; \ | | 169 | || failed="$${failed}$${failed:+ }$${test}" ; \ |
169 | done ; \ | | 170 | done ; \ |
170 | if [ -n "$${failed}" ]; then \ | | 171 | if [ -n "$${failed}" ]; then \ |
171 | echo "Failed tests: $${failed}" ; false ; \ | | 172 | echo "Failed tests: $${failed}" ; false ; \ |
172 | else \ | | 173 | else \ |
173 | echo "All tests passed" ; \ | | 174 | echo "All tests passed" ; \ |
174 | fi | | 175 | fi |
175 | | | 176 | |
176 | accept: | | 177 | accept: |
177 | @for test in ${TESTS}; do \ | | 178 | @for test in ${TESTS}; do \ |
178 | cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ | | 179 | cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ |
179 | || { echo "Replacing $${test}.exp" ; \ | | 180 | || { echo "Replacing $${test}.exp" ; \ |
180 | cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ | | 181 | cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ |
181 | done | | 182 | done |
182 | | | 183 | |
183 | .if exists(${TEST_MAKE}) | | 184 | .if exists(${TEST_MAKE}) |
184 | ${TESTS:=.rawout}: ${TEST_MAKE} | | 185 | ${TESTS:=.rawout}: ${TEST_MAKE} |
185 | .endif | | 186 | .endif |
186 | | | 187 | |
187 | .-include <bsd.obj.mk> | | 188 | .-include <bsd.obj.mk> |