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