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