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