Makefile revision 1.373
1# $NetBSD: Makefile,v 1.373 2025/11/12 22:14:08 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-sun-shell1 406TESTS+= varmod-sysv 407TESTS+= varmod-tail 408TESTS+= varmod-to-abs 409TESTS+= varmod-to-lower 410TESTS+= varmod-to-many-words 411TESTS+= varmod-to-one-word 412TESTS+= varmod-to-separator 413TESTS+= varmod-to-title 414TESTS+= varmod-to-upper 415TESTS+= varmod-undefined 416TESTS+= varmod-unique 417TESTS+= varname 418TESTS+= varname-circumflex 419TESTS+= varname-dollar 420TESTS+= varname-dot-alltargets 421TESTS+= varname-dot-curdir 422TESTS+= varname-dot-includes 423TESTS+= varname-dot-includedfromdir 424TESTS+= varname-dot-includedfromfile 425TESTS+= varname-dot-libs 426TESTS+= varname-dot-make-dependfile 427TESTS+= varname-dot-make-expand_variables 428TESTS+= varname-dot-make-exported 429TESTS+= varname-dot-make-jobs 430TESTS+= varname-dot-make-jobs-prefix 431TESTS+= varname-dot-make-level 432TESTS+= varname-dot-make-makefile_preference 433TESTS+= varname-dot-make-makefiles 434TESTS+= varname-dot-make-meta-bailiwick 435TESTS+= varname-dot-make-meta-created 436TESTS+= varname-dot-make-meta-files 437.if ${.MAKE.PATH_FILEMON:Uno:Nktrace:N/dev*} == "" && ${TMPDIR:N/tmp*:N/var/tmp*} != "" 438# these tests will not work if TMPDIR is or is a subdir of 439# /tmp or /var/tmp 440TESTS+= varname-dot-make-meta-ignore_filter 441TESTS+= varname-dot-make-meta-ignore_paths 442TESTS+= varname-dot-make-meta-ignore_patterns 443TESTS+= varname-dot-make-path_filemon 444.endif 445TESTS+= varname-dot-make-meta-prefix 446TESTS+= varname-dot-make-mode 447TESTS+= varname-dot-make-pid 448TESTS+= varname-dot-make-ppid 449TESTS+= varname-dot-make-save_dollars 450TESTS+= varname-dot-makeflags 451TESTS+= varname-dot-makeoverrides 452TESTS+= varname-dot-newline 453TESTS+= varname-dot-objdir 454TESTS+= varname-dot-parsedir 455TESTS+= varname-dot-parsefile 456TESTS+= varname-dot-path 457TESTS+= varname-dot-shell 458TESTS+= varname-dot-suffixes 459TESTS+= varname-dot-targets 460TESTS+= varname-empty 461TESTS+= varname-make 462TESTS+= varname-make_stack_trace 463TESTS+= varname-make_print_var_on_error 464TESTS+= varname-make_print_var_on_error-jobs 465TESTS+= varname-makefile 466TESTS+= varname-makeflags 467TESTS+= varname-pwd 468TESTS+= varname-vpath 469TESTS+= varparse-dynamic 470TESTS+= varparse-errors 471TESTS+= varparse-mod 472TESTS+= varparse-undef-partial 473 474# Some tests just do not work on some platforms or environments 475# so allow for some filtering. 476.if !empty(BROKEN_TESTS) 477TESTS:= ${TESTS:${BROKEN_TESTS:S,^,N,:ts:}} 478.endif 479 480# Ideas for more tests: 481# char-0020-space.mk 482# escape-cond-str.mk 483# escape-cond-func-arg.mk 484# escape-varmod.mk 485# escape-varmod-define.mk 486# escape-varmod-match.mk 487# escape-varname.mk 488# escape-varassign-varname.mk 489# escape-varassign-varname-cmdline.mk 490# escape-varassign-value.mk 491# escape-varassign-value-cmdline.mk 492# escape-dependency-source.mk 493# escape-dependency-target.mk 494# escape-for-varname.mk 495# escape-for-item.mk 496# posix-*.mk (see posix.mk and posix1.mk) 497 498# Additional environment variables for some of the tests. 499# The base environment is -i PATH="$PATH". 500ENV.depsrc-optional+= TZ=UTC 501ENV.directive-undef= ENV_VAR=env-value 502ENV.opt-env= FROM_ENV=value-from-env 503ENV.opt-m-include-dir= ${MAKEOBJDIR:DMAKEOBJDIR=${MAKEOBJDIR}} 504ENV.varmisc= FROM_ENV=env 505ENV.varmisc+= FROM_ENV_BEFORE=env 506ENV.varmisc+= FROM_ENV_AFTER=env 507ENV.varmod-localtime+= TZ=Europe/Berlin 508ENV.varname-vpath+= VPATH=varname-vpath.dir:varname-vpath.dir2 509 510# Override make flags for some of the tests; default is -k. 511# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of 512# settings FLAGS.test=-dv here, since that is closer to the test code. 513FLAGS.cond-func-make= via-cmdline 514FLAGS.doterror= # none, especially not -k 515FLAGS.jobs-error-indirect= # none, especially not -k 516FLAGS.jobs-error-nested= # none, especially not -k 517FLAGS.jobs-error-nested-make= # none, especially not -k 518FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmdline-plain' 519 520# Some tests need extra postprocessing. 521SED_CMDS.deptgt-phony= ${STD_SED_CMDS.dd} 522SED_CMDS.dir= ${STD_SED_CMDS.dd} 523SED_CMDS.directive-include-guard= \ 524 -e '/\.MAKEFLAGS/d' \ 525 -e '/^Parsing .*:[1-9][0-9]*:/d' \ 526 -e '/^SetFilenameVars:/d' \ 527 -e '/^ParseDependency/d' \ 528 -e '/^ParseEOF:/d' 529SED_CMDS.export= -e '/^[^=_A-Za-z0-9]*=/d' 530SED_CMDS.export-all= ${SED_CMDS.export} 531SED_CMDS.export-env= ${SED_CMDS.export} 532SED_CMDS.job-output-long-lines= \ 533 ${:D Job separators on their own line are ok. } \ 534 -e '/^--- job-[ab] ---$$/d' \ 535 ${:D Plain output lines are ok as well. } \ 536 ${:D They may come in multiples of 1024 or as 10000. } \ 537 -e '/^aa*$$/d' \ 538 -e '/^bb*$$/d' \ 539 ${:D The following lines should rather not occur since the job } \ 540 ${:D marker should always be at the beginning of the line. } \ 541 -e '/^aa*--- job-b ---$$/d' \ 542 -e '/^bb*--- job-a ---$$/d' 543 544# meta line numbers can vary based on filemon implementation 545SED_CMDS.meta-ignore= -e 's,\(\.meta:\)[1-9][0-9]*:,\1<line>:,' 546 547SED_CMDS.opt-chdir= -e 's,\(nonexistent\).[1-9][0-9]*,\1,' 548SED_CMDS.opt-debug-graph1= ${STD_SED_CMDS.dg1} 549SED_CMDS.opt-debug-graph2= ${STD_SED_CMDS.dg2} 550SED_CMDS.opt-debug-graph3= ${STD_SED_CMDS.dg3} 551SED_CMDS.opt-debug-hash= -e 's,\(entries\)=[1-9][0-9],\1=<entries>,' 552SED_CMDS.opt-debug-jobs= ${STD_SED_CMDS.dj} 553SED_CMDS.opt-debug-lint+= ${STD_SED_CMDS.regex} 554SED_CMDS.opt-jobs-no-action= ${STD_SED_CMDS.hide-from-output} 555SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output} 556SED_CMDS.opt-where-am-i= -e '/usr.obj/d' 557# For Compat_RunCommand, useShell == false. 558SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<not found: ...>,' 559# For Compat_RunCommand, useShell == true. 560SED_CMDS.sh-dots+= -e 's,^make: exec(\(.*\)): .*$$,<not found: \1>,' 561SED_CMDS.sh-dots+= -e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,' 562# Race condition between the child's stdout and make's status. 563SED_CMDS.sh-errctl= ${STD_SED_CMDS.dj} 564SED_CMDS.sh-errctl+= -e '/^Process with pid/d' 565SED_CMDS.sh-errctl+= -e '/^JobFinish:/d' 566SED_CMDS.sh-flags= ${STD_SED_CMDS.hide-from-output} 567SED_CMDS.sh-leading-hyphen= ${STD_SED_CMDS.shell} 568SED_CMDS.suff-main+= ${STD_SED_CMDS.dg1} 569SED_CMDS.suff-main-several+= ${STD_SED_CMDS.dg1} 570SED_CMDS.suff-transform-debug+= ${STD_SED_CMDS.dg1} 571SED_CMDS.var-op-shell+= ${STD_SED_CMDS.shell} 572SED_CMDS.var-op-shell+= -e '/command/s,No such.*,not found,' 573SED_CMDS.vardebug+= -e 's,${.SHELL},</path/to/shell>,' 574SED_CMDS.varmod-mtime+= -e "s,\(mtime for .*\): .*,\1: <ENOENT>," 575SED_CMDS.varmod-subst-regex+= ${STD_SED_CMDS.regex} 576SED_CMDS.varparse-errors+= ${STD_SED_CMDS.timestamp} 577SED_CMDS.varname-dot-make-meta-ignore_filter+= ${SED_CMDS.meta-ignore} 578SED_CMDS.varname-dot-make-meta-ignore_paths+= ${SED_CMDS.meta-ignore} 579SED_CMDS.varname-dot-make-meta-ignore_patterns+= ${SED_CMDS.meta-ignore} 580SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: [^:]*:,make: <normalized>:,' 581SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: [^:]*:,make: <normalized>:,' 582SED_CMDS.varname-dot-shell= -e 's, = /[^ ]*, = (details omitted),g' 583SED_CMDS.varname-dot-shell+= -e 's,"/[^" ]*","(details omitted)",g' 584SED_CMDS.varname-dot-shell+= -e 's,\[/[^] ]*\],[(details omitted)],g' 585SED_CMDS.varname-empty= ${.OBJDIR .PARSEDIR .PATH .SHELL .SYSPATH:L:@v@-e '/\\$v/d'@} 586 587# Some tests need an additional round of postprocessing. 588POSTPROC.depsrc-wait= sed -e '/^---/d' -e 's,^\(: Making 3[abc]\)[123]$$,\1,' 589POSTPROC.deptgt-suffixes= awk '/^\#\*\*\* Suffixes/,/^never-stop/' 590POSTPROC.gnode-submake= awk '/Begin input graph/, /^$$/' 591POSTPROC.varname-dot-make-mode= sed 's,^\(: Making [abc]\)[123]$$,\1,' 592 593# Some tests reuse other tests, which makes them unnecessarily fragile. 594export-all.rawout: export.mk 595unexport.rawout: export.mk 596unexport-env.rawout: export.mk 597 598# End of the configuration section. 599 600# Some standard sed commands, to be used in the SED_CMDS above. 601 602# In tests that use the debugging option -dd, ignore debugging output that is 603# only logged in -DCLEANUP mode. 604STD_SED_CMDS.dd= -e '/^OpenDirs_Done:/d' 605STD_SED_CMDS.dd+= -e '/^CachedDir /d' 606STD_SED_CMDS.dd+= -e 's, ${DEFSYSPATH:U/usr/share/mk} , <defsyspath> ,' 607 608# Omit details such as process IDs from the output of the -dg1 option. 609STD_SED_CMDS.dg1= -e 's,${.CURDIR}$$,<curdir>,' 610STD_SED_CMDS.dg1+= -e 's, ${DEFSYSPATH:U/usr/share/mk}$$, <defsyspath>,' 611STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,' 612STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,' 613STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.JOBS\.C *=\) .*,\1 <details omitted>,' 614STD_SED_CMDS.dg1+= -e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,' 615STD_SED_CMDS.dg1+= -e 's,^\(MAKE *=\) .*,\1 <details omitted>,' 616STD_SED_CMDS.dg1+= -e 's,^\(\.SHELL *=\) .*,\1 <details omitted>,' 617STD_SED_CMDS.dg1+= -e '/\.SYSPATH/d' 618 619STD_SED_CMDS.dg2= ${STD_SED_CMDS.dg1} 620STD_SED_CMDS.dg2+= -e 's,\(last modified\) ..:..:.. ... ..\, ....,\1 <timestamp>,' 621STD_SED_CMDS.dg3= ${STD_SED_CMDS.dg2} 622 623# Omit details such as process IDs from the output of the -dj option. 624STD_SED_CMDS.dj= -e 's, pid [0-9][0-9]*, pid <pid>,' 625STD_SED_CMDS.dj+= -e 's,^\(.Command\): ${.SHELL:T},\1: <shell>,' 626# The "-q" may be there or not, see jobs.c, variable shells. 627STD_SED_CMDS.dj+= -e 's,^\(.Command: <shell>\) -q,\1,' 628 629# Reduce the noise for tests running with the -n option, since there is no 630# other way to suppress the echoing of the commands. 631STD_SED_CMDS.hide-from-output= \ 632 -e '/^echo hide-from-output/d' \ 633 -e 's,hide-from-output ,,' \ 634 -e 's,hide-from-output,,' 635 636# Normalize the output for error messages from the shell. 637# 638# $shell -c '...' 639# NetBSD sh ...: not found 640# NetBSD ksh ksh: ...: not found 641# bash 5.0.18 bash: ...: command not found 642# bash 5.1.0 bash: line 1: ...: command not found 643# dash dash: 1: ...: not found 644# 645# $shell -c '< /nonexistent' 646# NetBSD sh sh: cannot open /nonexistent: no such file 647# NetBSD ksh ksh: cannot open /nonexistent: No such file or directory 648# bash 5.0.18 bash: /nonexistent: No such file or directory 649# bash 5.1.0 bash: line 1: /nonexistent: No such file or directory 650# dash dash: 1: cannot open /nonexistent: No such file 651# 652# echo '< /nonexistent' | $shell 653# NetBSD sh sh: cannot open /nonexistent: no such file 654# NetBSD ksh ksh: <stdin>[1]: cannot open /nonexistent: No such file or directory 655# bash 5.0.18 bash: line 1: /nonexistent: No such file or directory 656# bash 5.1.0 bash: line 1: /nonexistent: No such file or directory 657# dash dash: 1: cannot open /nonexistent: No such file 658# 659STD_SED_CMDS.shell+= -e 's,^${.SHELL},${.SHELL:T},' 660STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: line [0-9][0-9]*: ,,' 661STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: [0-9][0-9]*: ,,' 662STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: ,,' 663STD_SED_CMDS.shell+= -e 's,: command not found,: not found,' 664 665# The actual error messages for a failed regcomp or regexec differ between the 666# implementations. 667STD_SED_CMDS.regex= \ 668 -e 's,\(Regex compilation error:\).*,\1 (details omitted),' 669 670# Normalize timestamps from ':gmtime' or ':localtime' to '<timestamp>'. 671# See STD_SED_CMDS.dg2 for timestamps from the debug log. 672STD_SED_CMDS.timestamp= \ 673 -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>,' 674 675# End of the configuration helpers section. 676 677UNIT_TESTS:= ${.PARSEDIR} 678.PATH: ${UNIT_TESTS} 679 680.if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes 681OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@} 682.else 683OUTFILES= ${TESTS:=.out} 684.endif 685 686all: ${OUTFILES} 687 688CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp 689CLEANFILES+= obj*.[och] lib*.a # posix1.mk 690CLEANFILES+= issue* .[ab]* # suffixes.mk 691CLEANDIRS= dir dummy *.tmp # posix1.mk 692 693clean: 694 rm -rf ${CLEANDIRS} 695 rm -f ${CLEANFILES} 696 697TEST_MAKE?= ${.MAKE} 698TOOL_SED?= sed 699 700# ensure consistent results from sort(1) 701LC_ALL= C 702LANG= C 703.export LANG LC_ALL 704 705# Some Linux systems such as Fedora have deprecated egrep in favor of grep -E. 706.if ${.MAKE.OS:NLinux} == "" 707EGREP= grep -E 708.endif 709# Keep the classical definition for all other systems. Just as the bmake code 710# is kept compatible with C90, the tests are kept compatible with systems that 711# are several decades old and don't follow modern POSIX standards. 712EGREP?= egrep 713 714MAKE_TEST_ENV= EGREP="${EGREP}" 715MAKE_TEST_ENV+= MALLOC_OPTIONS="JA" # for jemalloc 100 716MAKE_TEST_ENV+= MALLOC_CONF="junk:true" # for jemalloc 510 717MAKE_TEST_ENV+= TMPDIR=${TMPDIR} 718 719.if ${.MAKE.OS} == "NetBSD" 720LIMIT_RESOURCES?= ulimit -v 300000 721.endif 722LIMIT_RESOURCES?= : 723 724# Each test is run in a sub-make, to keep the tests from interfering with 725# each other, and because they use different environment variables and 726# command line options. 727.SUFFIXES: .mk .rawout .out 728.mk.rawout: 729 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX} 730 @set -eu; \ 731 ${LIMIT_RESOURCES}; \ 732 cd ${.OBJDIR}; \ 733 env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \ 734 ${TEST_MAKE} \ 735 -r -C ${.CURDIR} -f ${.IMPSRC} \ 736 ${FLAGS.${.PREFIX:T}:U-k} \ 737 > ${.TARGET}.tmp 2>&1 \ 738 && status=$$? || status=$$?; \ 739 echo $$status > ${.TARGET:R}.status 740 @mv ${.TARGET}.tmp ${.TARGET} 741 742# Postprocess the test output to make the output platform-independent. 743# 744# Replace anything after 'stopped in' with unit-tests 745_SED_CMDS+= -e '/stopped/s, in /.*, in unit-tests,' 746# Allow the test files to be placed anywhere. 747_SED_CMDS+= -e 's,\(\.PARSEDIR}\) = `'"/[^']*'"',\1 = <some-dir>,' 748_SED_CMDS+= -e 's,\(\.INCLUDEDFROMDIR}\) = `'"/[^']*'"',\1 = <some-dir>,' 749_SED_CMDS+= -e 's,${TMPDIR},<tmpdir>,g' -e 's,${TMPDIR:tA},<tmpdir>,g' 750# canonicalize ${.OBJDIR} and ${.CURDIR} 751_SED_CMDS+= -e 's,${.CURDIR},<curdir>,g' 752.if ${.OBJDIR} != ${.CURDIR} 753# yes this is inaccurate but none of the tests expect <objdir> anywhere 754# which we get depending on how MAKEOBJDIR is set. 755_SED_CMDS+= -e 's,${.OBJDIR},<curdir>,g' -e 's,${.OBJDIR:tA},<curdir>,g' 756.endif 757# always pretend .MAKE was called 'make' 758_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 759_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 760_SED_CMDS+= -e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,' 761_SED_CMDS+= -e 's,${TEST_MAKE:T:S,.,\\.,g}\(\[[1-9][0-9]*\][: ]\),make\1,' 762_SED_CMDS+= -e 's,<curdir>/,,g' 763_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 764_SED_CMDS+= -e '/MAKE_VERSION/d' 765_SED_CMDS+= -e '/EGREP=/d' 766 767.rawout.out: 768 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \ 769 < ${.IMPSRC} > ${.TARGET}.tmp 770 @${POSTPROC.${.PREFIX:T}:D \ 771 ${POSTPROC.${.PREFIX:T}} < ${.TARGET}.tmp > ${.TARGET}.post \ 772 && mv ${.TARGET}.post ${.TARGET}.tmp} 773 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp 774 @mv ${.TARGET}.tmp ${.TARGET} 775 776# Compare all output files 777test: ${OUTFILES} .PHONY 778 @failed= ; \ 779 for test in ${TESTS}; do \ 780 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 781 || failed="$${failed}$${failed:+ }$${test}" ; \ 782 done ; \ 783 if [ -n "$${failed}" ]; then \ 784 echo "Failed tests: $${failed}" ; false ; \ 785 else \ 786 echo "All tests passed" ; \ 787 lua=${LUA:Ulua} ; \ 788 have_lua=$$("$$lua" -e 'print "yes"' 2>&1) ; \ 789 if [ "$$have_lua" = "yes" ]; then \ 790 (cd ${.CURDIR} && "$$lua" ./check-expect.lua *.mk); \ 791 fi; \ 792 fi 793 794accept: 795 @for test in ${TESTS}; do \ 796 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 797 || { echo "Replacing $${test}.exp" ; \ 798 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 799 done 800 801# Note: only works for adding tests. 802# To remove a test, the $$mi file must be edited manually. 803sync-mi: 804 @set -eu; \ 805 cd "${MAKEFILE:tA:H}/../../.."; \ 806 mi="distrib/sets/lists/tests/mi"; \ 807 cvs update "$$mi"; \ 808 testsdir="usr.bin/make/unit-tests"; \ 809 fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \ 810 cat "$$mi" > "$$mi.tmp"; \ 811 (cd "$$testsdir" && egrep '\.(exp|mk)/' CVS/Entries | cut -d/ -f2) | \ 812 xargs printf "$$fmt" >> "$$mi.tmp"; \ 813 distrib/sets/fmt-list "$$mi.tmp"; \ 814 mv "$$mi.tmp" "$$mi"; \ 815 cvs diff "$$mi" || true 816 817.if exists(${TEST_MAKE}) 818${TESTS:=.rawout}: ${TEST_MAKE} 819# in meta mode, we *know* if a target script is impacted 820# by a makefile change. 821.if ${.MAKE.MODE:Unormal:Mmeta} == "" 822${TESTS:=.rawout}: ${.PARSEDIR}/Makefile 823.endif 824.endif 825 826.-include <bsd.obj.mk> 827