Makefile revision 1.198
1# $NetBSD: Makefile,v 1.198 2020/11/12 23:35:21 sjg 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+= objdir-writable 192TESTS+= opt 193TESTS+= opt-backwards 194TESTS+= opt-chdir 195TESTS+= opt-debug 196TESTS+= opt-debug-all 197TESTS+= opt-debug-archive 198TESTS+= opt-debug-curdir 199TESTS+= opt-debug-cond 200TESTS+= opt-debug-dir 201TESTS+= opt-debug-errors 202TESTS+= opt-debug-file 203TESTS+= opt-debug-for 204TESTS+= opt-debug-graph1 205TESTS+= opt-debug-graph2 206TESTS+= opt-debug-graph3 207TESTS+= opt-debug-hash 208TESTS+= opt-debug-jobs 209TESTS+= opt-debug-lint 210TESTS+= opt-debug-loud 211TESTS+= opt-debug-meta 212TESTS+= opt-debug-making 213TESTS+= opt-debug-no-rm 214TESTS+= opt-debug-parse 215TESTS+= opt-debug-suff 216TESTS+= opt-debug-targets 217TESTS+= opt-debug-varraw 218TESTS+= opt-debug-var 219TESTS+= opt-debug-x-trace 220TESTS+= opt-define 221TESTS+= opt-env 222TESTS+= opt-file 223TESTS+= opt-ignore 224TESTS+= opt-include-dir 225TESTS+= opt-jobs 226TESTS+= opt-jobs-internal 227TESTS+= opt-keep-going 228TESTS+= opt-m-include-dir 229TESTS+= opt-no-action 230TESTS+= opt-no-action-at-all 231TESTS+= opt-query 232TESTS+= opt-raw 233TESTS+= opt-silent 234TESTS+= opt-touch 235TESTS+= opt-tracefile 236TESTS+= opt-var-expanded 237TESTS+= opt-var-literal 238TESTS+= opt-warnings-as-errors 239TESTS+= opt-where-am-i 240TESTS+= opt-x-reduce-exported 241TESTS+= order 242TESTS+= parse-var 243TESTS+= phony-end 244TESTS+= posix 245TESTS+= # posix1 # broken by reverting POSIX changes 246TESTS+= qequals 247TESTS+= recursive 248TESTS+= sh 249TESTS+= sh-dots 250TESTS+= sh-jobs 251TESTS+= sh-jobs-error 252TESTS+= sh-leading-at 253TESTS+= sh-leading-hyphen 254TESTS+= sh-leading-plus 255TESTS+= sh-meta-chars 256TESTS+= sh-multi-line 257TESTS+= sh-single-line 258TESTS+= shell-csh 259TESTS+= shell-custom 260TESTS+= shell-ksh 261TESTS+= shell-sh 262TESTS+= suff-add-later 263TESTS+= suff-clear-regular 264TESTS+= suff-clear-single 265TESTS+= suff-lookup 266TESTS+= suff-main 267TESTS+= suff-rebuild 268TESTS+= suff-transform-endless 269TESTS+= suff-transform-expand 270TESTS+= suff-transform-select 271TESTS+= sunshcmd 272TESTS+= ternary 273TESTS+= unexport 274TESTS+= unexport-env 275TESTS+= use-inference 276TESTS+= var-class 277TESTS+= var-class-cmdline 278TESTS+= var-class-env 279TESTS+= var-class-global 280TESTS+= var-class-local 281TESTS+= var-class-local-legacy 282TESTS+= var-op 283TESTS+= var-op-append 284TESTS+= var-op-assign 285TESTS+= var-op-default 286TESTS+= var-op-expand 287TESTS+= var-op-shell 288TESTS+= var-op-sunsh 289TESTS+= var-recursive 290TESTS+= varcmd 291TESTS+= vardebug 292TESTS+= varfind 293TESTS+= varmisc 294TESTS+= varmod 295TESTS+= varmod-assign 296TESTS+= varmod-defined 297TESTS+= varmod-edge 298TESTS+= varmod-exclam-shell 299TESTS+= varmod-extension 300TESTS+= varmod-gmtime 301TESTS+= varmod-hash 302TESTS+= varmod-head 303TESTS+= varmod-ifelse 304TESTS+= varmod-l-name-to-value 305TESTS+= varmod-localtime 306TESTS+= varmod-loop 307TESTS+= varmod-match 308TESTS+= varmod-match-escape 309TESTS+= varmod-no-match 310TESTS+= varmod-order 311TESTS+= varmod-order-reverse 312TESTS+= varmod-order-shuffle 313TESTS+= varmod-path 314TESTS+= varmod-quote 315TESTS+= varmod-quote-dollar 316TESTS+= varmod-range 317TESTS+= varmod-remember 318TESTS+= varmod-root 319TESTS+= varmod-select-words 320TESTS+= varmod-shell 321TESTS+= varmod-subst 322TESTS+= varmod-subst-regex 323TESTS+= varmod-sysv 324TESTS+= varmod-tail 325TESTS+= varmod-to-abs 326TESTS+= varmod-to-lower 327TESTS+= varmod-to-many-words 328TESTS+= varmod-to-one-word 329TESTS+= varmod-to-separator 330TESTS+= varmod-to-upper 331TESTS+= varmod-undefined 332TESTS+= varmod-unique 333TESTS+= varname 334TESTS+= varname-dollar 335TESTS+= varname-dot-alltargets 336TESTS+= varname-dot-curdir 337TESTS+= varname-dot-includes 338TESTS+= varname-dot-includedfromdir 339TESTS+= varname-dot-includedfromfile 340TESTS+= varname-dot-libs 341TESTS+= varname-dot-make-dependfile 342TESTS+= varname-dot-make-expand_variables 343TESTS+= varname-dot-make-exported 344TESTS+= varname-dot-make-jobs 345TESTS+= varname-dot-make-jobs-prefix 346TESTS+= varname-dot-make-level 347TESTS+= varname-dot-make-makefile_preference 348TESTS+= varname-dot-make-makefiles 349TESTS+= varname-dot-make-meta-bailiwick 350TESTS+= varname-dot-make-meta-created 351TESTS+= varname-dot-make-meta-files 352TESTS+= varname-dot-make-meta-ignore_filter 353TESTS+= varname-dot-make-meta-ignore_paths 354TESTS+= varname-dot-make-meta-ignore_patterns 355TESTS+= varname-dot-make-meta-prefix 356TESTS+= varname-dot-make-mode 357TESTS+= varname-dot-make-path_filemon 358TESTS+= varname-dot-make-pid 359TESTS+= varname-dot-make-ppid 360TESTS+= varname-dot-make-save_dollars 361TESTS+= varname-dot-makeoverrides 362TESTS+= varname-dot-newline 363TESTS+= varname-dot-objdir 364TESTS+= varname-dot-parsedir 365TESTS+= varname-dot-parsefile 366TESTS+= varname-dot-path 367TESTS+= varname-dot-shell 368TESTS+= varname-dot-targets 369TESTS+= varname-empty 370TESTS+= varname-make 371TESTS+= varname-make_print_var_on_error 372TESTS+= varname-make_print_var_on_error-jobs 373TESTS+= varname-makefile 374TESTS+= varname-makeflags 375TESTS+= varname-pwd 376TESTS+= varname-vpath 377TESTS+= varparse-dynamic 378TESTS+= varparse-errors 379TESTS+= varparse-mod 380TESTS+= varparse-undef-partial 381TESTS+= varquote 382 383.if ${.OBJDIR} != ${.CURDIR} 384RO_OBJDIR:= ${.OBJDIR}/roobj 385.else 386RO_OBJDIR:= ${TMPDIR:U/tmp}/roobj 387.endif 388# Additional environment variables for some of the tests. 389# The base environment is -i PATH="$PATH". 390ENV.depsrc-optional+= TZ=UTC 391ENV.envfirst= FROM_ENV=value-from-env 392ENV.objdir-writable+= RO_OBJDIR=${RO_OBJDIR} 393ENV.varmisc= FROM_ENV=env 394ENV.varmisc+= FROM_ENV_BEFORE=env 395ENV.varmisc+= FROM_ENV_AFTER=env 396ENV.varmod-localtime+= TZ=Europe/Berlin 397ENV.varname-vpath+= VPATH=varname-vpath.dir:varname-vpath.dir2 398 399# Override make flags for some of the tests; default is -k. 400# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of 401# settings FLAGS.test=-dv here, since that is closer to the test code. 402FLAGS.cond-func-make= via-cmdline 403FLAGS.directive-ifmake= first second 404FLAGS.doterror= # none, especially not -k 405FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain' 406 407# Some tests need extra postprocessing. 408SED_CMDS.job-output-long-lines= \ 409 ${:D Job separators on their own line are ok. } \ 410 -e '/^--- job-[ab] ---$$/d' \ 411 ${:D Plain output lines are ok as well. } \ 412 ${:D They may come in multiples of 1024 or as 10000. } \ 413 -e '/^aa*$$/d' \ 414 -e '/^bb*$$/d' \ 415 ${:D The following lines should rather not occur since the job } \ 416 ${:D marker should always be at the beginning of the line. } \ 417 -e '/^aa*--- job-b ---$$/d' \ 418 -e '/^bb*--- job-a ---$$/d' 419SED_CMDS.objdir-writable= -e 's,${RO_OBJDIR},OBJDIR/roobj,g' 420SED_CMDS.opt-debug-graph1= \ 421 -e 's,${.CURDIR},CURDIR,' 422SED_CMDS.opt-debug-graph1+= \ 423 -e '/Global Variables:/,/Suffixes:/d' 424SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<normalized: ...: not found>,' 425SED_CMDS.opt-debug-jobs= -e 's,([0-9][0-9]*),(<pid>),' 426SED_CMDS.opt-debug-jobs+= -e 's,pid [0-9][0-9]*,pid <pid>,' 427SED_CMDS.opt-debug-jobs+= -e 's,Process [0-9][0-9]*,Process <pid>,' 428SED_CMDS.opt-debug-jobs+= -e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,' 429# The "-q" may be there or not, see jobs.c, variable shells. 430SED_CMDS.opt-debug-jobs+= -e 's,^\(.Command: sh\) -q,\1,' 431SED_CMDS.var-op-shell+= -e 's,^${.SHELL:T}: ,,' 432SED_CMDS.var-op-shell+= -e '/command/s,No such.*,not found,' 433SED_CMDS.varmod-subst-regex+= \ 434 -e 's,\(Regex compilation error:\).*,\1 (details omitted),' 435SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,' 436SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,' 437SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,' 438SED_CMDS.varname-dot-shell= -e 's, = /[^ ]*, = (details omitted),g' 439SED_CMDS.varname-dot-shell+= -e 's,"/[^" ]*","(details omitted)",g' 440SED_CMDS.varname-dot-shell+= -e 's,\[/[^] ]*\],[(details omitted)],g' 441 442# Some tests need an additional round of postprocessing. 443POSTPROC.deptgt-suffixes= \ 444 ${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p' 445POSTPROC.gnode-submake= awk '/Input graph/, /^$$/' 446POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p' 447 448# Some tests reuse other tests, which makes them unnecessarily fragile. 449export-all.rawout: export.mk 450unexport.rawout: export.mk 451unexport-env.rawout: export.mk 452 453# End of the configuration section. 454 455.MAIN: all 456 457UNIT_TESTS:= ${.PARSEDIR} 458.PATH: ${UNIT_TESTS} 459 460.if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes 461OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@} 462.else 463OUTFILES= ${TESTS:=.out} 464.endif 465 466all: ${OUTFILES} 467 468CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp 469CLEANFILES+= obj*.[och] lib*.a # posix1.mk 470CLEANFILES+= issue* .[ab]* # suffixes.mk 471CLEANDIRS= dir dummy # posix1.mk 472 473clean: 474 rm -f ${CLEANFILES} 475 rm -rf ${CLEANDIRS} 476 477TEST_MAKE?= ${.MAKE} 478TOOL_SED?= sed 479 480# ensure consistent results from sort(1) 481LC_ALL= C 482LANG= C 483.export LANG LC_ALL 484 485MAKE_TEST_ENV?= MALLOC_OPTIONS="JA" # for jemalloc 486 487# Each test is run in a sub-make, to keep the tests for interfering with 488# each other, and because they use different environment variables and 489# command line options. 490.SUFFIXES: .mk .rawout .out 491.mk.rawout: 492 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX} 493 @set -eu; \ 494 cd ${.OBJDIR}; \ 495 env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \ 496 ${TEST_MAKE} \ 497 -r -C ${.CURDIR} -f ${.IMPSRC} \ 498 ${FLAGS.${.PREFIX:T}:U-k} \ 499 > ${.TARGET}.tmp 2>&1 \ 500 && status=$$? || status=$$?; \ 501 echo $$status > ${.TARGET:R}.status 502 @mv ${.TARGET}.tmp ${.TARGET} 503 504# Postprocess the test output so that the results can be compared. 505# 506# always pretend .MAKE was called 'make' 507_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 508_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 509# replace anything after 'stopped in' with unit-tests 510_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' 511# strip ${.CURDIR}/ from the output 512_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' 513_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 514 515.rawout.out: 516 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \ 517 < ${.IMPSRC} > ${.TARGET}.tmp1 518 @${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 519 @rm ${.TARGET}.tmp1 520 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 521 @mv ${.TARGET}.tmp2 ${.TARGET} 522 523# Compare all output files 524test: ${OUTFILES} .PHONY 525 @failed= ; \ 526 for test in ${TESTS}; do \ 527 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 528 || failed="$${failed}$${failed:+ }$${test}" ; \ 529 done ; \ 530 if [ -n "$${failed}" ]; then \ 531 echo "Failed tests: $${failed}" ; false ; \ 532 else \ 533 echo "All tests passed" ; \ 534 fi 535 536accept: 537 @for test in ${TESTS}; do \ 538 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 539 || { echo "Replacing $${test}.exp" ; \ 540 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 541 done 542 543# Note: only works for adding tests. 544# To remove a test, the $$mi file must be edited manually. 545sync-mi: 546 @set -eu; \ 547 cd "${MAKEFILE:tA:H}/../../.."; \ 548 mi="distrib/sets/lists/tests/mi"; \ 549 cvs update "$$mi"; \ 550 testsdir="usr.bin/make/unit-tests"; \ 551 fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \ 552 cat "$$mi" > "$$mi.tmp"; \ 553 (cd "$$testsdir" && ls *.exp *.mk) | xargs printf "$$fmt" >> "$$mi.tmp"; \ 554 distrib/sets/fmt-list "$$mi.tmp"; \ 555 mv "$$mi.tmp" "$$mi"; \ 556 cvs diff "$$mi" || true 557 558.if exists(${TEST_MAKE}) 559${TESTS:=.rawout}: ${TEST_MAKE} 560# in meta mode, we *know* if a target script is impacted 561# by a makefile change. 562.if ${.MAKE.MODE:Unormal:Mmeta} == "" 563${TESTS:=.rawout}: ${.PARSEDIR}/Makefile 564.endif 565.endif 566 567.-include <bsd.obj.mk> 568