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