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