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