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