Makefile revision 1.250 1 # $NetBSD: Makefile,v 1.250 2020/12/14 20:23:50 rillig Exp $
2 #
3 # Unit tests for make(1)
4 #
5 # The main targets are:
6 #
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 # Settable variables
15 #
16 # TEST_MAKE
17 # The make program to be tested.
18 #
19 #
20 # Adding a test case
21 #
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),
24 # and it should be added to the TESTS list.
25 #
26 # Any added files must also be added to src/distrib/sets/lists/tests/mi.
27 # To do that, just run "make sync-mi" in this directory.
28 #
29 # A few *.mk files are helper files for other tests (such as include-sub.mk)
30 # and are thus not added to TESTS. Such files must be ignored in
31 # src/tests/usr.bin/make/t_make.sh.
32 #
33
34 # we use this below but we might be an older make
35 .MAKE.UID?= ${id -u:L:sh}
36
37 # Each test is in a sub-makefile.
38 # Keep the list sorted.
39 # Any test that is commented out must be ignored in
40 # src/tests/usr.bin/make/t_make.sh as well.
41 TESTS+= archive
42 TESTS+= archive-suffix
43 TESTS+= cmd-errors
44 TESTS+= cmd-errors-lint
45 TESTS+= cmd-interrupt
46 TESTS+= cmdline
47 TESTS+= cmdline-undefined
48 TESTS+= comment
49 TESTS+= compat-error
50 TESTS+= cond-cmp-numeric
51 TESTS+= cond-cmp-numeric-eq
52 TESTS+= cond-cmp-numeric-ge
53 TESTS+= cond-cmp-numeric-gt
54 TESTS+= cond-cmp-numeric-le
55 TESTS+= cond-cmp-numeric-lt
56 TESTS+= cond-cmp-numeric-ne
57 TESTS+= cond-cmp-string
58 TESTS+= cond-cmp-unary
59 TESTS+= cond-eof
60 TESTS+= cond-func
61 TESTS+= cond-func-commands
62 TESTS+= cond-func-defined
63 TESTS+= cond-func-empty
64 TESTS+= cond-func-exists
65 TESTS+= cond-func-make
66 TESTS+= cond-func-make-main
67 TESTS+= cond-func-target
68 TESTS+= cond-late
69 TESTS+= cond-op
70 TESTS+= cond-op-and
71 TESTS+= cond-op-and-lint
72 TESTS+= cond-op-not
73 TESTS+= cond-op-or
74 TESTS+= cond-op-or-lint
75 TESTS+= cond-op-parentheses
76 TESTS+= cond-short
77 TESTS+= cond-token-number
78 TESTS+= cond-token-plain
79 TESTS+= cond-token-string
80 TESTS+= cond-token-var
81 TESTS+= cond-undef-lint
82 TESTS+= cond1
83 TESTS+= counter
84 TESTS+= counter-append
85 TESTS+= dep
86 TESTS+= dep-colon
87 TESTS+= dep-colon-bug-cross-file
88 TESTS+= dep-double-colon
89 TESTS+= dep-double-colon-indep
90 TESTS+= dep-exclam
91 TESTS+= dep-none
92 TESTS+= dep-percent
93 TESTS+= dep-var
94 TESTS+= dep-wildcards
95 TESTS+= depsrc
96 TESTS+= depsrc-end
97 TESTS+= depsrc-exec
98 TESTS+= depsrc-ignore
99 TESTS+= depsrc-made
100 TESTS+= depsrc-make
101 TESTS+= depsrc-meta
102 TESTS+= depsrc-nometa
103 TESTS+= depsrc-nometa_cmp
104 TESTS+= depsrc-nopath
105 TESTS+= depsrc-notmain
106 TESTS+= depsrc-optional
107 TESTS+= depsrc-phony
108 TESTS+= depsrc-precious
109 TESTS+= depsrc-recursive
110 TESTS+= depsrc-silent
111 TESTS+= depsrc-use
112 TESTS+= depsrc-usebefore
113 TESTS+= depsrc-usebefore-double-colon
114 TESTS+= depsrc-wait
115 TESTS+= deptgt
116 TESTS+= deptgt-begin
117 TESTS+= deptgt-begin-fail
118 TESTS+= deptgt-begin-fail-indirect
119 TESTS+= deptgt-default
120 TESTS+= deptgt-delete_on_error
121 TESTS+= deptgt-end
122 TESTS+= deptgt-end-fail
123 TESTS+= deptgt-end-fail-all
124 TESTS+= deptgt-end-fail-indirect
125 TESTS+= deptgt-end-jobs
126 TESTS+= deptgt-error
127 TESTS+= deptgt-ignore
128 TESTS+= deptgt-interrupt
129 TESTS+= deptgt-main
130 TESTS+= deptgt-makeflags
131 TESTS+= deptgt-no_parallel
132 TESTS+= deptgt-nopath
133 TESTS+= deptgt-notparallel
134 TESTS+= deptgt-objdir
135 TESTS+= deptgt-order
136 TESTS+= deptgt-path
137 TESTS+= deptgt-path-suffix
138 TESTS+= deptgt-phony
139 TESTS+= deptgt-precious
140 TESTS+= deptgt-shell
141 TESTS+= deptgt-silent
142 TESTS+= deptgt-stale
143 TESTS+= deptgt-suffixes
144 TESTS+= dir
145 TESTS+= dir-expand-path
146 TESTS+= directive
147 TESTS+= directive-dinclude
148 TESTS+= directive-elif
149 TESTS+= directive-elifdef
150 TESTS+= directive-elifmake
151 TESTS+= directive-elifndef
152 TESTS+= directive-elifnmake
153 TESTS+= directive-else
154 TESTS+= directive-endif
155 TESTS+= directive-error
156 TESTS+= directive-export
157 TESTS+= directive-export-env
158 TESTS+= directive-export-gmake
159 TESTS+= directive-export-literal
160 TESTS+= directive-for
161 TESTS+= directive-for-generating-endif
162 TESTS+= directive-hyphen-include
163 TESTS+= directive-if
164 TESTS+= directive-if-nested
165 TESTS+= directive-ifdef
166 TESTS+= directive-ifmake
167 TESTS+= directive-ifndef
168 TESTS+= directive-ifnmake
169 TESTS+= directive-include
170 TESTS+= directive-include-fatal
171 TESTS+= directive-info
172 TESTS+= directive-misspellings
173 TESTS+= directive-sinclude
174 TESTS+= directive-undef
175 TESTS+= directive-unexport
176 TESTS+= directive-unexport-env
177 TESTS+= directive-warning
178 TESTS+= dollar
179 TESTS+= doterror
180 TESTS+= dotwait
181 TESTS+= envfirst
182 TESTS+= error
183 TESTS+= # escape # broken by reverting POSIX changes
184 TESTS+= export
185 TESTS+= export-all
186 TESTS+= export-env
187 TESTS+= export-variants
188 TESTS+= forloop
189 TESTS+= forsubst
190 TESTS+= gnode-submake
191 TESTS+= hanoi-include
192 TESTS+= impsrc
193 TESTS+= include-main
194 TESTS+= job-flags
195 TESTS+= job-output-long-lines
196 TESTS+= jobs-error-indirect
197 TESTS+= jobs-error-nested
198 TESTS+= jobs-error-nested-make
199 TESTS+= lint
200 TESTS+= make-exported
201 TESTS+= meta-cmd-cmp
202 TESTS+= moderrs
203 TESTS+= modmatch
204 TESTS+= modmisc
205 TESTS+= modts
206 TESTS+= modword
207 .if ${.MAKE.UID} > 0
208 TESTS+= objdir-writable
209 .endif
210 TESTS+= opt
211 TESTS+= opt-backwards
212 TESTS+= opt-chdir
213 TESTS+= opt-debug
214 TESTS+= opt-debug-all
215 TESTS+= opt-debug-archive
216 TESTS+= opt-debug-curdir
217 TESTS+= opt-debug-cond
218 TESTS+= opt-debug-dir
219 TESTS+= opt-debug-errors
220 TESTS+= opt-debug-file
221 TESTS+= opt-debug-for
222 TESTS+= opt-debug-graph1
223 TESTS+= opt-debug-graph2
224 TESTS+= opt-debug-graph3
225 TESTS+= opt-debug-hash
226 TESTS+= opt-debug-jobs
227 TESTS+= opt-debug-lint
228 TESTS+= opt-debug-loud
229 TESTS+= opt-debug-meta
230 TESTS+= opt-debug-making
231 TESTS+= opt-debug-no-rm
232 TESTS+= opt-debug-parse
233 TESTS+= opt-debug-suff
234 TESTS+= opt-debug-targets
235 TESTS+= opt-debug-varraw
236 TESTS+= opt-debug-var
237 TESTS+= opt-debug-x-trace
238 TESTS+= opt-define
239 TESTS+= opt-env
240 TESTS+= opt-file
241 TESTS+= opt-ignore
242 TESTS+= opt-include-dir
243 TESTS+= opt-jobs
244 TESTS+= opt-jobs-internal
245 TESTS+= opt-jobs-no-action
246 TESTS+= opt-keep-going
247 TESTS+= opt-keep-going-multiple
248 TESTS+= opt-m-include-dir
249 TESTS+= opt-no-action
250 TESTS+= opt-no-action-at-all
251 TESTS+= opt-no-action-runflags
252 TESTS+= opt-query
253 TESTS+= opt-raw
254 TESTS+= opt-silent
255 TESTS+= opt-touch
256 TESTS+= opt-touch-jobs
257 TESTS+= opt-tracefile
258 TESTS+= opt-var-expanded
259 TESTS+= opt-var-literal
260 TESTS+= opt-warnings-as-errors
261 TESTS+= opt-where-am-i
262 TESTS+= opt-x-reduce-exported
263 TESTS+= order
264 TESTS+= parse-var
265 TESTS+= phony-end
266 TESTS+= posix
267 TESTS+= # posix1 # broken by reverting POSIX changes
268 TESTS+= recursive
269 TESTS+= sh
270 TESTS+= sh-dots
271 TESTS+= sh-errctl
272 TESTS+= sh-flags
273 TESTS+= sh-jobs
274 TESTS+= sh-jobs-error
275 TESTS+= sh-leading-at
276 TESTS+= sh-leading-hyphen
277 TESTS+= sh-leading-plus
278 TESTS+= sh-meta-chars
279 TESTS+= sh-multi-line
280 TESTS+= sh-single-line
281 TESTS+= shell-csh
282 TESTS+= shell-custom
283 TESTS+= shell-ksh
284 TESTS+= shell-sh
285 TESTS+= suff-add-later
286 TESTS+= suff-clear-regular
287 TESTS+= suff-clear-single
288 TESTS+= suff-incomplete
289 TESTS+= suff-lookup
290 TESTS+= suff-main
291 TESTS+= suff-main-several
292 TESTS+= suff-phony
293 TESTS+= suff-rebuild
294 TESTS+= suff-self
295 TESTS+= suff-transform-debug
296 TESTS+= suff-transform-endless
297 TESTS+= suff-transform-expand
298 TESTS+= suff-transform-select
299 TESTS+= sunshcmd
300 TESTS+= ternary
301 TESTS+= unexport
302 TESTS+= unexport-env
303 TESTS+= use-inference
304 TESTS+= var-class
305 TESTS+= var-class-cmdline
306 TESTS+= var-class-env
307 TESTS+= var-class-global
308 TESTS+= var-class-local
309 TESTS+= var-class-local-legacy
310 TESTS+= var-op
311 TESTS+= var-op-append
312 TESTS+= var-op-assign
313 TESTS+= var-op-default
314 TESTS+= var-op-expand
315 TESTS+= var-op-shell
316 TESTS+= var-op-sunsh
317 TESTS+= var-recursive
318 TESTS+= varcmd
319 TESTS+= vardebug
320 TESTS+= varfind
321 TESTS+= varmisc
322 TESTS+= varmod
323 TESTS+= varmod-assign
324 TESTS+= varmod-defined
325 TESTS+= varmod-edge
326 TESTS+= varmod-exclam-shell
327 TESTS+= varmod-extension
328 TESTS+= varmod-gmtime
329 TESTS+= varmod-hash
330 TESTS+= varmod-head
331 TESTS+= varmod-ifelse
332 TESTS+= varmod-indirect
333 TESTS+= varmod-l-name-to-value
334 TESTS+= varmod-localtime
335 TESTS+= varmod-loop
336 TESTS+= varmod-match
337 TESTS+= varmod-match-escape
338 TESTS+= varmod-no-match
339 TESTS+= varmod-order
340 TESTS+= varmod-order-reverse
341 TESTS+= varmod-order-shuffle
342 TESTS+= varmod-path
343 TESTS+= varmod-quote
344 TESTS+= varmod-quote-dollar
345 TESTS+= varmod-range
346 TESTS+= varmod-remember
347 TESTS+= varmod-root
348 TESTS+= varmod-select-words
349 TESTS+= varmod-shell
350 TESTS+= varmod-subst
351 TESTS+= varmod-subst-regex
352 TESTS+= varmod-sysv
353 TESTS+= varmod-tail
354 TESTS+= varmod-to-abs
355 TESTS+= varmod-to-lower
356 TESTS+= varmod-to-many-words
357 TESTS+= varmod-to-one-word
358 TESTS+= varmod-to-separator
359 TESTS+= varmod-to-upper
360 TESTS+= varmod-undefined
361 TESTS+= varmod-unique
362 TESTS+= varname
363 TESTS+= varname-dollar
364 TESTS+= varname-dot-alltargets
365 TESTS+= varname-dot-curdir
366 TESTS+= varname-dot-includes
367 TESTS+= varname-dot-includedfromdir
368 TESTS+= varname-dot-includedfromfile
369 TESTS+= varname-dot-libs
370 TESTS+= varname-dot-make-dependfile
371 TESTS+= varname-dot-make-expand_variables
372 TESTS+= varname-dot-make-exported
373 TESTS+= varname-dot-make-jobs
374 TESTS+= varname-dot-make-jobs-prefix
375 TESTS+= varname-dot-make-level
376 TESTS+= varname-dot-make-makefile_preference
377 TESTS+= varname-dot-make-makefiles
378 TESTS+= varname-dot-make-meta-bailiwick
379 TESTS+= varname-dot-make-meta-created
380 TESTS+= varname-dot-make-meta-files
381 TESTS+= varname-dot-make-meta-ignore_filter
382 TESTS+= varname-dot-make-meta-ignore_paths
383 TESTS+= varname-dot-make-meta-ignore_patterns
384 TESTS+= varname-dot-make-meta-prefix
385 TESTS+= varname-dot-make-mode
386 TESTS+= varname-dot-make-path_filemon
387 TESTS+= varname-dot-make-pid
388 TESTS+= varname-dot-make-ppid
389 TESTS+= varname-dot-make-save_dollars
390 TESTS+= varname-dot-makeflags
391 TESTS+= varname-dot-makeoverrides
392 TESTS+= varname-dot-newline
393 TESTS+= varname-dot-objdir
394 TESTS+= varname-dot-parsedir
395 TESTS+= varname-dot-parsefile
396 TESTS+= varname-dot-path
397 TESTS+= varname-dot-shell
398 TESTS+= varname-dot-targets
399 TESTS+= varname-empty
400 TESTS+= varname-make
401 TESTS+= varname-make_print_var_on_error
402 TESTS+= varname-make_print_var_on_error-jobs
403 TESTS+= varname-makefile
404 TESTS+= varname-makeflags
405 TESTS+= varname-pwd
406 TESTS+= varname-vpath
407 TESTS+= varparse-dynamic
408 TESTS+= varparse-errors
409 TESTS+= varparse-mod
410 TESTS+= varparse-undef-partial
411 TESTS+= varquote
412
413 # Ideas for more tests:
414 # char-0020-space.mk
415 # char-005C-backslash.mk
416 # escape-cond-str.mk
417 # escape-cond-func-arg.mk
418 # escape-cond-func-arg.mk
419 # escape-varmod.mk
420 # escape-varmod-define.mk
421 # escape-varmod-match.mk
422 # escape-varname.mk
423 # escape-varassign-varname.mk
424 # escape-varassign-varname-cmdline.mk
425 # escape-varassign-value.mk
426 # escape-varassign-value-cmdline.mk
427 # escape-dependency-source.mk
428 # escape-dependency-target.mk
429 # escape-for-varname.mk
430 # escape-for-item.mk
431 # posix-*.mk (see posix.mk and posix1.mk)
432
433 .if ${.OBJDIR} != ${.CURDIR}
434 RO_OBJDIR:= ${.OBJDIR}/roobj
435 .else
436 RO_OBJDIR:= ${TMPDIR:U/tmp}/roobj
437 .endif
438 # Additional environment variables for some of the tests.
439 # The base environment is -i PATH="$PATH".
440 ENV.depsrc-optional+= TZ=UTC
441 ENV.envfirst= FROM_ENV=value-from-env
442 ENV.objdir-writable+= RO_OBJDIR=${RO_OBJDIR}
443 ENV.varmisc= FROM_ENV=env
444 ENV.varmisc+= FROM_ENV_BEFORE=env
445 ENV.varmisc+= FROM_ENV_AFTER=env
446 ENV.varmod-localtime+= TZ=Europe/Berlin
447 ENV.varname-vpath+= VPATH=varname-vpath.dir:varname-vpath.dir2
448
449 # Override make flags for some of the tests; default is -k.
450 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
451 # settings FLAGS.test=-dv here, since that is closer to the test code.
452 FLAGS.cond-func-make= via-cmdline
453 FLAGS.directive-ifmake= first second
454 FLAGS.doterror= # none, especially not -k
455 FLAGS.jobs-error-indirect= # none, especially not -k
456 FLAGS.jobs-error-nested= # none, especially not -k
457 FLAGS.jobs-error-nested-make= # none, especially not -k
458 FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmdline-plain'
459
460 # Some tests need extra postprocessing.
461 SED_CMDS.dir= ${:D remove output from -DCLEANUP mode }
462 SED_CMDS.dir+= -e '/^OpenDirs_Done:/d'
463 SED_CMDS.dir+= -e '/^CachedDir /d'
464 SED_CMDS.export= -e '/^[^=_A-Za-z0-9]*=/d'
465 SED_CMDS.export-all= ${SED_CMDS.export}
466 SED_CMDS.export-env= ${SED_CMDS.export}
467 SED_CMDS.job-output-long-lines= \
468 ${:D Job separators on their own line are ok. } \
469 -e '/^--- job-[ab] ---$$/d' \
470 ${:D Plain output lines are ok as well. } \
471 ${:D They may come in multiples of 1024 or as 10000. } \
472 -e '/^aa*$$/d' \
473 -e '/^bb*$$/d' \
474 ${:D The following lines should rather not occur since the job } \
475 ${:D marker should always be at the beginning of the line. } \
476 -e '/^aa*--- job-b ---$$/d' \
477 -e '/^bb*--- job-a ---$$/d'
478 SED_CMDS.objdir-writable= -e 's,${RO_OBJDIR},OBJDIR/roobj,g'
479 SED_CMDS.opt-debug-graph1= ${STD_SED_CMDS.dg1}
480 SED_CMDS.opt-debug-jobs= -e 's,([0-9][0-9]*),(<pid>),'
481 SED_CMDS.opt-debug-jobs+= -e 's,pid [0-9][0-9]*,pid <pid>,'
482 SED_CMDS.opt-debug-jobs+= -e 's,Process [0-9][0-9]*,Process <pid>,'
483 SED_CMDS.opt-debug-jobs+= -e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,'
484 SED_CMDS.opt-debug-jobs+= -e 's,Command: ${.SHELL:T},Command: <shell>,'
485 # The "-q" may be there or not, see jobs.c, variable shells.
486 SED_CMDS.opt-debug-jobs+= -e 's,^\(.Command: <shell>\) -q,\1,'
487 SED_CMDS.opt-jobs-no-action= ${STD_SED_CMDS.hide-from-output}
488 SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output}
489 # For Compat_RunCommand, useShell == FALSE.
490 SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<not found: ...>,'
491 # For Compat_RunCommand, useShell == TRUE.
492 SED_CMDS.sh-dots+= -e 's,^make: exec(\(.*\)) failed (.*)$$,<not found: \1>,'
493 SED_CMDS.sh-dots+= -e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,'
494 SED_CMDS.sh-errctl= ${STD_SED_CMDS.dj}
495 SED_CMDS.sh-flags= ${STD_SED_CMDS.hide-from-output}
496 SED_CMDS.suff-main+= ${STD_SED_CMDS.dg1}
497 SED_CMDS.suff-main-several+= ${STD_SED_CMDS.dg1}
498 SED_CMDS.suff-transform-debug+= ${STD_SED_CMDS.dg1}
499 SED_CMDS.var-op-shell+= \
500 -e 's,^${.SHELL:T}: [ 0-9:]*,,' \
501 -e '/command/s,No such.*,not found,'
502 SED_CMDS.vardebug+= -e 's,${.SHELL},</path/to/shell>,'
503 SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,'
504 SED_CMDS.varmod-gmtime+= -e 's,Tue Jan 19 03:14:08 2038,<normalized>,'
505 SED_CMDS.varmod-gmtime+= ${:D FreeBSD i386 still has 32-bit time_t. }
506 SED_CMDS.varmod-gmtime+= -e 's,Fri Dec 13 20:45:52 1901,<normalized>,'
507 SED_CMDS.varmod-localtime+= -e 's,Tue Jan 19 04:14:08 2038,<normalized>,'
508 SED_CMDS.varmod-localtime+= ${:D FreeBSD i386 still has 32-bit time_t. }
509 SED_CMDS.varmod-localtime+= -e 's,Fri Dec 13 21:45:52 1901,<normalized>,'
510 SED_CMDS.varmod-subst-regex+= \
511 -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
512 SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
513 SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
514 SED_CMDS.varname-dot-shell= -e 's, = /[^ ]*, = (details omitted),g'
515 SED_CMDS.varname-dot-shell+= -e 's,"/[^" ]*","(details omitted)",g'
516 SED_CMDS.varname-dot-shell+= -e 's,\[/[^] ]*\],[(details omitted)],g'
517
518 # Some tests need an additional round of postprocessing.
519 POSTPROC.deptgt-suffixes= awk '/^\#\*\*\* Suffixes/,/^never-stop/'
520 POSTPROC.gnode-submake= awk '/Input graph/, /^$$/'
521 POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'
522
523 # Some tests reuse other tests, which makes them unnecessarily fragile.
524 export-all.rawout: export.mk
525 unexport.rawout: export.mk
526 unexport-env.rawout: export.mk
527
528 # End of the configuration section.
529
530 # Some standard sed commands, to be used in the SED_CMDS above.
531
532 # Omit details such as process IDs from the output of the -dg1 option.
533 STD_SED_CMDS.dg1= -e 's,${.CURDIR}$$,<curdir>,'
534 STD_SED_CMDS.dg1+= -e 's, ${DEFSYSPATH:U/usr/share/mk}$$, <defsyspath>,'
535 STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,'
536 STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,'
537 STD_SED_CMDS.dg1+= -e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,'
538 STD_SED_CMDS.dg1+= -e 's,^\(MAKE *=\) .*,\1 <details omitted>,'
539
540 # Omit details such as process IDs from the output of the -dj option.
541 STD_SED_CMDS.dj= \
542 -e '/Process/d;/JobFinish:/d' \
543 -e 's,^\(Job_TokenWithdraw\)([0-9]*),\1(<pid>),' \
544 -e 's,^([0-9][0-9]*) \(withdrew token\),(<pid>) \1,' \
545 -e 's, \(pid\) [0-9][0-9]*, \1 <pid>,' \
546 -e 's,^\( Command:\) .*,\1 <shell>,'
547
548 # Reduce the noise for tests running with the -n option, since there is no
549 # other way to suppress the echoing of the commands.
550 STD_SED_CMDS.hide-from-output= \
551 -e '/^echo hide-from-output/d' \
552 -e 's,hide-from-output ,,' \
553 -e 's,hide-from-output,,'
554
555 # End of the configuration helpers section.
556
557 .MAIN: all
558
559 UNIT_TESTS:= ${.PARSEDIR}
560 .PATH: ${UNIT_TESTS}
561
562 .if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes
563 OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@}
564 .else
565 OUTFILES= ${TESTS:=.out}
566 .endif
567
568 all: ${OUTFILES}
569
570 CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp
571 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
572 CLEANFILES+= issue* .[ab]* # suffixes.mk
573 CLEANDIRS= dir dummy # posix1.mk
574
575 clean:
576 rm -f ${CLEANFILES}
577 rm -rf ${CLEANDIRS}
578
579 TEST_MAKE?= ${.MAKE}
580 TOOL_SED?= sed
581
582 # ensure consistent results from sort(1)
583 LC_ALL= C
584 LANG= C
585 .export LANG LC_ALL
586
587 MAKE_TEST_ENV?= MALLOC_OPTIONS="JA" # for jemalloc
588
589 .if ${.MAKE.OS:U${uname -s:L:sh}} == "NetBSD"
590 LIMIT_RESOURCES?= ulimit -v 200000
591 .endif
592 LIMIT_RESOURCES?= :
593
594 # Each test is run in a sub-make, to keep the tests for interfering with
595 # each other, and because they use different environment variables and
596 # command line options.
597 .SUFFIXES: .mk .rawout .out
598 .mk.rawout:
599 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX}
600 @set -eu; \
601 ${LIMIT_RESOURCES}; \
602 cd ${.OBJDIR}; \
603 env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \
604 ${TEST_MAKE} \
605 -r -C ${.CURDIR} -f ${.IMPSRC} \
606 ${FLAGS.${.PREFIX:T}:U-k} \
607 > ${.TARGET}.tmp 2>&1 \
608 && status=$$? || status=$$?; \
609 echo $$status > ${.TARGET:R}.status
610 @mv ${.TARGET}.tmp ${.TARGET}
611
612 # Postprocess the test output so that the results can be compared.
613 #
614 # always pretend .MAKE was called 'make'
615 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
616 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
617 _SED_CMDS+= -e 's,${TEST_MAKE:T:S,.,\\.,g}[][0-9]* warning,make warning,'
618 _SED_CMDS+= -e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,'
619 # replace anything after 'stopped in' with unit-tests
620 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
621 # strip ${.CURDIR}/ from the output
622 _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
623 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
624
625 .rawout.out:
626 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \
627 < ${.IMPSRC} > ${.TARGET}.tmp1
628 @${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
629 @rm ${.TARGET}.tmp1
630 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
631 @mv ${.TARGET}.tmp2 ${.TARGET}
632
633 # Compare all output files
634 test: ${OUTFILES} .PHONY
635 @failed= ; \
636 for test in ${TESTS}; do \
637 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
638 || failed="$${failed}$${failed:+ }$${test}" ; \
639 done ; \
640 if [ -n "$${failed}" ]; then \
641 echo "Failed tests: $${failed}" ; false ; \
642 else \
643 echo "All tests passed" ; \
644 fi
645
646 accept:
647 @for test in ${TESTS}; do \
648 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
649 || { echo "Replacing $${test}.exp" ; \
650 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
651 done
652
653 # Note: only works for adding tests.
654 # To remove a test, the $$mi file must be edited manually.
655 sync-mi:
656 @set -eu; \
657 cd "${MAKEFILE:tA:H}/../../.."; \
658 mi="distrib/sets/lists/tests/mi"; \
659 cvs update "$$mi"; \
660 testsdir="usr.bin/make/unit-tests"; \
661 fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
662 cat "$$mi" > "$$mi.tmp"; \
663 (cd "$$testsdir" && ls *.exp *.mk) | xargs printf "$$fmt" >> "$$mi.tmp"; \
664 distrib/sets/fmt-list "$$mi.tmp"; \
665 mv "$$mi.tmp" "$$mi"; \
666 cvs diff "$$mi" || true
667
668 .if exists(${TEST_MAKE})
669 ${TESTS:=.rawout}: ${TEST_MAKE}
670 # in meta mode, we *know* if a target script is impacted
671 # by a makefile change.
672 .if ${.MAKE.MODE:Unormal:Mmeta} == ""
673 ${TESTS:=.rawout}: ${.PARSEDIR}/Makefile
674 .endif
675 .endif
676
677 .-include <bsd.obj.mk>
678