Makefile revision 1.152
1# $NetBSD: Makefile,v 1.152 2020/09/25 23:24:49 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-literal 141TESTS+= directive-for 142TESTS+= directive-for-generating-endif 143TESTS+= directive-hyphen-include 144TESTS+= directive-if 145TESTS+= directive-ifdef 146TESTS+= directive-ifmake 147TESTS+= directive-ifndef 148TESTS+= directive-ifnmake 149TESTS+= directive-include 150TESTS+= directive-include-fatal 151TESTS+= directive-info 152TESTS+= directive-sinclude 153TESTS+= directive-undef 154TESTS+= directive-unexport 155TESTS+= directive-unexport-env 156TESTS+= directive-warning 157TESTS+= directives 158TESTS+= dollar 159TESTS+= doterror 160TESTS+= dotwait 161TESTS+= envfirst 162TESTS+= error 163TESTS+= # escape # broken by reverting POSIX changes 164TESTS+= export 165TESTS+= export-all 166TESTS+= export-env 167TESTS+= export-variants 168TESTS+= forloop 169TESTS+= forsubst 170TESTS+= impsrc 171TESTS+= include-main 172TESTS+= lint 173TESTS+= make-exported 174TESTS+= misc 175TESTS+= moderrs 176TESTS+= modmatch 177TESTS+= modmisc 178TESTS+= modts 179TESTS+= modword 180TESTS+= opt 181TESTS+= opt-backwards 182TESTS+= opt-chdir 183TESTS+= opt-debug 184TESTS+= opt-debug-all 185TESTS+= opt-debug-archive 186TESTS+= opt-debug-curdir 187TESTS+= opt-debug-cond 188TESTS+= opt-debug-dir 189TESTS+= opt-debug-errors 190TESTS+= opt-debug-file 191TESTS+= opt-debug-for 192TESTS+= opt-debug-graph1 193TESTS+= opt-debug-graph2 194TESTS+= opt-debug-graph3 195TESTS+= opt-debug-hash 196TESTS+= opt-debug-jobs 197TESTS+= opt-debug-lint 198TESTS+= opt-debug-loud 199TESTS+= opt-debug-meta 200TESTS+= opt-debug-making 201TESTS+= opt-debug-no-rm 202TESTS+= opt-debug-parse 203TESTS+= opt-debug-suff 204TESTS+= opt-debug-targets 205TESTS+= opt-debug-varraw 206TESTS+= opt-debug-var 207TESTS+= opt-debug-x-trace 208TESTS+= opt-define 209TESTS+= opt-env 210TESTS+= opt-file 211TESTS+= opt-ignore 212TESTS+= opt-include-dir 213TESTS+= opt-jobs 214TESTS+= opt-jobs-internal 215TESTS+= opt-keep-going 216TESTS+= opt-m-include-dir 217TESTS+= opt-no-action 218TESTS+= opt-no-action-at-all 219TESTS+= opt-query 220TESTS+= opt-raw 221TESTS+= opt-silent 222TESTS+= opt-touch 223TESTS+= opt-tracefile 224TESTS+= opt-var-expanded 225TESTS+= opt-var-literal 226TESTS+= opt-warnings-as-errors 227TESTS+= opt-where-am-i 228TESTS+= opt-x-reduce-exported 229TESTS+= order 230TESTS+= phony-end 231TESTS+= posix 232TESTS+= # posix1 # broken by reverting POSIX changes 233TESTS+= qequals 234TESTS+= recursive 235TESTS+= sh 236TESTS+= sh-dots 237TESTS+= sh-jobs 238TESTS+= sh-jobs-error 239TESTS+= sh-leading-at 240TESTS+= sh-leading-hyphen 241TESTS+= sh-leading-plus 242TESTS+= sh-meta-chars 243TESTS+= sh-multi-line 244TESTS+= sh-single-line 245TESTS+= # suffixes # runs into an endless loop (try -dA) 246TESTS+= suff-rebuild 247TESTS+= sunshcmd 248TESTS+= sysv 249TESTS+= ternary 250TESTS+= unexport 251TESTS+= unexport-env 252TESTS+= use-inference 253TESTS+= var-class 254TESTS+= var-class-cmdline 255TESTS+= var-class-env 256TESTS+= var-class-global 257TESTS+= var-class-local 258TESTS+= var-class-local-legacy 259TESTS+= var-op 260TESTS+= var-op-append 261TESTS+= var-op-assign 262TESTS+= var-op-default 263TESTS+= var-op-expand 264TESTS+= var-op-shell 265TESTS+= varcmd 266TESTS+= vardebug 267TESTS+= varfind 268TESTS+= varmisc 269TESTS+= varmod 270TESTS+= varmod-assign 271TESTS+= varmod-defined 272TESTS+= varmod-edge 273TESTS+= varmod-exclam-shell 274TESTS+= varmod-extension 275TESTS+= varmod-gmtime 276TESTS+= varmod-hash 277TESTS+= varmod-head 278TESTS+= varmod-ifelse 279TESTS+= varmod-l-name-to-value 280TESTS+= varmod-localtime 281TESTS+= varmod-loop 282TESTS+= varmod-match 283TESTS+= varmod-match-escape 284TESTS+= varmod-no-match 285TESTS+= varmod-order 286TESTS+= varmod-order-reverse 287TESTS+= varmod-order-shuffle 288TESTS+= varmod-path 289TESTS+= varmod-quote 290TESTS+= varmod-quote-dollar 291TESTS+= varmod-range 292TESTS+= varmod-remember 293TESTS+= varmod-root 294TESTS+= varmod-select-words 295TESTS+= varmod-shell 296TESTS+= varmod-subst 297TESTS+= varmod-subst-regex 298TESTS+= varmod-sysv 299TESTS+= varmod-tail 300TESTS+= varmod-to-abs 301TESTS+= varmod-to-lower 302TESTS+= varmod-to-many-words 303TESTS+= varmod-to-one-word 304TESTS+= varmod-to-separator 305TESTS+= varmod-to-upper 306TESTS+= varmod-undefined 307TESTS+= varmod-unique 308TESTS+= varname 309TESTS+= varname-dollar 310TESTS+= varname-dot-alltargets 311TESTS+= varname-dot-curdir 312TESTS+= varname-dot-includes 313TESTS+= varname-dot-includedfromdir 314TESTS+= varname-dot-includedfromfile 315TESTS+= varname-dot-libs 316TESTS+= varname-dot-make-dependfile 317TESTS+= varname-dot-make-expand_variables 318TESTS+= varname-dot-make-exported 319TESTS+= varname-dot-make-jobs 320TESTS+= varname-dot-make-jobs-prefix 321TESTS+= varname-dot-make-level 322TESTS+= varname-dot-make-makefile_preference 323TESTS+= varname-dot-make-makefiles 324TESTS+= varname-dot-make-meta-bailiwick 325TESTS+= varname-dot-make-meta-created 326TESTS+= varname-dot-make-meta-files 327TESTS+= varname-dot-make-meta-ignore_filter 328TESTS+= varname-dot-make-meta-ignore_paths 329TESTS+= varname-dot-make-meta-ignore_patterns 330TESTS+= varname-dot-make-meta-prefix 331TESTS+= varname-dot-make-mode 332TESTS+= varname-dot-make-path_filemon 333TESTS+= varname-dot-make-pid 334TESTS+= varname-dot-make-ppid 335TESTS+= varname-dot-make-save_dollars 336TESTS+= varname-dot-makeoverrides 337TESTS+= varname-dot-newline 338TESTS+= varname-dot-objdir 339TESTS+= varname-dot-parsedir 340TESTS+= varname-dot-parsefile 341TESTS+= varname-dot-path 342TESTS+= varname-dot-shell 343TESTS+= varname-dot-targets 344TESTS+= varname-empty 345TESTS+= varname-make 346TESTS+= varname-make_print_var_on_error 347TESTS+= varname-makefile 348TESTS+= varname-makeflags 349TESTS+= varname-pwd 350TESTS+= varname-vpath 351TESTS+= varparse-dynamic 352TESTS+= varparse-undef-partial 353TESTS+= varquote 354TESTS+= varshell 355 356# Additional environment variables for some of the tests. 357# The base environment is -i PATH="$PATH". 358ENV.envfirst= FROM_ENV=value-from-env 359ENV.varmisc= FROM_ENV=env 360ENV.varmisc+= FROM_ENV_BEFORE=env 361ENV.varmisc+= FROM_ENV_AFTER=env 362 363# Override make flags for some of the tests; default is -k. 364# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of 365# settings FLAGS.test=-dv here, since that is closer to the test code. 366FLAGS.cond-func-make= via-cmdline 367FLAGS.directive-ifmake= first second 368FLAGS.doterror= # none 369FLAGS.envfirst= -e 370FLAGS.export= # none 371FLAGS.opt-ignore= -i 372FLAGS.opt-keep-going= -k 373FLAGS.opt-no-action= -n 374FLAGS.opt-query= -q 375FLAGS.opt-var-expanded= -v VAR -v VALUE 376FLAGS.opt-var-literal= -V VAR -V VALUE 377FLAGS.opt-warnings-as-errors= -W 378FLAGS.order= -j1 379FLAGS.recursive= -dL 380FLAGS.sh-leading-plus= -n 381FLAGS.vardebug= -k -dv FROM_CMDLINE= 382FLAGS.varmod-match-escape= -dv 383FLAGS.varname-dot-shell= -dpv 384FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain' 385 386# Some tests need extra postprocessing. 387SED_CMDS.opt-debug-graph1= \ 388 -e 's,${.CURDIR},CURDIR,' 389SED_CMDS.opt-debug-graph1+= \ 390 -e '/Global Variables:/,/Suffixes:/d' 391SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<normalized: ...: not found>,' 392SED_CMDS.varmod-subst-regex+= \ 393 -e 's,\(Regex compilation error:\).*,\1 (details omitted),' 394SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,' 395SED_CMDS.varshell+= -e 's,^${.SHELL:T}: ,,' 396SED_CMDS.varshell+= -e '/command/s,No such.*,not found,' 397SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,' 398SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,' 399SED_CMDS.varname-dot-shell= -e 's, = /.*, = (details omitted),' 400SED_CMDS.varname-dot-shell+= -e 's,"/[^"]*","(details omitted)",' 401SED_CMDS.varname-dot-shell+= -e 's,\[/[^]]*\],[(details omitted)],' 402 403# Some tests need an additional round of postprocessing. 404POSTPROC.deptgt-suffixes= \ 405 ${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p' 406POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' 407POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p' 408POSTPROC.varname= ${TOOL_SED} -n -e '/^MAGIC/p' -e '/^ORDER_/p' 409POSTPROC.varname-dot-shell= \ 410 awk '/\.SHELL/ || /^ParseReadLine/' 411POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p' 412 413# Some tests reuse other tests, which makes them unnecessarily fragile. 414export-all.rawout: export.mk 415unexport.rawout: export.mk 416unexport-env.rawout: export.mk 417 418# End of the configuration section. 419 420.MAIN: all 421 422UNIT_TESTS:= ${.PARSEDIR} 423.PATH: ${UNIT_TESTS} 424 425.if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes 426OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@} 427.else 428OUTFILES= ${TESTS:=.out} 429.endif 430 431all: ${OUTFILES} 432 433CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp 434CLEANFILES+= obj*.[och] lib*.a # posix1.mk 435CLEANFILES+= issue* .[ab]* # suffixes.mk 436CLEANDIRS= dir dummy # posix1.mk 437 438clean: 439 rm -f ${CLEANFILES} 440 rm -rf ${CLEANDIRS} 441 442TEST_MAKE?= ${.MAKE} 443TOOL_SED?= sed 444 445# ensure consistent results from sort(1) 446LC_ALL= C 447LANG= C 448.export LANG LC_ALL 449 450# Each test is run in a sub-make, to keep the tests for interfering with 451# each other, and because they use different environment variables and 452# command line options. 453.SUFFIXES: .mk .rawout .out 454.mk.rawout: 455 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX} 456 @set -eu; \ 457 cd ${.OBJDIR}; \ 458 env -i PATH="$$PATH" ${ENV.${.PREFIX:T}} \ 459 ${TEST_MAKE} \ 460 -r -C ${.CURDIR} -f ${.IMPSRC} \ 461 ${FLAGS.${.PREFIX:T}:U-k} \ 462 > ${.TARGET}.tmp 2>&1 \ 463 && status=$$? || status=$$?; \ 464 echo $$status > ${.TARGET:R}.status 465 @mv ${.TARGET}.tmp ${.TARGET} 466 467# Postprocess the test output so that the results can be compared. 468# 469# always pretend .MAKE was called 'make' 470_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 471_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 472# replace anything after 'stopped in' with unit-tests 473_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' 474# strip ${.CURDIR}/ from the output 475_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' 476_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 477 478.rawout.out: 479 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \ 480 < ${.IMPSRC} > ${.TARGET}.tmp1 481 @${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 482 @rm ${.TARGET}.tmp1 483 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 484 @mv ${.TARGET}.tmp2 ${.TARGET} 485 486# Compare all output files 487test: ${OUTFILES} .PHONY 488 @failed= ; \ 489 for test in ${TESTS}; do \ 490 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 491 || failed="$${failed}$${failed:+ }$${test}" ; \ 492 done ; \ 493 if [ -n "$${failed}" ]; then \ 494 echo "Failed tests: $${failed}" ; false ; \ 495 else \ 496 echo "All tests passed" ; \ 497 fi 498 499accept: 500 @for test in ${TESTS}; do \ 501 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 502 || { echo "Replacing $${test}.exp" ; \ 503 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 504 done 505 506# Note: only works for adding tests. 507# To remove a test, the $$mi file must be edited manually. 508sync-mi: 509 @set -eu; \ 510 cd "${MAKEFILE:tA:H}/../../.."; \ 511 mi="distrib/sets/lists/tests/mi"; \ 512 cvs update "$$mi"; \ 513 testsdir="usr.bin/make/unit-tests"; \ 514 fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \ 515 (cd "$$testsdir" && ls *.exp *.mk) | xargs printf "$$fmt" >> "$$mi"; \ 516 distrib/sets/fmt-list "$$mi"; \ 517 cvs diff "$$mi" || true 518 519.if exists(${TEST_MAKE}) 520${TESTS:=.rawout}: ${TEST_MAKE} ${.PARSEDIR}/Makefile 521.endif 522 523.-include <bsd.obj.mk> 524