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