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