Tue Jul 28 18:39:56 2020 UTC ()
Use cat if no POSTPROC.${.TARGET:R}

On Linux sed with no flags throws an error.


(sjg)
diff -r1.73 -r1.74 src/usr.bin/make/unit-tests/Makefile

cvs diff -r1.73 -r1.74 src/usr.bin/make/unit-tests/Makefile (switch to unified diff)

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