1 # $NetBSD: Makefile,v 1.384 2026/08/23 08:23:56 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, run "make sync-mi" in this directory. 28 # 29 30 .MAIN: all 31 32 # we use these below but we might be an older make 33 .MAKE.OS?= ${uname -s:L:sh} 34 .MAKE.UID?= ${id -u:L:sh} 35 36 # for many tests we need a TMPDIR that will not collide 37 # with other users. 38 .if ${.OBJDIR} != ${.CURDIR} 39 # easy 40 TMPDIR:= ${.OBJDIR}/tmp 41 .elif defined(TMPDIR) 42 TMPDIR:= ${TMPDIR}/uid${.MAKE.UID} 43 .else 44 TMPDIR:= /tmp/uid${.MAKE.UID} 45 .endif 46 # make sure it exists 47 .if !exist(${TMPDIR}) 48 _!= mkdir -p ${TMPDIR} 49 .endif 50 # and clean it up - outside the context of 51 # any target that might be using it. 52 .END: rm-tmpdir 53 rm-tmpdir: .NOMETA 54 @rm -rf ${TMPDIR} 55 56 # Each test is in a sub-makefile. 57 # Keep the list sorted. 58 # Any test that is commented out must be ignored in 59 # src/tests/usr.bin/make/t_make.sh as well. 60 TESTS+= archive 61 TESTS+= archive-suffix 62 TESTS+= char-005c-reverse-solidus 63 TESTS+= char-000a-new-line 64 TESTS+= cmd-errors 65 TESTS+= cmd-errors-jobs 66 TESTS+= cmd-errors-lint 67 TESTS+= cmd-interrupt 68 TESTS+= cmdline 69 TESTS+= cmdline-redirect-stdin 70 TESTS+= cmdline-undefined 71 TESTS+= comment 72 TESTS+= compat-error 73 TESTS+= cond-cmp-numeric 74 TESTS+= cond-cmp-numeric-eq 75 TESTS+= cond-cmp-numeric-ge 76 TESTS+= cond-cmp-numeric-gt 77 TESTS+= cond-cmp-numeric-le 78 TESTS+= cond-cmp-numeric-lt 79 TESTS+= cond-cmp-numeric-ne 80 TESTS+= cond-cmp-string 81 TESTS+= cond-cmp-unary 82 TESTS+= cond-eof 83 TESTS+= cond-func 84 TESTS+= cond-func-commands 85 TESTS+= cond-func-defined 86 TESTS+= cond-func-empty 87 TESTS+= cond-func-exists 88 TESTS+= cond-func-make 89 TESTS+= cond-func-make-main 90 TESTS+= cond-func-target 91 TESTS+= cond-late 92 TESTS+= cond-op 93 TESTS+= cond-op-and 94 TESTS+= cond-op-and-lint 95 TESTS+= cond-op-not 96 TESTS+= cond-op-or 97 TESTS+= cond-op-or-lint 98 TESTS+= cond-op-parentheses 99 TESTS+= cond-short 100 TESTS+= cond-token-number 101 TESTS+= cond-token-plain 102 TESTS+= cond-token-string 103 TESTS+= cond-token-var 104 TESTS+= cond-undef-lint 105 TESTS+= counter 106 TESTS+= counter-append 107 TESTS+= dep 108 TESTS+= dep-colon 109 TESTS+= dep-colon-bug-cross-file 110 TESTS+= dep-double-colon 111 TESTS+= dep-double-colon-indep 112 TESTS+= dep-duplicate 113 TESTS+= dep-exclam 114 TESTS+= dep-none 115 TESTS+= dep-op-missing 116 TESTS+= dep-percent 117 TESTS+= dep-var 118 TESTS+= dep-wildcards 119 TESTS+= depsrc 120 TESTS+= depsrc-end 121 TESTS+= depsrc-exec 122 TESTS+= depsrc-ignore 123 TESTS+= depsrc-made 124 TESTS+= depsrc-make 125 TESTS+= depsrc-meta 126 TESTS+= depsrc-nometa 127 TESTS+= depsrc-nometa_cmp 128 TESTS+= depsrc-nopath 129 TESTS+= depsrc-notmain 130 TESTS+= depsrc-optional 131 TESTS+= depsrc-phony 132 TESTS+= depsrc-precious 133 TESTS+= depsrc-recursive 134 TESTS+= depsrc-silent 135 TESTS+= depsrc-use 136 TESTS+= depsrc-usebefore 137 TESTS+= depsrc-usebefore-double-colon 138 TESTS+= depsrc-wait 139 TESTS+= deptgt 140 TESTS+= deptgt-begin 141 TESTS+= deptgt-begin-fail 142 TESTS+= deptgt-begin-fail-indirect 143 TESTS+= deptgt-default 144 TESTS+= deptgt-delete_on_error 145 TESTS+= deptgt-end 146 TESTS+= deptgt-end-fail 147 TESTS+= deptgt-end-fail-all 148 TESTS+= deptgt-end-fail-indirect 149 TESTS+= deptgt-end-jobs 150 TESTS+= deptgt-error 151 TESTS+= deptgt-ignore 152 TESTS+= deptgt-interrupt 153 TESTS+= deptgt-main 154 TESTS+= deptgt-makeflags 155 TESTS+= deptgt-no_parallel 156 TESTS+= deptgt-nopath 157 TESTS+= deptgt-notparallel 158 TESTS+= deptgt-objdir 159 TESTS+= deptgt-order 160 TESTS+= deptgt-path 161 TESTS+= deptgt-path-suffix 162 TESTS+= deptgt-phony 163 TESTS+= deptgt-posix 164 TESTS+= deptgt-precious 165 TESTS+= deptgt-shell 166 TESTS+= deptgt-silent 167 TESTS+= deptgt-silent-jobs 168 TESTS+= deptgt-stale 169 TESTS+= deptgt-suffixes 170 TESTS+= dir 171 TESTS+= dir-expand-path 172 TESTS+= directive 173 TESTS+= directive-dinclude 174 TESTS+= directive-elif 175 TESTS+= directive-elifdef 176 TESTS+= directive-elifmake 177 TESTS+= directive-elifndef 178 TESTS+= directive-elifnmake 179 TESTS+= directive-else 180 TESTS+= directive-endfor 181 TESTS+= directive-endif 182 TESTS+= directive-error 183 TESTS+= directive-export 184 TESTS+= directive-export-env 185 TESTS+= directive-export-impl 186 TESTS+= directive-export-gmake 187 TESTS+= directive-export-literal 188 TESTS+= directive-for 189 TESTS+= directive-for-break 190 TESTS+= directive-for-empty 191 TESTS+= directive-for-errors 192 TESTS+= directive-for-escape 193 TESTS+= directive-for-generating-endif 194 TESTS+= directive-for-if 195 TESTS+= directive-for-lines 196 TESTS+= directive-for-null 197 TESTS+= directive-hyphen-include 198 TESTS+= directive-if 199 TESTS+= directive-if-nested 200 TESTS+= directive-ifdef 201 TESTS+= directive-ifmake 202 TESTS+= directive-ifndef 203 TESTS+= directive-ifnmake 204 TESTS+= directive-include 205 TESTS+= directive-include-fatal 206 TESTS+= directive-include-guard 207 TESTS+= directive-info 208 TESTS+= directive-misspellings 209 TESTS+= directive-sinclude 210 TESTS+= directive-undef 211 TESTS+= directive-unexport 212 TESTS+= directive-unexport-env 213 TESTS+= directive-warning 214 TESTS+= dollar 215 TESTS+= doterror 216 TESTS+= dotwait 217 TESTS+= error 218 TESTS+= # escape # broken by reverting POSIX changes 219 TESTS+= export 220 TESTS+= export-all 221 TESTS+= export-env 222 TESTS+= export-variants 223 TESTS+= gnode-submake 224 TESTS+= hanoi-include 225 TESTS+= impsrc 226 TESTS+= include-main 227 TESTS+= job-flags 228 TESTS+= job-output 229 TESTS+= job-output-long-lines 230 TESTS+= job-output-null 231 TESTS+= jobs-empty-commands 232 TESTS+= jobs-empty-commands-error 233 TESTS+= jobs-error-indirect 234 TESTS+= jobs-error-nested 235 TESTS+= jobs-error-nested-make 236 TESTS+= lint 237 TESTS+= make-exported 238 TESTS+= meta-cmd-cmp 239 TESTS+= meta-output 240 TESTS+= moderrs 241 TESTS+= modmisc 242 .if ${.MAKE.UID} > 0 243 TESTS+= objdir-writable 244 .endif 245 TESTS+= opt 246 TESTS+= opt-backwards 247 TESTS+= opt-chdir 248 TESTS+= opt-debug 249 TESTS+= opt-debug-all 250 TESTS+= opt-debug-archive 251 TESTS+= opt-debug-curdir 252 TESTS+= opt-debug-cond 253 TESTS+= opt-debug-dir 254 TESTS+= opt-debug-errors 255 TESTS+= opt-debug-errors-jobs 256 TESTS+= opt-debug-file 257 TESTS+= opt-debug-for 258 TESTS+= opt-debug-graph1 259 TESTS+= opt-debug-graph2 260 TESTS+= opt-debug-graph3 261 TESTS+= opt-debug-hash 262 TESTS+= opt-debug-jobs 263 TESTS+= opt-debug-lint 264 TESTS+= opt-debug-loud 265 TESTS+= opt-debug-meta 266 TESTS+= opt-debug-making 267 TESTS+= opt-debug-no-rm 268 TESTS+= opt-debug-parse 269 TESTS+= opt-debug-suff 270 TESTS+= opt-debug-targets 271 TESTS+= opt-debug-varraw 272 TESTS+= opt-debug-var 273 TESTS+= opt-debug-x-trace 274 TESTS+= opt-define 275 TESTS+= opt-env 276 TESTS+= opt-file 277 TESTS+= opt-ignore 278 TESTS+= opt-include-dir 279 TESTS+= opt-jobs 280 TESTS+= opt-jobs-internal 281 TESTS+= opt-jobs-no-action 282 TESTS+= opt-keep-going 283 TESTS+= opt-keep-going-indirect 284 TESTS+= opt-keep-going-multiple 285 TESTS+= opt-m-include-dir 286 TESTS+= opt-no-action 287 TESTS+= opt-no-action-at-all 288 TESTS+= opt-no-action-runflags 289 TESTS+= opt-no-action-touch 290 TESTS+= opt-query 291 TESTS+= opt-raw 292 TESTS+= opt-silent 293 TESTS+= opt-touch 294 TESTS+= opt-touch-jobs 295 TESTS+= opt-tracefile 296 TESTS+= opt-var-expanded 297 TESTS+= opt-var-literal 298 TESTS+= opt-version 299 TESTS+= opt-warnings-as-errors 300 TESTS+= opt-where-am-i 301 TESTS+= opt-x-reduce-exported 302 TESTS+= order 303 TESTS+= parse 304 TESTS+= parse-var 305 TESTS+= phony-end 306 TESTS+= posix 307 TESTS+= posix-execution 308 TESTS+= posix-expansion 309 TESTS+= posix-varassign 310 TESTS+= # posix1 # broken by reverting POSIX changes 311 TESTS+= recursive 312 TESTS+= sh 313 TESTS+= sh-dots 314 TESTS+= sh-errctl 315 TESTS+= sh-flags 316 TESTS+= sh-jobs 317 TESTS+= sh-jobs-error 318 TESTS+= sh-leading-at 319 TESTS+= sh-leading-hyphen 320 TESTS+= sh-leading-plus 321 TESTS+= sh-meta-chars 322 TESTS+= sh-multi-line 323 TESTS+= sh-single-line 324 TESTS+= shell-csh 325 TESTS+= shell-custom 326 TESTS+= shell-ksh 327 TESTS+= shell-sh 328 TESTS+= suff 329 TESTS+= suff-add-later 330 TESTS+= suff-clear-regular 331 TESTS+= suff-clear-single 332 TESTS+= suff-incomplete 333 TESTS+= suff-lookup 334 TESTS+= suff-main 335 TESTS+= suff-main-several 336 TESTS+= suff-phony 337 TESTS+= suff-rebuild 338 TESTS+= suff-self 339 TESTS+= suff-transform-debug 340 TESTS+= suff-transform-endless 341 TESTS+= suff-transform-expand 342 TESTS+= suff-transform-select 343 TESTS+= suff-use 344 TESTS+= sunshcmd 345 TESTS+= ternary 346 TESTS+= unexport 347 TESTS+= unexport-env 348 TESTS+= use-inference 349 TESTS+= var-readonly 350 TESTS+= var-scope 351 TESTS+= var-scope-cmdline 352 TESTS+= var-scope-env 353 TESTS+= var-scope-global 354 TESTS+= var-scope-local 355 TESTS+= var-scope-local-legacy 356 TESTS+= var-eval-short 357 TESTS+= var-op 358 TESTS+= var-op-append 359 TESTS+= var-op-assign 360 TESTS+= var-op-default 361 TESTS+= var-op-expand 362 TESTS+= var-op-shell 363 TESTS+= var-op-sunsh 364 TESTS+= var-recursive 365 TESTS+= varcmd 366 TESTS+= vardebug 367 TESTS+= varfind 368 TESTS+= varmisc 369 TESTS+= varmod 370 TESTS+= varmod-assign 371 TESTS+= varmod-assign-shell 372 TESTS+= varmod-defined 373 TESTS+= varmod-edge 374 TESTS+= varmod-exclam-shell 375 TESTS+= varmod-extension 376 TESTS+= varmod-gmtime 377 TESTS+= varmod-hash 378 TESTS+= varmod-head 379 TESTS+= varmod-ifelse 380 TESTS+= varmod-indirect 381 TESTS+= varmod-l-name-to-value 382 TESTS+= varmod-localtime 383 TESTS+= varmod-loop 384 TESTS+= varmod-loop-delete 385 TESTS+= varmod-loop-varname 386 TESTS+= varmod-match 387 TESTS+= varmod-match-escape 388 TESTS+= varmod-mtime 389 TESTS+= varmod-no-match 390 TESTS+= varmod-order 391 TESTS+= varmod-order-numeric 392 TESTS+= varmod-order-reverse 393 TESTS+= varmod-order-shuffle 394 TESTS+= varmod-order-string 395 TESTS+= varmod-path 396 TESTS+= varmod-quote 397 TESTS+= varmod-quote-dollar 398 TESTS+= varmod-range 399 TESTS+= varmod-remember 400 TESTS+= varmod-root 401 TESTS+= varmod-select-words 402 TESTS+= varmod-shell 403 TESTS+= varmod-subst 404 TESTS+= varmod-subst-regex 405 TESTS+= varmod-sun-shell 406 TESTS+= varmod-sun-shell1 407 TESTS+= varmod-sysv 408 TESTS+= varmod-tail 409 TESTS+= varmod-to-abs 410 TESTS+= varmod-to-lower 411 TESTS+= varmod-to-many-words 412 TESTS+= varmod-to-one-word 413 TESTS+= varmod-to-separator 414 TESTS+= varmod-to-title 415 TESTS+= varmod-to-upper 416 TESTS+= varmod-undefined 417 TESTS+= varmod-unique 418 TESTS+= varname 419 TESTS+= varname-circumflex 420 TESTS+= varname-dollar 421 TESTS+= varname-dot-alltargets 422 TESTS+= varname-dot-curdir 423 TESTS+= varname-dot-includes 424 TESTS+= varname-dot-includedfromdir 425 TESTS+= varname-dot-includedfromfile 426 TESTS+= varname-dot-libs 427 TESTS+= varname-dot-make-dependfile 428 TESTS+= varname-dot-make-expand_variables 429 TESTS+= varname-dot-make-exported 430 TESTS+= varname-dot-make-jobs 431 TESTS+= varname-dot-make-jobs-prefix 432 TESTS+= varname-dot-make-level 433 TESTS+= varname-dot-make-makefile_preference 434 TESTS+= varname-dot-make-makefiles 435 TESTS+= varname-dot-make-meta-bailiwick 436 TESTS+= varname-dot-make-meta-created 437 TESTS+= varname-dot-make-meta-files 438 .if ${.MAKE.PATH_FILEMON:Uno:Nktrace:N/dev*} == "" && ${TMPDIR:N/tmp*:N/var/tmp*} != "" 439 # these tests will not work if TMPDIR is or is a subdir of 440 # /tmp or /var/tmp 441 TESTS+= varname-dot-make-meta-ignore_filter 442 TESTS+= varname-dot-make-meta-ignore_paths 443 TESTS+= varname-dot-make-meta-ignore_patterns 444 TESTS+= varname-dot-make-path_filemon 445 .endif 446 TESTS+= varname-dot-make-meta-prefix 447 TESTS+= varname-dot-make-mode 448 TESTS+= varname-dot-make-pid 449 TESTS+= varname-dot-make-ppid 450 TESTS+= varname-dot-make-save_dollars 451 TESTS+= varname-dot-makeflags 452 TESTS+= varname-dot-makeoverrides 453 TESTS+= varname-dot-newline 454 TESTS+= varname-dot-objdir 455 TESTS+= varname-dot-parsedir 456 TESTS+= varname-dot-parsefile 457 TESTS+= varname-dot-path 458 TESTS+= varname-dot-shell 459 TESTS+= varname-dot-suffixes 460 TESTS+= varname-dot-targets 461 TESTS+= varname-empty 462 TESTS+= varname-make 463 TESTS+= varname-make_stack_trace 464 TESTS+= varname-make_print_var_on_error 465 TESTS+= varname-make_print_var_on_error-jobs 466 TESTS+= varname-makefile 467 TESTS+= varname-makeflags 468 TESTS+= varname-pwd 469 TESTS+= varname-vpath 470 TESTS+= varparse-dynamic 471 TESTS+= varparse-errors 472 TESTS+= varparse-mod 473 TESTS+= varparse-undef-partial 474 475 # Some tests just do not work on some platforms or environments 476 # so allow for some filtering. 477 .if !empty(BROKEN_TESTS) 478 TESTS:= ${TESTS:${BROKEN_TESTS:S,^,N,:ts:}} 479 .endif 480 481 # Ideas for more tests: 482 # char-0020-space.mk 483 # escape-cond-str.mk 484 # escape-cond-func-arg.mk 485 # escape-varmod.mk 486 # escape-varmod-define.mk 487 # escape-varmod-match.mk 488 # escape-varname.mk 489 # escape-varassign-varname.mk 490 # escape-varassign-varname-cmdline.mk 491 # escape-varassign-value.mk 492 # escape-varassign-value-cmdline.mk 493 # escape-dependency-source.mk 494 # escape-dependency-target.mk 495 # escape-for-varname.mk 496 # escape-for-item.mk 497 # posix-*.mk (see posix.mk and posix1.mk) 498 499 # Additional environment variables for some of the tests. 500 # The base environment is -i PATH="$PATH". 501 ENV.depsrc-optional+= TZ=UTC 502 ENV.directive-undef= ENV_VAR=env-value 503 ENV.opt-env= FROM_ENV=value-from-env 504 ENV.opt-m-include-dir= ${MAKEOBJDIR:DMAKEOBJDIR=${MAKEOBJDIR}} 505 ENV.varmisc= FROM_ENV=env 506 ENV.varmisc+= FROM_ENV_BEFORE=env 507 ENV.varmisc+= FROM_ENV_AFTER=env 508 ENV.varmod-localtime+= TZ=Europe/Berlin 509 ENV.varname-vpath+= VPATH=varname-vpath.dir:varname-vpath.dir2 510 511 # Override make flags for some of the tests; default is -k. 512 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of 513 # settings FLAGS.test=-dv here, since that is closer to the test code. 514 FLAGS.cond-func-make= via-cmdline 515 FLAGS.doterror= # none, especially not -k 516 FLAGS.jobs-error-indirect= # none, especially not -k 517 FLAGS.jobs-error-nested= # none, especially not -k 518 FLAGS.jobs-error-nested-make= # none, especially not -k 519 FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmdline-plain' 520 521 # Some tests need extra postprocessing. 522 SED_CMDS.deptgt-phony= ${STD_SED_CMDS.dd} 523 SED_CMDS.dir= ${STD_SED_CMDS.dd} 524 SED_CMDS.directive-include-guard= \ 525 -e '/\.MAKEFLAGS/d' \ 526 -e '/^Parsing .*:[1-9][0-9]*:/d' \ 527 -e '/^SetFilenameVars:/d' \ 528 -e '/^ParseDependency/d' \ 529 -e '/^ParseEOF:/d' 530 SED_CMDS.export= -e '/^[^=_A-Za-z0-9]*=/d' 531 SED_CMDS.export-all= ${SED_CMDS.export} 532 SED_CMDS.export-env= ${SED_CMDS.export} 533 SED_CMDS.job-output-long-lines= \ 534 ${:D Job separators on their own line are ok. } \ 535 -e '/^--- job-[ab] ---$$/d' \ 536 ${:D Plain output lines are ok as well. } \ 537 ${:D They may come in multiples of 1024 or as 10000. } \ 538 -e '/^aa*$$/d' \ 539 -e '/^bb*$$/d' \ 540 ${:D The following lines should rather not occur since the job } \ 541 ${:D marker should always be at the beginning of the line. } \ 542 -e '/^aa*--- job-b ---$$/d' \ 543 -e '/^bb*--- job-a ---$$/d' 544 545 SED_CMDS.gnode-submake= ${STD_SED_CMDS.dj} 546 SED_CMDS.gnode-submake= ${STD_SED_CMDS.dg2} 547 548 # meta line numbers can vary based on filemon implementation 549 SED_CMDS.meta-ignore= -e 's,\(\.meta:\)[1-9][0-9]*:,\1<line>:,' 550 551 SED_CMDS.opt-chdir= -e 's,\(nonexistent\).[1-9][0-9]*,\1,' 552 SED_CMDS.opt-debug-graph1= ${STD_SED_CMDS.dg1} 553 SED_CMDS.opt-debug-graph2= ${STD_SED_CMDS.dg2} 554 SED_CMDS.opt-debug-graph3= ${STD_SED_CMDS.dg3} 555 SED_CMDS.opt-debug-hash= -e 's,\(entries\)=[1-9][0-9],\1=<entries>,' 556 SED_CMDS.opt-debug-jobs= ${STD_SED_CMDS.dj} 557 SED_CMDS.opt-debug-lint+= ${STD_SED_CMDS.regex} 558 SED_CMDS.opt-jobs-no-action= ${STD_SED_CMDS.hide-from-output} 559 SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output} 560 SED_CMDS.opt-where-am-i= -e '/usr.obj/d' 561 SED_CMDS.opt-where-am-i+= -e '/\/\//d' 562 # For Compat_RunCommand, useShell == false. 563 SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<not found: ...>,' 564 # For Compat_RunCommand, useShell == true. 565 SED_CMDS.sh-dots+= -e 's,^make: exec(\(.*\)): .*$$,<not found: \1>,' 566 SED_CMDS.sh-dots+= -e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,' 567 # Race condition between the child's stdout and make's status. 568 SED_CMDS.sh-errctl= ${STD_SED_CMDS.dj} 569 SED_CMDS.sh-errctl+= -e '/^Process with pid/d' 570 SED_CMDS.sh-errctl+= -e '/^JobFinish:/d' 571 SED_CMDS.sh-flags= ${STD_SED_CMDS.hide-from-output} 572 SED_CMDS.sh-leading-hyphen= ${STD_SED_CMDS.shell} 573 SED_CMDS.suff-main+= ${STD_SED_CMDS.dg1} 574 SED_CMDS.suff-main-several+= ${STD_SED_CMDS.dg1} 575 SED_CMDS.suff-transform-debug+= ${STD_SED_CMDS.dg1} 576 SED_CMDS.var-op-shell+= ${STD_SED_CMDS.shell} 577 SED_CMDS.var-op-shell+= -e '/command/s,No such.*,not found,' 578 SED_CMDS.vardebug+= -e 's,${.SHELL},</path/to/shell>,' 579 SED_CMDS.varmod-mtime+= -e "s,\(mtime for .*\): .*,\1: <ENOENT>," 580 SED_CMDS.varmod-subst+= ${STD_SED_CMDS.regex} 581 SED_CMDS.varmod-subst-regex+= ${STD_SED_CMDS.regex} 582 SED_CMDS.varparse-errors+= ${STD_SED_CMDS.timestamp} 583 SED_CMDS.varname-dot-make-meta-ignore_filter+= ${SED_CMDS.meta-ignore} 584 SED_CMDS.varname-dot-make-meta-ignore_paths+= ${SED_CMDS.meta-ignore} 585 SED_CMDS.varname-dot-make-meta-ignore_patterns+= ${SED_CMDS.meta-ignore} 586 SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: [^:]*:,make: <normalized>:,' 587 SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: [^:]*:,make: <normalized>:,' 588 SED_CMDS.varname-dot-shell= -e 's, = /[^ ]*, = (details omitted),g' 589 SED_CMDS.varname-dot-shell+= -e 's,"/[^" ]*","(details omitted)",g' 590 SED_CMDS.varname-dot-shell+= -e 's,\[/[^] ]*\],[(details omitted)],g' 591 SED_CMDS.varname-empty= ${.OBJDIR .PARSEDIR .PATH .SHELL .SYSPATH:L:@v@-e '/\\$v/d'@} 592 593 # Some tests need an additional round of postprocessing. 594 POSTPROC.depsrc-wait= sed -e '/^---/d' -e 's,^\(: Making 3[abc]\)[123]$$,\1,' 595 POSTPROC.deptgt-suffixes= awk '/^\#\*\*\* Suffixes/,/^never-stop/' 596 POSTPROC.gnode-submake= \ 597 awk '/Begin input graph/, /^\# \.END/ { \ 598 if (/made,/) print $$0 \ 599 }' 600 POSTPROC.varname-dot-make-mode= sed 's,^\(: Making [abc]\)[123]$$,\1,' 601 602 # Some tests reuse other tests, which makes them unnecessarily fragile. 603 export-all.rawout: export.mk 604 unexport.rawout: export.mk 605 unexport-env.rawout: export.mk 606 607 # End of the configuration section. 608 609 # Some standard sed commands, to be used in the SED_CMDS above. 610 611 # In tests that use the debugging option -dd, ignore debugging output that is 612 # only logged in -DCLEANUP mode. 613 STD_SED_CMDS.dd= -e '/^OpenDirs_Done:/d' 614 STD_SED_CMDS.dd+= -e '/^CachedDir /d' 615 STD_SED_CMDS.dd+= -e 's, ${DEFSYSPATH:U/usr/share/mk} , <defsyspath> ,' 616 617 # Omit details such as process IDs from the output of the -dg1 option. 618 STD_SED_CMDS.dg1= -e 's,${.CURDIR}$$,<curdir>,' 619 STD_SED_CMDS.dg1+= -e 's, ${DEFSYSPATH:U/usr/share/mk}$$, <defsyspath>,' 620 STD_SED_CMDS.dg1+= -e '/^\.MAKE\.PATH_FILEMON/d' 621 STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,' 622 STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,' 623 STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.JOBS\.C *=\) .*,\1 <details omitted>,' 624 STD_SED_CMDS.dg1+= -e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,' 625 STD_SED_CMDS.dg1+= -e 's,^\(MAKE *=\) .*,\1 <details omitted>,' 626 STD_SED_CMDS.dg1+= -e 's,^\(\.SHELL *=\) .*,\1 <details omitted>,' 627 STD_SED_CMDS.dg1+= -e '/\.SYSPATH/d' 628 629 STD_SED_CMDS.dg2= ${STD_SED_CMDS.dg1} 630 STD_SED_CMDS.dg2+= -e 's,\(last modified\) ..:..:.. ... ..\, ....,\1 <timestamp>,' 631 632 STD_SED_CMDS.dg3= ${STD_SED_CMDS.dg2} 633 634 # Omit details such as process IDs from the output of the -dj option. 635 STD_SED_CMDS.dj= -e 's, pid [0-9][0-9]*, pid <pid>,' 636 STD_SED_CMDS.dj+= -e 's,^\(.Command\): ${.SHELL:T},\1: <shell>,' 637 # The "-q" may be there or not, see jobs.c, variable shells. 638 STD_SED_CMDS.dj+= -e 's,^\(.Command: <shell>\) -q,\1,' 639 640 # Reduce the noise for tests running with the -n option, since there is no 641 # other way to suppress the echoing of the commands. 642 STD_SED_CMDS.hide-from-output= \ 643 -e '/^echo hide-from-output/d' \ 644 -e 's,hide-from-output ,,' \ 645 -e 's,hide-from-output,,' 646 647 # Normalize the output for error messages from the shell. 648 # 649 # $shell -c '...' 650 # NetBSD sh ...: not found 651 # NetBSD ksh ksh: ...: not found 652 # bash 5.0.18 bash: ...: command not found 653 # bash 5.1.0 bash: line 1: ...: command not found 654 # dash dash: 1: ...: not found 655 # 656 # $shell -c '< /nonexistent' 657 # NetBSD sh sh: cannot open /nonexistent: no such file 658 # NetBSD ksh ksh: cannot open /nonexistent: No such file or directory 659 # bash 5.0.18 bash: /nonexistent: No such file or directory 660 # bash 5.1.0 bash: line 1: /nonexistent: No such file or directory 661 # dash dash: 1: cannot open /nonexistent: No such file 662 # 663 # echo '< /nonexistent' | $shell 664 # NetBSD sh sh: cannot open /nonexistent: no such file 665 # NetBSD ksh ksh: <stdin>[1]: cannot open /nonexistent: No such file or directory 666 # bash 5.0.18 bash: line 1: /nonexistent: No such file or directory 667 # bash 5.1.0 bash: line 1: /nonexistent: No such file or directory 668 # dash dash: 1: cannot open /nonexistent: No such file 669 # 670 STD_SED_CMDS.shell+= -e 's,^${.SHELL},${.SHELL:T},' 671 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: line [0-9][0-9]*: ,,' 672 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: [0-9][0-9]*: ,,' 673 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: ,,' 674 STD_SED_CMDS.shell+= -e 's,: command not found,: not found,' 675 676 # The actual error messages for a failed regcomp or regexec differ between the 677 # implementations. 678 STD_SED_CMDS.regex= \ 679 -e 's,\(Regex compilation error:\).*,\1 (details omitted),' 680 681 # Normalize timestamps from ':gmtime' or ':localtime' to '<timestamp>'. 682 # See STD_SED_CMDS.dg2 for timestamps from the debug log. 683 STD_SED_CMDS.timestamp= \ 684 -e 's,[A-Z][a-z][a-z] [A-Z][a-z][a-z] [ 0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [12][0-9][0-9][0-9],<timestamp>,' 685 686 # End of the configuration helpers section. 687 688 UNIT_TESTS:= ${.PARSEDIR} 689 .PATH: ${UNIT_TESTS} 690 691 .if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes 692 OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@} 693 .else 694 OUTFILES= ${TESTS:=.out} 695 .endif 696 697 all: ${OUTFILES} 698 699 CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp 700 CLEANFILES+= obj*.[och] lib*.a # posix1.mk 701 CLEANFILES+= issue* .[ab]* # suffixes.mk 702 CLEANDIRS= dir dummy *.tmp # posix1.mk 703 704 clean: 705 rm -rf ${CLEANDIRS} 706 rm -f ${CLEANFILES} 707 708 TEST_MAKE?= ${.MAKE} 709 .if ${TEST_MAKE:M/*} == "" 710 # we want an absolute path for TEST_MAKE 711 tm!= for d in ${PATH:S,:, ,g:M/*}; do \ 712 test -x $$d/${TEST_MAKE} || continue; \ 713 echo $$d/${TEST_MAKE}; break; done 714 .if ${tm:M/*} 715 TEST_MAKE:= ${tm} 716 .endif 717 .endif 718 719 TOOL_SED?= sed 720 721 # ensure consistent results from sort(1) 722 LC_ALL= C 723 LANG= C 724 .export LANG LC_ALL 725 726 # Some Linux systems such as Fedora have deprecated egrep in favor of grep -E. 727 .if ${.MAKE.OS:NLinux} == "" 728 EGREP= grep -E 729 .endif 730 # Keep the classical definition for all other systems. Just as the bmake code 731 # is kept compatible with C90, the tests are kept compatible with systems that 732 # are several decades old and don't follow modern POSIX standards. 733 EGREP?= egrep 734 735 MAKE_TEST_ENV= EGREP="${EGREP}" 736 MAKE_TEST_ENV+= MALLOC_OPTIONS="JA" # for jemalloc 100 737 MAKE_TEST_ENV+= MALLOC_CONF="junk:true" # for jemalloc 510 738 MAKE_TEST_ENV+= TMPDIR=${TMPDIR} 739 740 .if ${.MAKE.OS} == "NetBSD" 741 LIMIT_RESOURCES?= ulimit -v 300000 742 .endif 743 LIMIT_RESOURCES?= : 744 745 # Each test is run in a sub-make, to keep the tests from interfering with 746 # each other, and because they use different environment variables and 747 # command line options. 748 .SUFFIXES: .mk .rawout .out 749 .mk.rawout: .META 750 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX} 751 @set -eu; \ 752 ${LIMIT_RESOURCES}; \ 753 cd ${.OBJDIR}; \ 754 env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \ 755 ${TEST_MAKE} \ 756 -r -C ${.CURDIR} -f ${.IMPSRC} \ 757 ${FLAGS.${.PREFIX:T}:U-k} \ 758 > ${.TARGET}.tmp 2>&1 \ 759 && status=$$? || status=$$?; \ 760 echo $$status > ${.TARGET:R}.status 761 @mv ${.TARGET}.tmp ${.TARGET} 762 763 # Postprocess the test output to make the output platform-independent. 764 # 765 # Replace anything after 'stopped in' with unit-tests 766 _SED_CMDS+= -e '/stopped/s, in /.*, in unit-tests,' 767 # Allow the test files to be placed anywhere. 768 _SED_CMDS+= -e 's,\(\.PARSEDIR}\) = `'"/[^']*'"',\1 = <some-dir>,' 769 _SED_CMDS+= -e 's,\(\.INCLUDEDFROMDIR}\) = `'"/[^']*'"',\1 = <some-dir>,' 770 _SED_CMDS+= -e 's,${TMPDIR},<tmpdir>,g' -e 's,${TMPDIR:tA},<tmpdir>,g' 771 # canonicalize ${.OBJDIR} and ${.CURDIR} 772 _SED_CMDS+= -e 's,${.CURDIR},<curdir>,g' 773 .if ${.OBJDIR} != ${.CURDIR} 774 # yes this is inaccurate but none of the tests expect <objdir> anywhere 775 # which we get depending on how MAKEOBJDIR is set. 776 _SED_CMDS+= -e 's,${.OBJDIR},<curdir>,g' -e 's,${.OBJDIR:tA},<curdir>,g' 777 .endif 778 779 # At the end, make sure we cleanup any dregs... 780 .for d in ${MAKEOBJDIRPREFIX:S,/$,,} /usr/obj 781 _SED_CMDS_LAST+= -e 's,$d,,' 782 .endfor 783 784 # always pretend .MAKE was called 'make' 785 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 786 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 787 _SED_CMDS+= -e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,' 788 _SED_CMDS+= -e 's,${TEST_MAKE:T:S,.,\\.,g}\(\[[1-9][0-9]*\][: ]\),make\1,' 789 _SED_CMDS+= -e 's,<curdir>/,,g' 790 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 791 _SED_CMDS+= -e 's,\(\.make\)[1-9][0-9]*,\1,g' 792 _SED_CMDS+= -e '/MAKE.VERSION/d' 793 _SED_CMDS+= -e '/EGREP=/d' 794 795 .rawout.out: .META 796 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} ${_SED_CMDS_LAST} \ 797 < ${.IMPSRC} > ${.TARGET}.tmp 798 @${POSTPROC.${.PREFIX:T}:D \ 799 ${POSTPROC.${.PREFIX:T}} < ${.TARGET}.tmp > ${.TARGET}.post \ 800 && mv ${.TARGET}.post ${.TARGET}.tmp} 801 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp 802 @mv ${.TARGET}.tmp ${.TARGET} 803 804 # Compare all output files 805 test: ${OUTFILES} .PHONY 806 @failed= ; \ 807 for test in ${TESTS}; do \ 808 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 809 || failed="$${failed}$${failed:+ }$${test}" ; \ 810 done ; \ 811 if [ -n "$${failed}" ]; then \ 812 echo "Failed tests: $${failed}" ; false ; \ 813 else \ 814 echo "All tests passed" ; \ 815 lua=${LUA:Ulua} ; \ 816 have_lua=$$("$$lua" -e 'print "yes"' 2>&1) ; \ 817 if [ "$$have_lua" = "yes" ]; then \ 818 (cd ${.CURDIR} && "$$lua" ./check-expect.lua *.mk); \ 819 fi; \ 820 fi 821 822 accept: 823 @for test in ${TESTS}; do \ 824 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 825 || { echo "Replacing $${test}.exp" ; \ 826 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 827 done 828 829 # Note: only works for adding tests. 830 # To remove a test, the $$mi file must be edited manually. 831 sync-mi: 832 @set -eu; \ 833 cd "${MAKEFILE:tA:H}/../../.."; \ 834 mi="distrib/sets/lists/tests/mi"; \ 835 cvs update "$$mi"; \ 836 testsdir="usr.bin/make/unit-tests"; \ 837 fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \ 838 cat "$$mi" > "$$mi.tmp"; \ 839 (cd "$$testsdir" && egrep '\.(exp|mk)/' CVS/Entries | cut -d/ -f2) | \ 840 xargs printf "$$fmt" >> "$$mi.tmp"; \ 841 distrib/sets/fmt-list "$$mi.tmp"; \ 842 mv "$$mi.tmp" "$$mi"; \ 843 cvs diff "$$mi" || true 844 845 .if exists(${TEST_MAKE}) 846 ${TESTS:=.rawout}: ${TEST_MAKE} 847 # in meta mode, we *know* if a target script is impacted 848 # by a makefile change. 849 .if ${.MAKE.MODE:Unormal:Mmeta} == "" 850 ${TESTS:=.rawout}: ${.PARSEDIR}/Makefile 851 .endif 852 .endif 853 854 .-include <bsd.obj.mk> 855