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