Makefile revision 1.258 1 # $NetBSD: Makefile,v 1.258 2020/12/29 01:45:06 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 these below but we might be an older make
35 .MAKE.OS?= ${uname -s:L:sh}
36 .MAKE.UID?= ${id -u:L:sh}
37
38 # Each test is in a sub-makefile.
39 # Keep the list sorted.
40 # Any test that is commented out must be ignored in
41 # src/tests/usr.bin/make/t_make.sh as well.
42 TESTS+= archive
43 TESTS+= archive-suffix
44 TESTS+= cmd-errors
45 TESTS+= cmd-errors-jobs
46 TESTS+= cmd-errors-lint
47 TESTS+= cmd-interrupt
48 TESTS+= cmdline
49 TESTS+= cmdline-undefined
50 TESTS+= comment
51 TESTS+= compat-error
52 TESTS+= cond-cmp-numeric
53 TESTS+= cond-cmp-numeric-eq
54 TESTS+= cond-cmp-numeric-ge
55 TESTS+= cond-cmp-numeric-gt
56 TESTS+= cond-cmp-numeric-le
57 TESTS+= cond-cmp-numeric-lt
58 TESTS+= cond-cmp-numeric-ne
59 TESTS+= cond-cmp-string
60 TESTS+= cond-cmp-unary
61 TESTS+= cond-eof
62 TESTS+= cond-func
63 TESTS+= cond-func-commands
64 TESTS+= cond-func-defined
65 TESTS+= cond-func-empty
66 TESTS+= cond-func-exists
67 TESTS+= cond-func-make
68 TESTS+= cond-func-make-main
69 TESTS+= cond-func-target
70 TESTS+= cond-late
71 TESTS+= cond-op
72 TESTS+= cond-op-and
73 TESTS+= cond-op-and-lint
74 TESTS+= cond-op-not
75 TESTS+= cond-op-or
76 TESTS+= cond-op-or-lint
77 TESTS+= cond-op-parentheses
78 TESTS+= cond-short
79 TESTS+= cond-token-number
80 TESTS+= cond-token-plain
81 TESTS+= cond-token-string
82 TESTS+= cond-token-var
83 TESTS+= cond-undef-lint
84 TESTS+= cond1
85 TESTS+= counter
86 TESTS+= counter-append
87 TESTS+= dep
88 TESTS+= dep-colon
89 TESTS+= dep-colon-bug-cross-file
90 TESTS+= dep-double-colon
91 TESTS+= dep-double-colon-indep
92 TESTS+= dep-exclam
93 TESTS+= dep-none
94 TESTS+= dep-percent
95 TESTS+= dep-var
96 TESTS+= dep-wildcards
97 TESTS+= depsrc
98 TESTS+= depsrc-end
99 TESTS+= depsrc-exec
100 TESTS+= depsrc-ignore
101 TESTS+= depsrc-made
102 TESTS+= depsrc-make
103 TESTS+= depsrc-meta
104 TESTS+= depsrc-nometa
105 TESTS+= depsrc-nometa_cmp
106 TESTS+= depsrc-nopath
107 TESTS+= depsrc-notmain
108 TESTS+= depsrc-optional
109 TESTS+= depsrc-phony
110 TESTS+= depsrc-precious
111 TESTS+= depsrc-recursive
112 TESTS+= depsrc-silent
113 TESTS+= depsrc-use
114 TESTS+= depsrc-usebefore
115 TESTS+= depsrc-usebefore-double-colon
116 TESTS+= depsrc-wait
117 TESTS+= deptgt
118 TESTS+= deptgt-begin
119 TESTS+= deptgt-begin-fail
120 TESTS+= deptgt-begin-fail-indirect
121 TESTS+= deptgt-default
122 TESTS+= deptgt-delete_on_error
123 TESTS+= deptgt-end
124 TESTS+= deptgt-end-fail
125 TESTS+= deptgt-end-fail-all
126 TESTS+= deptgt-end-fail-indirect
127 TESTS+= deptgt-end-jobs
128 TESTS+= deptgt-error
129 TESTS+= deptgt-ignore
130 TESTS+= deptgt-interrupt
131 TESTS+= deptgt-main
132 TESTS+= deptgt-makeflags
133 TESTS+= deptgt-no_parallel
134 TESTS+= deptgt-nopath
135 TESTS+= deptgt-notparallel
136 TESTS+= deptgt-objdir
137 TESTS+= deptgt-order
138 TESTS+= deptgt-path
139 TESTS+= deptgt-path-suffix
140 TESTS+= deptgt-phony
141 TESTS+= deptgt-precious
142 TESTS+= deptgt-shell
143 TESTS+= deptgt-silent
144 TESTS+= deptgt-stale
145 TESTS+= deptgt-suffixes
146 TESTS+= dir
147 TESTS+= dir-expand-path
148 TESTS+= directive
149 TESTS+= directive-dinclude
150 TESTS+= directive-elif
151 TESTS+= directive-elifdef
152 TESTS+= directive-elifmake
153 TESTS+= directive-elifndef
154 TESTS+= directive-elifnmake
155 TESTS+= directive-else
156 TESTS+= directive-endif
157 TESTS+= directive-error
158 TESTS+= directive-export
159 TESTS+= directive-export-env
160 TESTS+= directive-export-impl
161 TESTS+= directive-export-gmake
162 TESTS+= directive-export-literal
163 TESTS+= directive-for
164 TESTS+= directive-for-generating-endif
165 TESTS+= directive-for-lines
166 TESTS+= directive-for-null
167 TESTS+= directive-hyphen-include
168 TESTS+= directive-if
169 TESTS+= directive-if-nested
170 TESTS+= directive-ifdef
171 TESTS+= directive-ifmake
172 TESTS+= directive-ifndef
173 TESTS+= directive-ifnmake
174 TESTS+= directive-include
175 TESTS+= directive-include-fatal
176 TESTS+= directive-info
177 TESTS+= directive-misspellings
178 TESTS+= directive-sinclude
179 TESTS+= directive-undef
180 TESTS+= directive-unexport
181 TESTS+= directive-unexport-env
182 TESTS+= directive-warning
183 TESTS+= dollar
184 TESTS+= doterror
185 TESTS+= dotwait
186 TESTS+= envfirst
187 TESTS+= error
188 TESTS+= # escape # broken by reverting POSIX changes
189 TESTS+= export
190 TESTS+= export-all
191 TESTS+= export-env
192 TESTS+= export-variants
193 TESTS+= forloop
194 TESTS+= forsubst
195 TESTS+= gnode-submake
196 TESTS+= hanoi-include
197 TESTS+= impsrc
198 TESTS+= include-main
199 TESTS+= job-flags
200 TESTS+= job-output-long-lines
201 TESTS+= jobs-error-indirect
202 TESTS+= jobs-error-nested
203 TESTS+= jobs-error-nested-make
204 TESTS+= lint
205 TESTS+= make-exported
206 TESTS+= meta-cmd-cmp
207 TESTS+= moderrs
208 TESTS+= modmatch
209 TESTS+= modmisc
210 TESTS+= modts
211 TESTS+= modword
212 .if ${.MAKE.UID} > 0
213 TESTS+= objdir-writable
214 .endif
215 TESTS+= opt
216 TESTS+= opt-backwards
217 TESTS+= opt-chdir
218 TESTS+= opt-debug
219 TESTS+= opt-debug-all
220 TESTS+= opt-debug-archive
221 TESTS+= opt-debug-curdir
222 TESTS+= opt-debug-cond
223 TESTS+= opt-debug-dir
224 TESTS+= opt-debug-errors
225 TESTS+= opt-debug-file
226 TESTS+= opt-debug-for
227 TESTS+= opt-debug-graph1
228 TESTS+= opt-debug-graph2
229 TESTS+= opt-debug-graph3
230 TESTS+= opt-debug-hash
231 TESTS+= opt-debug-jobs
232 TESTS+= opt-debug-lint
233 TESTS+= opt-debug-loud
234 TESTS+= opt-debug-meta
235 TESTS+= opt-debug-making
236 TESTS+= opt-debug-no-rm
237 TESTS+= opt-debug-parse
238 TESTS+= opt-debug-suff
239 TESTS+= opt-debug-targets
240 TESTS+= opt-debug-varraw
241 TESTS+= opt-debug-var
242 TESTS+= opt-debug-x-trace
243 TESTS+= opt-define
244 TESTS+= opt-env
245 TESTS+= opt-file
246 TESTS+= opt-ignore
247 TESTS+= opt-include-dir
248 TESTS+= opt-jobs
249 TESTS+= opt-jobs-internal
250 TESTS+= opt-jobs-no-action
251 TESTS+= opt-keep-going
252 TESTS+= opt-keep-going-multiple
253 TESTS+= opt-m-include-dir
254 TESTS+= opt-no-action
255 TESTS+= opt-no-action-at-all
256 TESTS+= opt-no-action-runflags
257 TESTS+= opt-query
258 TESTS+= opt-raw
259 TESTS+= opt-silent
260 TESTS+= opt-touch
261 TESTS+= opt-touch-jobs
262 TESTS+= opt-tracefile
263 TESTS+= opt-var-expanded
264 TESTS+= opt-var-literal
265 TESTS+= opt-warnings-as-errors
266 TESTS+= opt-where-am-i
267 TESTS+= opt-x-reduce-exported
268 TESTS+= order
269 TESTS+= parse-var
270 TESTS+= phony-end
271 TESTS+= posix
272 TESTS+= # posix1 # broken by reverting POSIX changes
273 TESTS+= recursive
274 TESTS+= sh
275 TESTS+= sh-dots
276 TESTS+= sh-errctl
277 TESTS+= sh-flags
278 TESTS+= sh-jobs
279 TESTS+= sh-jobs-error
280 TESTS+= sh-leading-at
281 TESTS+= sh-leading-hyphen
282 TESTS+= sh-leading-plus
283 TESTS+= sh-meta-chars
284 TESTS+= sh-multi-line
285 TESTS+= sh-single-line
286 TESTS+= shell-csh
287 TESTS+= shell-custom
288 TESTS+= shell-ksh
289 TESTS+= shell-sh
290 TESTS+= suff-add-later
291 TESTS+= suff-clear-regular
292 TESTS+= suff-clear-single
293 TESTS+= suff-incomplete
294 TESTS+= suff-lookup
295 TESTS+= suff-main
296 TESTS+= suff-main-several
297 TESTS+= suff-phony
298 TESTS+= suff-rebuild
299 TESTS+= suff-self
300 TESTS+= suff-transform-debug
301 TESTS+= suff-transform-endless
302 TESTS+= suff-transform-expand
303 TESTS+= suff-transform-select
304 TESTS+= sunshcmd
305 TESTS+= ternary
306 TESTS+= unexport
307 TESTS+= unexport-env
308 TESTS+= use-inference
309 TESTS+= var-class
310 TESTS+= var-class-cmdline
311 TESTS+= var-class-env
312 TESTS+= var-class-global
313 TESTS+= var-class-local
314 TESTS+= var-class-local-legacy
315 TESTS+= var-op
316 TESTS+= var-op-append
317 TESTS+= var-op-assign
318 TESTS+= var-op-default
319 TESTS+= var-op-expand
320 TESTS+= var-op-shell
321 TESTS+= var-op-sunsh
322 TESTS+= var-recursive
323 TESTS+= varcmd
324 TESTS+= vardebug
325 TESTS+= varfind
326 TESTS+= varmisc
327 TESTS+= varmod
328 TESTS+= varmod-assign
329 TESTS+= varmod-defined
330 TESTS+= varmod-edge
331 TESTS+= varmod-exclam-shell
332 TESTS+= varmod-extension
333 TESTS+= varmod-gmtime
334 TESTS+= varmod-hash
335 TESTS+= varmod-head
336 TESTS+= varmod-ifelse
337 TESTS+= varmod-indirect
338 TESTS+= varmod-l-name-to-value
339 TESTS+= varmod-localtime
340 TESTS+= varmod-loop
341 TESTS+= varmod-match
342 TESTS+= varmod-match-escape
343 TESTS+= varmod-no-match
344 TESTS+= varmod-order
345 TESTS+= varmod-order-reverse
346 TESTS+= varmod-order-shuffle
347 TESTS+= varmod-path
348 TESTS+= varmod-quote
349 TESTS+= varmod-quote-dollar
350 TESTS+= varmod-range
351 TESTS+= varmod-remember
352 TESTS+= varmod-root
353 TESTS+= varmod-select-words
354 TESTS+= varmod-shell
355 TESTS+= varmod-subst
356 TESTS+= varmod-subst-regex
357 TESTS+= varmod-sysv
358 TESTS+= varmod-tail
359 TESTS+= varmod-to-abs
360 TESTS+= varmod-to-lower
361 TESTS+= varmod-to-many-words
362 TESTS+= varmod-to-one-word
363 TESTS+= varmod-to-separator
364 TESTS+= varmod-to-upper
365 TESTS+= varmod-undefined
366 TESTS+= varmod-unique
367 TESTS+= varname
368 TESTS+= varname-dollar
369 TESTS+= varname-dot-alltargets
370 TESTS+= varname-dot-curdir
371 TESTS+= varname-dot-includes
372 TESTS+= varname-dot-includedfromdir
373 TESTS+= varname-dot-includedfromfile
374 TESTS+= varname-dot-libs
375 TESTS+= varname-dot-make-dependfile
376 TESTS+= varname-dot-make-expand_variables
377 TESTS+= varname-dot-make-exported
378 TESTS+= varname-dot-make-jobs
379 TESTS+= varname-dot-make-jobs-prefix
380 TESTS+= varname-dot-make-level
381 TESTS+= varname-dot-make-makefile_preference
382 TESTS+= varname-dot-make-makefiles
383 TESTS+= varname-dot-make-meta-bailiwick
384 TESTS+= varname-dot-make-meta-created
385 TESTS+= varname-dot-make-meta-files
386 TESTS+= varname-dot-make-meta-ignore_filter
387 TESTS+= varname-dot-make-meta-ignore_paths
388 TESTS+= varname-dot-make-meta-ignore_patterns
389 TESTS+= varname-dot-make-meta-prefix
390 TESTS+= varname-dot-make-mode
391 TESTS+= varname-dot-make-path_filemon
392 TESTS+= varname-dot-make-pid
393 TESTS+= varname-dot-make-ppid
394 TESTS+= varname-dot-make-save_dollars
395 TESTS+= varname-dot-makeflags
396 TESTS+= varname-dot-makeoverrides
397 TESTS+= varname-dot-newline
398 TESTS+= varname-dot-objdir
399 TESTS+= varname-dot-parsedir
400 TESTS+= varname-dot-parsefile
401 TESTS+= varname-dot-path
402 TESTS+= varname-dot-shell
403 TESTS+= varname-dot-targets
404 TESTS+= varname-empty
405 TESTS+= varname-make
406 TESTS+= varname-make_print_var_on_error
407 TESTS+= varname-make_print_var_on_error-jobs
408 TESTS+= varname-makefile
409 TESTS+= varname-makeflags
410 TESTS+= varname-pwd
411 TESTS+= varname-vpath
412 TESTS+= varparse-dynamic
413 TESTS+= varparse-errors
414 TESTS+= varparse-mod
415 TESTS+= varparse-undef-partial
416 TESTS+= varquote
417
418 # Ideas for more tests:
419 # char-0020-space.mk
420 # char-005C-backslash.mk
421 # escape-cond-str.mk
422 # escape-cond-func-arg.mk
423 # escape-cond-func-arg.mk
424 # escape-varmod.mk
425 # escape-varmod-define.mk
426 # escape-varmod-match.mk
427 # escape-varname.mk
428 # escape-varassign-varname.mk
429 # escape-varassign-varname-cmdline.mk
430 # escape-varassign-value.mk
431 # escape-varassign-value-cmdline.mk
432 # escape-dependency-source.mk
433 # escape-dependency-target.mk
434 # escape-for-varname.mk
435 # escape-for-item.mk
436 # posix-*.mk (see posix.mk and posix1.mk)
437
438 .if ${.OBJDIR} != ${.CURDIR}
439 RO_OBJDIR:= ${.OBJDIR}/roobj
440 .else
441 RO_OBJDIR:= ${TMPDIR:U/tmp}/roobj
442 .endif
443 # Additional environment variables for some of the tests.
444 # The base environment is -i PATH="$PATH".
445 ENV.depsrc-optional+= TZ=UTC
446 ENV.envfirst= FROM_ENV=value-from-env
447 ENV.objdir-writable+= RO_OBJDIR=${RO_OBJDIR}
448 ENV.varmisc= FROM_ENV=env
449 ENV.varmisc+= FROM_ENV_BEFORE=env
450 ENV.varmisc+= FROM_ENV_AFTER=env
451 ENV.varmod-localtime+= TZ=Europe/Berlin
452 ENV.varname-vpath+= VPATH=varname-vpath.dir:varname-vpath.dir2
453
454 # Override make flags for some of the tests; default is -k.
455 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
456 # settings FLAGS.test=-dv here, since that is closer to the test code.
457 FLAGS.cond-func-make= via-cmdline
458 FLAGS.directive-ifmake= first second
459 FLAGS.doterror= # none, especially not -k
460 FLAGS.jobs-error-indirect= # none, especially not -k
461 FLAGS.jobs-error-nested= # none, especially not -k
462 FLAGS.jobs-error-nested-make= # none, especially not -k
463 FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmdline-plain'
464
465 # Some tests need extra postprocessing.
466 SED_CMDS.dir= ${:D remove output from -DCLEANUP mode }
467 SED_CMDS.dir+= -e '/^OpenDirs_Done:/d'
468 SED_CMDS.dir+= -e '/^CachedDir /d'
469 SED_CMDS.export= -e '/^[^=_A-Za-z0-9]*=/d'
470 SED_CMDS.export-all= ${SED_CMDS.export}
471 SED_CMDS.export-env= ${SED_CMDS.export}
472 SED_CMDS.job-output-long-lines= \
473 ${:D Job separators on their own line are ok. } \
474 -e '/^--- job-[ab] ---$$/d' \
475 ${:D Plain output lines are ok as well. } \
476 ${:D They may come in multiples of 1024 or as 10000. } \
477 -e '/^aa*$$/d' \
478 -e '/^bb*$$/d' \
479 ${:D The following lines should rather not occur since the job } \
480 ${:D marker should always be at the beginning of the line. } \
481 -e '/^aa*--- job-b ---$$/d' \
482 -e '/^bb*--- job-a ---$$/d'
483 SED_CMDS.objdir-writable= -e 's,${RO_OBJDIR},OBJDIR/roobj,g'
484 SED_CMDS.opt-debug-graph1= ${STD_SED_CMDS.dg1}
485 SED_CMDS.opt-debug-jobs= -e 's,([0-9][0-9]*),(<pid>),'
486 SED_CMDS.opt-debug-jobs+= -e 's,pid [0-9][0-9]*,pid <pid>,'
487 SED_CMDS.opt-debug-jobs+= -e 's,Process [0-9][0-9]*,Process <pid>,'
488 SED_CMDS.opt-debug-jobs+= -e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,'
489 SED_CMDS.opt-debug-jobs+= -e 's,Command: ${.SHELL:T},Command: <shell>,'
490 # The "-q" may be there or not, see jobs.c, variable shells.
491 SED_CMDS.opt-debug-jobs+= -e 's,^\(.Command: <shell>\) -q,\1,'
492 SED_CMDS.opt-jobs-no-action= ${STD_SED_CMDS.hide-from-output}
493 SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output}
494 # For Compat_RunCommand, useShell == FALSE.
495 SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<not found: ...>,'
496 # For Compat_RunCommand, useShell == TRUE.
497 SED_CMDS.sh-dots+= -e 's,^make: exec(\(.*\)) failed (.*)$$,<not found: \1>,'
498 SED_CMDS.sh-dots+= -e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,'
499 SED_CMDS.sh-errctl= ${STD_SED_CMDS.dj}
500 SED_CMDS.sh-flags= ${STD_SED_CMDS.hide-from-output}
501 SED_CMDS.suff-main+= ${STD_SED_CMDS.dg1}
502 SED_CMDS.suff-main-several+= ${STD_SED_CMDS.dg1}
503 SED_CMDS.suff-transform-debug+= ${STD_SED_CMDS.dg1}
504 SED_CMDS.var-op-shell+= \
505 -e 's,^${.SHELL:T}: [ 0-9:]*,,' \
506 -e '/command/s,No such.*,not found,'
507 SED_CMDS.vardebug+= -e 's,${.SHELL},</path/to/shell>,'
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} == "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