1# $Id: Makefile,v 1.216 2024/04/30 16:42:50 sjg Exp $ 2# 3# $NetBSD: Makefile,v 1.344 2024/04/30 16:41:32 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:NDarwin} == "" 478BROKEN_TESTS+= shell-ksh 479.endif 480 481.if ${.MAKE.OS:NIRIX*} == "" 482BROKEN_TESTS+= \ 483 cmd-interrupt \ 484 deptgt-interrupt \ 485 job-output-null \ 486 opt-chdir \ 487 opt-debug-x-trace \ 488 sh-leading-hyphen \ 489 490.endif 491 492.if ${.MAKE.OS} == "SCO_SV" 493BROKEN_TESTS+= \ 494 opt-debug-graph[23] \ 495 varmod-localtime \ 496 varmod-to-separator \ 497 498.if ${_shell} == "bash" 499BROKEN_TESTS+= job-output-null 500.else 501BROKEN_TESTS+= \ 502 cmd-interrupt \ 503 job-flags \ 504 505.endif 506.endif 507 508# Some tests just do not work on some platforms or environments 509# so allow for some filtering. 510.if !empty(BROKEN_TESTS) 511.warning Skipping broken tests: ${BROKEN_TESTS:O:u} 512TESTS:= ${TESTS:${BROKEN_TESTS:S,^,N,:ts:}} 513.endif 514 515# Ideas for more tests: 516# char-0020-space.mk 517# char-005C-backslash.mk 518# escape-cond-str.mk 519# escape-cond-func-arg.mk 520# escape-varmod.mk 521# escape-varmod-define.mk 522# escape-varmod-match.mk 523# escape-varname.mk 524# escape-varassign-varname.mk 525# escape-varassign-varname-cmdline.mk 526# escape-varassign-value.mk 527# escape-varassign-value-cmdline.mk 528# escape-dependency-source.mk 529# escape-dependency-target.mk 530# escape-for-varname.mk 531# escape-for-item.mk 532# posix-*.mk (see posix.mk and posix1.mk) 533 534# Additional environment variables for some of the tests. 535# The base environment is -i PATH="$PATH". 536ENV.depsrc-optional+= TZ=UTC 537ENV.deptgt-phony+= MAKESYSPATH=. 538ENV.directive-undef= ENV_VAR=env-value 539ENV.opt-env= FROM_ENV=value-from-env 540ENV.opt-m-include-dir= ${MAKEOBJDIR:DMAKEOBJDIR=${MAKEOBJDIR}} 541ENV.varmisc= FROM_ENV=env 542ENV.varmisc+= FROM_ENV_BEFORE=env 543ENV.varmisc+= FROM_ENV_AFTER=env 544ENV.varmod-localtime+= TZ=${UTC_1:UEurope/Berlin} 545ENV.varname-vpath+= VPATH=varname-vpath.dir:varname-vpath.dir2 546 547# Override make flags for some of the tests; default is -k. 548# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of 549# settings FLAGS.test=-dv here, since that is closer to the test code. 550FLAGS.cond-func-make= via-cmdline 551FLAGS.doterror= # none, especially not -k 552FLAGS.jobs-error-indirect= # none, especially not -k 553FLAGS.jobs-error-nested= # none, especially not -k 554FLAGS.jobs-error-nested-make= # none, especially not -k 555FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmdline-plain' 556 557# Some tests need extra postprocessing. 558SED_CMDS.deptgt-phony= ${STD_SED_CMDS.dd} 559SED_CMDS.dir= ${STD_SED_CMDS.dd} 560SED_CMDS.directive-include-guard= \ 561 -e '/\.MAKEFLAGS/d' \ 562 -e '/^Parsing line/d' \ 563 -e '/^SetFilenameVars:/d' \ 564 -e '/^ParseDependency/d' \ 565 -e '/^ParseEOF:/d' 566SED_CMDS.export= -e '/^[^=_A-Za-z0-9]*=/d' 567.if ${.MAKE.OS:NCygwin} == "" 568SED_CMDS.export+= -e '/^WINDIR=/d' -e '/^SYSTEMROOT=/d' 569.endif 570SED_CMDS.export-all= ${SED_CMDS.export} 571SED_CMDS.export-env= ${SED_CMDS.export} 572SED_CMDS.cmdline= -e 's,uid${.MAKE.UID}/,,' 573SED_CMDS.job-output-long-lines= \ 574 ${:D Job separators on their own line are ok. } \ 575 -e '/^--- job-[ab] ---$$/d' \ 576 ${:D Plain output lines are ok as well. } \ 577 ${:D They may come in multiples of 1024 or as 10000. } \ 578 -e '/^aa*$$/d' \ 579 -e '/^bb*$$/d' \ 580 ${:D The following lines should rather not occur since the job } \ 581 ${:D marker should always be at the beginning of the line. } \ 582 -e '/^aa*--- job-b ---$$/d' \ 583 -e '/^bb*--- job-a ---$$/d' 584SED_CMDS.opt-chdir= -e 's,\(nonexistent\).[1-9][0-9]*,\1,' \ 585 -e '/name/s,file,File,' \ 586 -e 's,no such,No such,' \ 587 -e 's,Filename,File name,' 588 589# meta line numbers can vary based on filemon implementation 590SED_CMDS.meta-ignore= -e 's,\(\.meta:\) [1-9][0-9]*:,\1 <line>:,' 591SED_CMDS.opt-debug-graph1= ${STD_SED_CMDS.dg1} 592SED_CMDS.opt-debug-graph2= ${STD_SED_CMDS.dg2} 593SED_CMDS.opt-debug-graph3= ${STD_SED_CMDS.dg3} 594SED_CMDS.opt-debug-hash= -e 's,\(numEntries\)=[1-9][0-9],\1=<entries>,' 595SED_CMDS.opt-debug-jobs= -e 's,([0-9][0-9]*),(<pid>),' 596SED_CMDS.opt-debug-jobs+= -e 's,pid [0-9][0-9]*,pid <pid>,' 597SED_CMDS.opt-debug-jobs+= -e 's,Process [0-9][0-9]*,Process <pid>,' 598SED_CMDS.opt-debug-jobs+= -e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,' 599SED_CMDS.opt-debug-jobs+= -e 's,Command: ${.SHELL:T},Command: <shell>,' 600# The "-q" may be there or not, see jobs.c, variable shells. 601SED_CMDS.opt-debug-jobs+= -e 's,^\(.Command: <shell>\) -q,\1,' 602SED_CMDS.opt-debug-lint+= ${STD_SED_CMDS.regex} 603SED_CMDS.opt-jobs-no-action= ${STD_SED_CMDS.hide-from-output} 604SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output} 605SED_CMDS.opt-where-am-i= -e '/usr.obj/d' 606# For Compat_RunCommand, useShell == false. 607SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<not found: ...>,' 608# For Compat_RunCommand, useShell == true. 609SED_CMDS.sh-dots+= -e 's,^make: exec(\(.*\)) failed (.*)$$,<not found: \1>,' 610SED_CMDS.sh-dots+= -e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,' 611SED_CMDS.sh-errctl= ${STD_SED_CMDS.dj} 612SED_CMDS.sh-flags= ${STD_SED_CMDS.hide-from-output} 613SED_CMDS.shell-csh= ${STD_SED_CMDS.white-space} 614SED_CMDS.sh-leading-hyphen= ${STD_SED_CMDS.shell} 615SED_CMDS.suff-main+= ${STD_SED_CMDS.dg1} 616SED_CMDS.suff-main-several+= ${STD_SED_CMDS.dg1} 617SED_CMDS.suff-transform-debug+= ${STD_SED_CMDS.dg1} 618SED_CMDS.var-op-shell+= ${STD_SED_CMDS.shell} 619SED_CMDS.var-op-shell+= -e '/command/s,No such.*,not found,' 620SED_CMDS.var-op-shell+= ${STD_SED_CMDS.white-space} 621SED_CMDS.vardebug+= -e 's,${.SHELL},</path/to/shell>,' 622SED_CMDS.varmod-mtime+= -e "s,\(.*\)': .*,\1': <ENOENT>," 623SED_CMDS.varmod-subst-regex+= ${STD_SED_CMDS.regex} 624SED_CMDS.varparse-errors+= ${STD_SED_CMDS.timestamp} 625SED_CMDS.varname-dot-make-meta-ignore_filter+= ${SED_CMDS.meta-ignore} 626SED_CMDS.varname-dot-make-meta-ignore_paths+= ${SED_CMDS.meta-ignore} 627SED_CMDS.varname-dot-make-meta-ignore_patterns+= ${SED_CMDS.meta-ignore} 628SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,' 629SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,' 630SED_CMDS.varname-dot-shell= -e 's, = /[^ ]*, = (details omitted),g' 631SED_CMDS.varname-dot-shell+= -e 's,"/[^" ]*","(details omitted)",g' 632SED_CMDS.varname-dot-shell+= -e 's,\[/[^] ]*\],[(details omitted)],g' 633SED_CMDS.varname-empty= ${.OBJDIR .PARSEDIR .PATH .SHELL .SYSPATH:L:@v@-e '/\\$v/d'@} 634 635# Some tests need an additional round of postprocessing. 636POSTPROC.depsrc-wait= sed -e '/^---/d' -e 's,^\(: Making 3[abc]\)[123]$$,\1,' 637POSTPROC.deptgt-suffixes= awk '/^\#\*\*\* Suffixes/,/^never-stop/' 638POSTPROC.gnode-submake= awk '/Input graph/, /^$$/' 639POSTPROC.varname-dot-make-mode= sed 's,^\(: Making [abc]\)[123]$$,\1,' 640 641# Some tests reuse other tests, which makes them unnecessarily fragile. 642export-all.rawout: export.mk 643unexport.rawout: export.mk 644unexport-env.rawout: export.mk 645 646# End of the configuration section. 647 648# Some standard sed commands, to be used in the SED_CMDS above. 649 650# In tests that use the debugging option -dd, ignore debugging output that is 651# only logged in -DCLEANUP mode. 652STD_SED_CMDS.dd= -e '/^OpenDirs_Done:/d' 653STD_SED_CMDS.dd+= -e '/^CachedDir /d' 654STD_SED_CMDS.dd+= -e 's, ${DEFSYSPATH:U/usr/share/mk} , <defsyspath> ,' 655 656# Omit details such as process IDs from the output of the -dg1 option. 657STD_SED_CMDS.dg1= -e '/\#.* \.$$/d' 658STD_SED_CMDS.dg1+= -e '/\.MAKE.PATH_FILEMON/d' 659STD_SED_CMDS.dg1+= -e '/^\#.*\/mk/d' 660STD_SED_CMDS.dg1+= -e 's, ${DEFSYSPATH:U/usr/share/mk}$$, <defsyspath>,' 661STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,' 662STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,' 663STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.JOBS\.C *=\) .*,\1 <details omitted>,' 664STD_SED_CMDS.dg1+= -e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,' 665STD_SED_CMDS.dg1+= -e 's,^\(MAKE *=\) .*,\1 <details omitted>,' 666STD_SED_CMDS.dg1+= -e 's,^\(\.SHELL *=\) .*,\1 <details omitted>,' 667STD_SED_CMDS.dg1+= -e '/\.SYSPATH/d' 668 669STD_SED_CMDS.dg2= ${STD_SED_CMDS.dg1} 670STD_SED_CMDS.dg2+= -e 's,\(last modified\) ..:..:.. ... ..\, ....,\1 <timestamp>,' 671STD_SED_CMDS.dg3= ${STD_SED_CMDS.dg2} 672 673# Omit details such as process IDs from the output of the -dj option. 674STD_SED_CMDS.dj= \ 675 -e '/Process/d;/JobFinish:/d' \ 676 -e 's,^\(Job_TokenWithdraw\)([0-9]*),\1(<pid>),' \ 677 -e 's,^([0-9][0-9]*) \(withdrew token\),(<pid>) \1,' \ 678 -e 's, \(pid\) [0-9][0-9]*, \1 <pid>,' \ 679 -e 's,^\( Command:\) .*,\1 <shell>,' 680 681# Reduce the noise for tests running with the -n option, since there is no 682# other way to suppress the echoing of the commands. 683STD_SED_CMDS.hide-from-output= \ 684 -e '/^echo hide-from-output/d' \ 685 -e 's,hide-from-output ,,' \ 686 -e 's,hide-from-output,,' 687 688# Normalize the output for error messages from the shell. 689# 690# $shell -c '...' 691# NetBSD sh ...: not found 692# NetBSD ksh ksh: ...: not found 693# bash 5.0.18 bash: ...: command not found 694# bash 5.1.0 bash: line 1: ...: command not found 695# dash dash: 1: ...: not found 696# 697# $shell -c '< /nonexistent' 698# NetBSD sh sh: cannot open /nonexistent: no such file 699# NetBSD ksh ksh: cannot open /nonexistent: No such file or directory 700# bash 5.0.18 bash: /nonexistent: No such file or directory 701# bash 5.1.0 bash: line 1: /nonexistent: No such file or directory 702# dash dash: 1: cannot open /nonexistent: No such file 703# 704# echo '< /nonexistent' | $shell 705# NetBSD sh sh: cannot open /nonexistent: no such file 706# NetBSD ksh ksh: <stdin>[1]: cannot open /nonexistent: No such file or directory 707# bash 5.0.18 bash: line 1: /nonexistent: No such file or directory 708# bash 5.1.0 bash: line 1: /nonexistent: No such file or directory 709# dash dash: 1: cannot open /nonexistent: No such file 710# 711STD_SED_CMDS.shell+= -e 's,^${.SHELL},${.SHELL:T},' 712STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: line [0-9][0-9]*: ,,' 713STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: [0-9][0-9]*: ,,' 714STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: ,,' 715STD_SED_CMDS.shell+= -e 's,: command not found,: not found,' 716 717STD_SED_CMDS.white-space= -e 's, *, ,g' -e 's, *$$,,' 718 719# The actual error messages for a failed regcomp or regexec differ between the 720# implementations. 721STD_SED_CMDS.regex= \ 722 -e 's,\(Regex compilation error:\).*,\1 (details omitted),' 723 724# Normalize timestamps from ':gmtime' or ':localtime' to '<timestamp>'. 725# See STD_SED_CMDS.dg2 for timestamps from the debug log. 726STD_SED_CMDS.timestamp= \ 727 -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>,' 728 729# End of the configuration helpers section. 730 731.-include "Makefile.inc" 732.-include "Makefile.config" 733 734UNIT_TESTS:= ${.PARSEDIR} 735.PATH: ${UNIT_TESTS} 736 737.if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes 738OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@} 739.else 740OUTFILES= ${TESTS:=.out} 741.endif 742 743all: ${OUTFILES} 744 745CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp 746CLEANFILES+= obj*.[och] lib*.a # posix1.mk 747CLEANFILES+= issue* .[ab]* # suffixes.mk 748CLEANDIRS= dir dummy # posix1.mk 749 750clean: 751 rm -f ${CLEANFILES} 752 rm -rf ${CLEANDIRS} 753 754TEST_MAKE?= ${.MAKE} 755TOOL_SED?= sed 756TOOL_TR?= tr 757TOOL_DIFF?= diff 758DIFF_FLAGS?= -u 759 760# ensure consistent results from sort(1) 761LC_ALL= C 762LANG= C 763.export LANG LC_ALL 764 765.if ${.MAKE.MODE:Unormal:Mmeta} != "" 766# we don't need the noise 767_MKMSG_TEST= : 768.endif 769 770# Some Linux systems such as Fedora have deprecated egrep in favor of grep -E. 771.if ${.MAKE.OS:NLinux} == "" 772EGREP= grep -E 773.endif 774# Keep the classical definition for all other systems. Just as the bmake code 775# is kept compatible with C90, the tests are kept compatible with systems that 776# are several decades old and don't follow modern POSIX standards. 777EGREP?= egrep 778 779MAKE_TEST_ENV= EGREP="${EGREP}" 780MAKE_TEST_ENV+= MALLOC_OPTIONS="JA" # for jemalloc 100 781MAKE_TEST_ENV+= MALLOC_CONF="junk:true" # for jemalloc 510 782MAKE_TEST_ENV+= TMPDIR=${TMPDIR} 783 784.if ${.MAKE.OS} == "NetBSD" 785LIMIT_RESOURCES?= ulimit -v 300000 786.endif 787LIMIT_RESOURCES?= : 788 789# Each test is run in a sub-make, to keep the tests from interfering with 790# each other, and because they use different environment variables and 791# command line options. 792.SUFFIXES: .mk .rawout .out 793.mk.rawout: 794 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX} 795 @set -eu; \ 796 ${LIMIT_RESOURCES}; \ 797 cd ${.OBJDIR}; \ 798 env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \ 799 ${TEST_MAKE} \ 800 -r -C ${.CURDIR} -f ${.IMPSRC} \ 801 ${FLAGS.${.PREFIX:T}:U-k} \ 802 > ${.TARGET}.tmp 2>&1 \ 803 && status=$$? || status=$$?; \ 804 echo $$status > ${.TARGET:R}.status 805 @mv ${.TARGET}.tmp ${.TARGET} 806 807# Postprocess the test output to make the output platform-independent. 808# 809# Replace anything after 'stopped in' with unit-tests 810_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' 811# Allow the test files to be placed anywhere. 812_SED_CMDS+= -e 's,\(\.PARSEDIR}\) = `'"/[^']*'"',\1 = <some-dir>,' 813_SED_CMDS+= -e 's,\(\.INCLUDEDFROMDIR}\) = `'"/[^']*'"',\1 = <some-dir>,' 814_SED_CMDS+= -e 's,${TMPDIR},<tmpdir>,g' -e 's,${TMPDIR:tA},<tmpdir>,g' 815# canonicalize ${.OBJDIR} and ${.CURDIR} 816_SED_CMDS+= -e 's,${.CURDIR},<curdir>,g' 817.if ${.OBJDIR} != ${.CURDIR} 818# yes this is inaccurate but none of the tests expect <objdir> anywhere 819# which we get depending on how MAKEOBJDIR is set. 820_SED_CMDS+= -e 's,${.OBJDIR},<curdir>,g' -e 's,${.OBJDIR:tA},<curdir>,g' 821.endif 822# always pretend .MAKE was called 'make' 823_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 824_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 825_SED_CMDS+= -e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,' 826_SED_CMDS+= -e 's,${TEST_MAKE:T:S,.,\\.,g}\(\[[1-9][0-9]*\]:\),make\1,' 827_SED_CMDS+= -e 's,<curdir>/,,g' 828_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 829_SED_CMDS+= -e '/MAKE_VERSION/d' 830_SED_CMDS+= -e '/EGREP=/d' 831 832# on AT&T derived systems: false exits 255 not 1 833.if ${.MAKE.OS:N*BSD} != "" 834_SED_CMDS+= -e 's,\(Error code\) 255,\1 1,' 835.endif 836.if ${.SHELL:T} == "ksh" 837_SED_CMDS+= -e '/^set [+-]v/d' 838.endif 839 840.rawout.out: 841 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \ 842 < ${.IMPSRC} > ${.TARGET}.tmp1 843 @${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 844 @rm ${.TARGET}.tmp1 845 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 846 @mv ${.TARGET}.tmp2 ${.TARGET} 847 848.if empty(DIFF_FLAGS) 849DIFF_ECHO= echo 850.else 851DIFF_ECHO= : 852.endif 853 854# Compare all output files 855test: ${OUTFILES} .PHONY 856 @failed= ; \ 857 for test in ${TESTS}; do \ 858 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out && continue || \ 859 ${DIFF_ECHO} diff ${UNIT_TESTS}/$${test}.exp $${test}.out; \ 860 ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \ 861 || failed="$${failed}$${failed:+ }$${test}" ; \ 862 done ; \ 863 if [ -n "$${failed}" ]; then \ 864 echo "Failed tests: $${failed}" ; false ; \ 865 else \ 866 echo "All tests passed" ; \ 867 fi 868 869accept: 870 @for test in ${TESTS}; do \ 871 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 872 || { echo "Replacing $${test}.exp" ; \ 873 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 874 done 875 876.if exists(${TEST_MAKE}) 877${TESTS:=.rawout}: ${TEST_MAKE} 878# in meta mode, we *know* if a target script is impacted 879# by a makefile change. 880.if ${.MAKE.MODE:Unormal:Mmeta} == "" 881${TESTS:=.rawout}: ${.PARSEDIR}/Makefile 882.endif 883.endif 884 885.-include <obj.mk> 886