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