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