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