Makefile revision 1.197
1# $NetBSD: Makefile,v 1.197 2020/11/10 22:23:37 rillig Exp $ 2# 3# Unit tests for make(1) 4# 5# The main targets are: 6# 7# all: 8# run all the tests 9# test: 10# run 'all', and compare to expected results 11# accept: 12# move generated output to expected results 13# 14# Settable variables 15# 16# TEST_MAKE 17# The make program to be tested. 18# 19# 20# Adding a test case 21# 22# Each feature should get its own set of tests in its own suitably 23# named makefile (*.mk), with its own set of expected results (*.exp), 24# and it should be added to the TESTS list. 25# 26# Any added files must also be added to src/distrib/sets/lists/tests/mi. 27# To do that, just run "make sync-mi" in this directory. 28# 29# A few *.mk files are helper files for other tests (such as include-sub.mk) 30# and are thus not added to TESTS. Such files must be ignored in 31# src/tests/usr.bin/make/t_make.sh. 32# 33 34# Each test is in a sub-makefile. 35# Keep the list sorted. 36# Any test that is commented out must be ignored in 37# src/tests/usr.bin/make/t_make.sh as well. 38TESTS+= archive 39TESTS+= archive-suffix 40TESTS+= cmd-errors 41TESTS+= cmd-errors-lint 42TESTS+= cmd-interrupt 43TESTS+= cmdline 44TESTS+= cmdline-undefined 45TESTS+= comment 46TESTS+= cond-cmp-numeric 47TESTS+= cond-cmp-numeric-eq 48TESTS+= cond-cmp-numeric-ge 49TESTS+= cond-cmp-numeric-gt 50TESTS+= cond-cmp-numeric-le 51TESTS+= cond-cmp-numeric-lt 52TESTS+= cond-cmp-numeric-ne 53TESTS+= cond-cmp-string 54TESTS+= cond-cmp-unary 55TESTS+= cond-func 56TESTS+= cond-func-commands 57TESTS+= cond-func-defined 58TESTS+= cond-func-empty 59TESTS+= cond-func-exists 60TESTS+= cond-func-make 61TESTS+= cond-func-target 62TESTS+= cond-late 63TESTS+= cond-op 64TESTS+= cond-op-and 65TESTS+= cond-op-and-lint 66TESTS+= cond-op-not 67TESTS+= cond-op-or 68TESTS+= cond-op-or-lint 69TESTS+= cond-op-parentheses 70TESTS+= cond-short 71TESTS+= cond-token-number 72TESTS+= cond-token-plain 73TESTS+= cond-token-string 74TESTS+= cond-token-var 75TESTS+= cond-undef-lint 76TESTS+= cond1 77TESTS+= counter 78TESTS+= counter-append 79TESTS+= dep 80TESTS+= dep-colon 81TESTS+= dep-colon-bug-cross-file 82TESTS+= dep-double-colon 83TESTS+= dep-double-colon-indep 84TESTS+= dep-exclam 85TESTS+= dep-none 86TESTS+= dep-percent 87TESTS+= dep-var 88TESTS+= dep-wildcards 89TESTS+= depsrc 90TESTS+= depsrc-end 91TESTS+= depsrc-exec 92TESTS+= depsrc-ignore 93TESTS+= depsrc-made 94TESTS+= depsrc-make 95TESTS+= depsrc-meta 96TESTS+= depsrc-nometa 97TESTS+= depsrc-nometa_cmp 98TESTS+= depsrc-nopath 99TESTS+= depsrc-notmain 100TESTS+= depsrc-optional 101TESTS+= depsrc-phony 102TESTS+= depsrc-precious 103TESTS+= depsrc-recursive 104TESTS+= depsrc-silent 105TESTS+= depsrc-use 106TESTS+= depsrc-usebefore 107TESTS+= depsrc-usebefore-double-colon 108TESTS+= depsrc-wait 109TESTS+= deptgt 110TESTS+= deptgt-begin 111TESTS+= deptgt-default 112TESTS+= deptgt-delete_on_error 113TESTS+= deptgt-end 114TESTS+= deptgt-end-jobs 115TESTS+= deptgt-error 116TESTS+= deptgt-ignore 117TESTS+= deptgt-interrupt 118TESTS+= deptgt-main 119TESTS+= deptgt-makeflags 120TESTS+= deptgt-no_parallel 121TESTS+= deptgt-nopath 122TESTS+= deptgt-notparallel 123TESTS+= deptgt-objdir 124TESTS+= deptgt-order 125TESTS+= deptgt-path 126TESTS+= deptgt-path-suffix 127TESTS+= deptgt-phony 128TESTS+= deptgt-precious 129TESTS+= deptgt-shell 130TESTS+= deptgt-silent 131TESTS+= deptgt-stale 132TESTS+= deptgt-suffixes 133TESTS+= dir 134TESTS+= dir-expand-path 135TESTS+= directive 136TESTS+= directive-dinclude 137TESTS+= directive-elif 138TESTS+= directive-elifdef 139TESTS+= directive-elifmake 140TESTS+= directive-elifndef 141TESTS+= directive-elifnmake 142TESTS+= directive-else 143TESTS+= directive-endif 144TESTS+= directive-error 145TESTS+= directive-export 146TESTS+= directive-export-env 147TESTS+= directive-export-gmake 148TESTS+= directive-export-literal 149TESTS+= directive-for 150TESTS+= directive-for-generating-endif 151TESTS+= directive-hyphen-include 152TESTS+= directive-if 153TESTS+= directive-if-nested 154TESTS+= directive-ifdef 155TESTS+= directive-ifmake 156TESTS+= directive-ifndef 157TESTS+= directive-ifnmake 158TESTS+= directive-include 159TESTS+= directive-include-fatal 160TESTS+= directive-info 161TESTS+= directive-sinclude 162TESTS+= directive-undef 163TESTS+= directive-unexport 164TESTS+= directive-unexport-env 165TESTS+= directive-warning 166TESTS+= dollar 167TESTS+= doterror 168TESTS+= dotwait 169TESTS+= envfirst 170TESTS+= error 171TESTS+= # escape # broken by reverting POSIX changes 172TESTS+= export 173TESTS+= export-all 174TESTS+= export-env 175TESTS+= export-variants 176TESTS+= forloop 177TESTS+= forsubst 178TESTS+= gnode-submake 179TESTS+= hanoi-include 180TESTS+= impsrc 181TESTS+= include-main 182TESTS+= job-flags 183TESTS+= job-output-long-lines 184TESTS+= lint 185TESTS+= make-exported 186TESTS+= moderrs 187TESTS+= modmatch 188TESTS+= modmisc 189TESTS+= modts 190TESTS+= modword 191TESTS+= opt 192TESTS+= opt-backwards 193TESTS+= opt-chdir 194TESTS+= opt-debug 195TESTS+= opt-debug-all 196TESTS+= opt-debug-archive 197TESTS+= opt-debug-curdir 198TESTS+= opt-debug-cond 199TESTS+= opt-debug-dir 200TESTS+= opt-debug-errors 201TESTS+= opt-debug-file 202TESTS+= opt-debug-for 203TESTS+= opt-debug-graph1 204TESTS+= opt-debug-graph2 205TESTS+= opt-debug-graph3 206TESTS+= opt-debug-hash 207TESTS+= opt-debug-jobs 208TESTS+= opt-debug-lint 209TESTS+= opt-debug-loud 210TESTS+= opt-debug-meta 211TESTS+= opt-debug-making 212TESTS+= opt-debug-no-rm 213TESTS+= opt-debug-parse 214TESTS+= opt-debug-suff 215TESTS+= opt-debug-targets 216TESTS+= opt-debug-varraw 217TESTS+= opt-debug-var 218TESTS+= opt-debug-x-trace 219TESTS+= opt-define 220TESTS+= opt-env 221TESTS+= opt-file 222TESTS+= opt-ignore 223TESTS+= opt-include-dir 224TESTS+= opt-jobs 225TESTS+= opt-jobs-internal 226TESTS+= opt-keep-going 227TESTS+= opt-m-include-dir 228TESTS+= opt-no-action 229TESTS+= opt-no-action-at-all 230TESTS+= opt-query 231TESTS+= opt-raw 232TESTS+= opt-silent 233TESTS+= opt-touch 234TESTS+= opt-tracefile 235TESTS+= opt-var-expanded 236TESTS+= opt-var-literal 237TESTS+= opt-warnings-as-errors 238TESTS+= opt-where-am-i 239TESTS+= opt-x-reduce-exported 240TESTS+= order 241TESTS+= parse-var 242TESTS+= phony-end 243TESTS+= posix 244TESTS+= # posix1 # broken by reverting POSIX changes 245TESTS+= qequals 246TESTS+= recursive 247TESTS+= sh 248TESTS+= sh-dots 249TESTS+= sh-jobs 250TESTS+= sh-jobs-error 251TESTS+= sh-leading-at 252TESTS+= sh-leading-hyphen 253TESTS+= sh-leading-plus 254TESTS+= sh-meta-chars 255TESTS+= sh-multi-line 256TESTS+= sh-single-line 257TESTS+= shell-csh 258TESTS+= shell-custom 259TESTS+= shell-ksh 260TESTS+= shell-sh 261TESTS+= suff-add-later 262TESTS+= suff-clear-regular 263TESTS+= suff-clear-single 264TESTS+= suff-lookup 265TESTS+= suff-main 266TESTS+= suff-rebuild 267TESTS+= suff-transform-endless 268TESTS+= suff-transform-expand 269TESTS+= suff-transform-select 270TESTS+= sunshcmd 271TESTS+= ternary 272TESTS+= unexport 273TESTS+= unexport-env 274TESTS+= use-inference 275TESTS+= var-class 276TESTS+= var-class-cmdline 277TESTS+= var-class-env 278TESTS+= var-class-global 279TESTS+= var-class-local 280TESTS+= var-class-local-legacy 281TESTS+= var-op 282TESTS+= var-op-append 283TESTS+= var-op-assign 284TESTS+= var-op-default 285TESTS+= var-op-expand 286TESTS+= var-op-shell 287TESTS+= var-op-sunsh 288TESTS+= var-recursive 289TESTS+= varcmd 290TESTS+= vardebug 291TESTS+= varfind 292TESTS+= varmisc 293TESTS+= varmod 294TESTS+= varmod-assign 295TESTS+= varmod-defined 296TESTS+= varmod-edge 297TESTS+= varmod-exclam-shell 298TESTS+= varmod-extension 299TESTS+= varmod-gmtime 300TESTS+= varmod-hash 301TESTS+= varmod-head 302TESTS+= varmod-ifelse 303TESTS+= varmod-l-name-to-value 304TESTS+= varmod-localtime 305TESTS+= varmod-loop 306TESTS+= varmod-match 307TESTS+= varmod-match-escape 308TESTS+= varmod-no-match 309TESTS+= varmod-order 310TESTS+= varmod-order-reverse 311TESTS+= varmod-order-shuffle 312TESTS+= varmod-path 313TESTS+= varmod-quote 314TESTS+= varmod-quote-dollar 315TESTS+= varmod-range 316TESTS+= varmod-remember 317TESTS+= varmod-root 318TESTS+= varmod-select-words 319TESTS+= varmod-shell 320TESTS+= varmod-subst 321TESTS+= varmod-subst-regex 322TESTS+= varmod-sysv 323TESTS+= varmod-tail 324TESTS+= varmod-to-abs 325TESTS+= varmod-to-lower 326TESTS+= varmod-to-many-words 327TESTS+= varmod-to-one-word 328TESTS+= varmod-to-separator 329TESTS+= varmod-to-upper 330TESTS+= varmod-undefined 331TESTS+= varmod-unique 332TESTS+= varname 333TESTS+= varname-dollar 334TESTS+= varname-dot-alltargets 335TESTS+= varname-dot-curdir 336TESTS+= varname-dot-includes 337TESTS+= varname-dot-includedfromdir 338TESTS+= varname-dot-includedfromfile 339TESTS+= varname-dot-libs 340TESTS+= varname-dot-make-dependfile 341TESTS+= varname-dot-make-expand_variables 342TESTS+= varname-dot-make-exported 343TESTS+= varname-dot-make-jobs 344TESTS+= varname-dot-make-jobs-prefix 345TESTS+= varname-dot-make-level 346TESTS+= varname-dot-make-makefile_preference 347TESTS+= varname-dot-make-makefiles 348TESTS+= varname-dot-make-meta-bailiwick 349TESTS+= varname-dot-make-meta-created 350TESTS+= varname-dot-make-meta-files 351TESTS+= varname-dot-make-meta-ignore_filter 352TESTS+= varname-dot-make-meta-ignore_paths 353TESTS+= varname-dot-make-meta-ignore_patterns 354TESTS+= varname-dot-make-meta-prefix 355TESTS+= varname-dot-make-mode 356TESTS+= varname-dot-make-path_filemon 357TESTS+= varname-dot-make-pid 358TESTS+= varname-dot-make-ppid 359TESTS+= varname-dot-make-save_dollars 360TESTS+= varname-dot-makeoverrides 361TESTS+= varname-dot-newline 362TESTS+= varname-dot-objdir 363TESTS+= varname-dot-parsedir 364TESTS+= varname-dot-parsefile 365TESTS+= varname-dot-path 366TESTS+= varname-dot-shell 367TESTS+= varname-dot-targets 368TESTS+= varname-empty 369TESTS+= varname-make 370TESTS+= varname-make_print_var_on_error 371TESTS+= varname-make_print_var_on_error-jobs 372TESTS+= varname-makefile 373TESTS+= varname-makeflags 374TESTS+= varname-pwd 375TESTS+= varname-vpath 376TESTS+= varparse-dynamic 377TESTS+= varparse-errors 378TESTS+= varparse-mod 379TESTS+= varparse-undef-partial 380TESTS+= varquote 381 382# Additional environment variables for some of the tests. 383# The base environment is -i PATH="$PATH". 384ENV.depsrc-optional+= TZ=UTC 385ENV.envfirst= FROM_ENV=value-from-env 386ENV.varmisc= FROM_ENV=env 387ENV.varmisc+= FROM_ENV_BEFORE=env 388ENV.varmisc+= FROM_ENV_AFTER=env 389ENV.varmod-localtime+= TZ=Europe/Berlin 390ENV.varname-vpath+= VPATH=varname-vpath.dir:varname-vpath.dir2 391 392# Override make flags for some of the tests; default is -k. 393# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of 394# settings FLAGS.test=-dv here, since that is closer to the test code. 395FLAGS.cond-func-make= via-cmdline 396FLAGS.directive-ifmake= first second 397FLAGS.doterror= # none, especially not -k 398FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain' 399 400# Some tests need extra postprocessing. 401SED_CMDS.job-output-long-lines= \ 402 ${:D Job separators on their own line are ok. } \ 403 -e '/^--- job-[ab] ---$$/d' \ 404 ${:D Plain output lines are ok as well. } \ 405 ${:D They may come in multiples of 1024 or as 10000. } \ 406 -e '/^aa*$$/d' \ 407 -e '/^bb*$$/d' \ 408 ${:D The following lines should rather not occur since the job } \ 409 ${:D marker should always be at the beginning of the line. } \ 410 -e '/^aa*--- job-b ---$$/d' \ 411 -e '/^bb*--- job-a ---$$/d' 412SED_CMDS.opt-debug-graph1= \ 413 -e 's,${.CURDIR},CURDIR,' 414SED_CMDS.opt-debug-graph1+= \ 415 -e '/Global Variables:/,/Suffixes:/d' 416SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<normalized: ...: not found>,' 417SED_CMDS.opt-debug-jobs= -e 's,([0-9][0-9]*),(<pid>),' 418SED_CMDS.opt-debug-jobs+= -e 's,pid [0-9][0-9]*,pid <pid>,' 419SED_CMDS.opt-debug-jobs+= -e 's,Process [0-9][0-9]*,Process <pid>,' 420SED_CMDS.opt-debug-jobs+= -e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,' 421# The "-q" may be there or not, see jobs.c, variable shells. 422SED_CMDS.opt-debug-jobs+= -e 's,^\(.Command: sh\) -q,\1,' 423SED_CMDS.var-op-shell+= -e 's,^${.SHELL:T}: ,,' 424SED_CMDS.var-op-shell+= -e '/command/s,No such.*,not found,' 425SED_CMDS.varmod-subst-regex+= \ 426 -e 's,\(Regex compilation error:\).*,\1 (details omitted),' 427SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,' 428SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,' 429SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,' 430SED_CMDS.varname-dot-shell= -e 's, = /[^ ]*, = (details omitted),g' 431SED_CMDS.varname-dot-shell+= -e 's,"/[^" ]*","(details omitted)",g' 432SED_CMDS.varname-dot-shell+= -e 's,\[/[^] ]*\],[(details omitted)],g' 433 434# Some tests need an additional round of postprocessing. 435POSTPROC.deptgt-suffixes= \ 436 ${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p' 437POSTPROC.gnode-submake= awk '/Input graph/, /^$$/' 438POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p' 439 440# Some tests reuse other tests, which makes them unnecessarily fragile. 441export-all.rawout: export.mk 442unexport.rawout: export.mk 443unexport-env.rawout: export.mk 444 445# End of the configuration section. 446 447.MAIN: all 448 449UNIT_TESTS:= ${.PARSEDIR} 450.PATH: ${UNIT_TESTS} 451 452.if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes 453OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@} 454.else 455OUTFILES= ${TESTS:=.out} 456.endif 457 458all: ${OUTFILES} 459 460CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp 461CLEANFILES+= obj*.[och] lib*.a # posix1.mk 462CLEANFILES+= issue* .[ab]* # suffixes.mk 463CLEANDIRS= dir dummy # posix1.mk 464 465clean: 466 rm -f ${CLEANFILES} 467 rm -rf ${CLEANDIRS} 468 469TEST_MAKE?= ${.MAKE} 470TOOL_SED?= sed 471 472# ensure consistent results from sort(1) 473LC_ALL= C 474LANG= C 475.export LANG LC_ALL 476 477MAKE_TEST_ENV?= MALLOC_OPTIONS="JA" # for jemalloc 478 479# Each test is run in a sub-make, to keep the tests for interfering with 480# each other, and because they use different environment variables and 481# command line options. 482.SUFFIXES: .mk .rawout .out 483.mk.rawout: 484 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX} 485 @set -eu; \ 486 cd ${.OBJDIR}; \ 487 env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \ 488 ${TEST_MAKE} \ 489 -r -C ${.CURDIR} -f ${.IMPSRC} \ 490 ${FLAGS.${.PREFIX:T}:U-k} \ 491 > ${.TARGET}.tmp 2>&1 \ 492 && status=$$? || status=$$?; \ 493 echo $$status > ${.TARGET:R}.status 494 @mv ${.TARGET}.tmp ${.TARGET} 495 496# Postprocess the test output so that the results can be compared. 497# 498# always pretend .MAKE was called 'make' 499_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 500_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 501# replace anything after 'stopped in' with unit-tests 502_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' 503# strip ${.CURDIR}/ from the output 504_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' 505_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 506 507.rawout.out: 508 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \ 509 < ${.IMPSRC} > ${.TARGET}.tmp1 510 @${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 511 @rm ${.TARGET}.tmp1 512 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 513 @mv ${.TARGET}.tmp2 ${.TARGET} 514 515# Compare all output files 516test: ${OUTFILES} .PHONY 517 @failed= ; \ 518 for test in ${TESTS}; do \ 519 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 520 || failed="$${failed}$${failed:+ }$${test}" ; \ 521 done ; \ 522 if [ -n "$${failed}" ]; then \ 523 echo "Failed tests: $${failed}" ; false ; \ 524 else \ 525 echo "All tests passed" ; \ 526 fi 527 528accept: 529 @for test in ${TESTS}; do \ 530 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 531 || { echo "Replacing $${test}.exp" ; \ 532 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 533 done 534 535# Note: only works for adding tests. 536# To remove a test, the $$mi file must be edited manually. 537sync-mi: 538 @set -eu; \ 539 cd "${MAKEFILE:tA:H}/../../.."; \ 540 mi="distrib/sets/lists/tests/mi"; \ 541 cvs update "$$mi"; \ 542 testsdir="usr.bin/make/unit-tests"; \ 543 fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \ 544 cat "$$mi" > "$$mi.tmp"; \ 545 (cd "$$testsdir" && ls *.exp *.mk) | xargs printf "$$fmt" >> "$$mi.tmp"; \ 546 distrib/sets/fmt-list "$$mi.tmp"; \ 547 mv "$$mi.tmp" "$$mi"; \ 548 cvs diff "$$mi" || true 549 550.if exists(${TEST_MAKE}) 551${TESTS:=.rawout}: ${TEST_MAKE} 552# in meta mode, we *know* if a target script is impacted 553# by a makefile change. 554.if ${.MAKE.MODE:Unormal:Mmeta} == "" 555${TESTS:=.rawout}: ${.PARSEDIR}/Makefile 556.endif 557.endif 558 559.-include <bsd.obj.mk> 560