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