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