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