Makefile revision 1.148
1# $NetBSD: Makefile,v 1.148 2020/09/23 07:54:08 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-double-colon 78TESTS+= dep-exclam 79TESTS+= dep-none 80TESTS+= dep-var 81TESTS+= dep-wildcards 82TESTS+= depsrc 83TESTS+= depsrc-exec 84TESTS+= depsrc-ignore 85TESTS+= depsrc-made 86TESTS+= depsrc-make 87TESTS+= depsrc-meta 88TESTS+= depsrc-nometa 89TESTS+= depsrc-nometa_cmp 90TESTS+= depsrc-nopath 91TESTS+= depsrc-notmain 92TESTS+= depsrc-optional 93TESTS+= depsrc-phony 94TESTS+= depsrc-precious 95TESTS+= depsrc-recursive 96TESTS+= depsrc-silent 97TESTS+= depsrc-use 98TESTS+= depsrc-usebefore 99TESTS+= depsrc-usebefore-double-colon 100TESTS+= depsrc-wait 101TESTS+= deptgt 102TESTS+= deptgt-begin 103TESTS+= deptgt-default 104TESTS+= deptgt-delete_on_error 105TESTS+= deptgt-end 106TESTS+= deptgt-end-jobs 107TESTS+= deptgt-error 108TESTS+= deptgt-ignore 109TESTS+= deptgt-interrupt 110TESTS+= deptgt-main 111TESTS+= deptgt-makeflags 112TESTS+= deptgt-no_parallel 113TESTS+= deptgt-nopath 114TESTS+= deptgt-notparallel 115TESTS+= deptgt-objdir 116TESTS+= deptgt-order 117TESTS+= deptgt-path 118TESTS+= deptgt-path-suffix 119TESTS+= deptgt-phony 120TESTS+= deptgt-precious 121TESTS+= deptgt-shell 122TESTS+= deptgt-silent 123TESTS+= deptgt-stale 124TESTS+= deptgt-suffixes 125TESTS+= dir 126TESTS+= dir-expand-path 127TESTS+= directive 128TESTS+= directive-dinclude 129TESTS+= directive-elif 130TESTS+= directive-elifdef 131TESTS+= directive-elifmake 132TESTS+= directive-elifndef 133TESTS+= directive-elifnmake 134TESTS+= directive-else 135TESTS+= directive-endif 136TESTS+= directive-error 137TESTS+= directive-export 138TESTS+= directive-export-env 139TESTS+= directive-export-literal 140TESTS+= directive-for 141TESTS+= directive-for-generating-endif 142TESTS+= directive-hyphen-include 143TESTS+= directive-if 144TESTS+= directive-ifdef 145TESTS+= directive-ifmake 146TESTS+= directive-ifndef 147TESTS+= directive-ifnmake 148TESTS+= directive-include 149TESTS+= directive-include-fatal 150TESTS+= directive-info 151TESTS+= directive-sinclude 152TESTS+= directive-undef 153TESTS+= directive-unexport 154TESTS+= directive-unexport-env 155TESTS+= directive-warning 156TESTS+= directives 157TESTS+= dollar 158TESTS+= doterror 159TESTS+= dotwait 160TESTS+= envfirst 161TESTS+= error 162TESTS+= # escape # broken by reverting POSIX changes 163TESTS+= export 164TESTS+= export-all 165TESTS+= export-env 166TESTS+= export-variants 167TESTS+= forloop 168TESTS+= forsubst 169TESTS+= impsrc 170TESTS+= include-main 171TESTS+= lint 172TESTS+= make-exported 173TESTS+= misc 174TESTS+= moderrs 175TESTS+= modmatch 176TESTS+= modmisc 177TESTS+= modts 178TESTS+= modword 179TESTS+= opt 180TESTS+= opt-backwards 181TESTS+= opt-chdir 182TESTS+= opt-debug 183TESTS+= opt-debug-all 184TESTS+= opt-debug-archive 185TESTS+= opt-debug-curdir 186TESTS+= opt-debug-cond 187TESTS+= opt-debug-dir 188TESTS+= opt-debug-errors 189TESTS+= opt-debug-file 190TESTS+= opt-debug-for 191TESTS+= opt-debug-graph1 192TESTS+= opt-debug-graph2 193TESTS+= opt-debug-graph3 194TESTS+= opt-debug-hash 195TESTS+= opt-debug-jobs 196TESTS+= opt-debug-lint 197TESTS+= opt-debug-loud 198TESTS+= opt-debug-meta 199TESTS+= opt-debug-making 200TESTS+= opt-debug-no-rm 201TESTS+= opt-debug-parse 202TESTS+= opt-debug-suff 203TESTS+= opt-debug-targets 204TESTS+= opt-debug-varraw 205TESTS+= opt-debug-var 206TESTS+= opt-debug-x-trace 207TESTS+= opt-define 208TESTS+= opt-env 209TESTS+= opt-file 210TESTS+= opt-ignore 211TESTS+= opt-include-dir 212TESTS+= opt-jobs 213TESTS+= opt-jobs-internal 214TESTS+= opt-keep-going 215TESTS+= opt-m-include-dir 216TESTS+= opt-no-action 217TESTS+= opt-no-action-at-all 218TESTS+= opt-query 219TESTS+= opt-raw 220TESTS+= opt-silent 221TESTS+= opt-touch 222TESTS+= opt-tracefile 223TESTS+= opt-var-expanded 224TESTS+= opt-var-literal 225TESTS+= opt-warnings-as-errors 226TESTS+= opt-where-am-i 227TESTS+= opt-x-reduce-exported 228TESTS+= order 229TESTS+= phony-end 230TESTS+= posix 231TESTS+= # posix1 # broken by reverting POSIX changes 232TESTS+= qequals 233TESTS+= recursive 234TESTS+= sh 235TESTS+= sh-dots 236TESTS+= sh-jobs 237TESTS+= sh-jobs-error 238TESTS+= sh-leading-at 239TESTS+= sh-leading-hyphen 240TESTS+= sh-leading-plus 241TESTS+= sh-meta-chars 242TESTS+= sh-multi-line 243TESTS+= sh-single-line 244TESTS+= # suffixes # runs into an endless loop (try -dA) 245TESTS+= sunshcmd 246TESTS+= sysv 247TESTS+= ternary 248TESTS+= unexport 249TESTS+= unexport-env 250TESTS+= use-inference 251TESTS+= var-class 252TESTS+= var-class-cmdline 253TESTS+= var-class-env 254TESTS+= var-class-global 255TESTS+= var-class-local 256TESTS+= var-class-local-legacy 257TESTS+= var-op 258TESTS+= var-op-append 259TESTS+= var-op-assign 260TESTS+= var-op-default 261TESTS+= var-op-expand 262TESTS+= var-op-shell 263TESTS+= varcmd 264TESTS+= vardebug 265TESTS+= varfind 266TESTS+= varmisc 267TESTS+= varmod 268TESTS+= varmod-assign 269TESTS+= varmod-defined 270TESTS+= varmod-edge 271TESTS+= varmod-exclam-shell 272TESTS+= varmod-extension 273TESTS+= varmod-gmtime 274TESTS+= varmod-hash 275TESTS+= varmod-head 276TESTS+= varmod-ifelse 277TESTS+= varmod-l-name-to-value 278TESTS+= varmod-localtime 279TESTS+= varmod-loop 280TESTS+= varmod-match 281TESTS+= varmod-match-escape 282TESTS+= varmod-no-match 283TESTS+= varmod-order 284TESTS+= varmod-order-reverse 285TESTS+= varmod-order-shuffle 286TESTS+= varmod-path 287TESTS+= varmod-quote 288TESTS+= varmod-quote-dollar 289TESTS+= varmod-range 290TESTS+= varmod-remember 291TESTS+= varmod-root 292TESTS+= varmod-select-words 293TESTS+= varmod-shell 294TESTS+= varmod-subst 295TESTS+= varmod-subst-regex 296TESTS+= varmod-sysv 297TESTS+= varmod-tail 298TESTS+= varmod-to-abs 299TESTS+= varmod-to-lower 300TESTS+= varmod-to-many-words 301TESTS+= varmod-to-one-word 302TESTS+= varmod-to-separator 303TESTS+= varmod-to-upper 304TESTS+= varmod-undefined 305TESTS+= varmod-unique 306TESTS+= varname 307TESTS+= varname-dollar 308TESTS+= varname-dot-alltargets 309TESTS+= varname-dot-curdir 310TESTS+= varname-dot-includes 311TESTS+= varname-dot-includedfromdir 312TESTS+= varname-dot-includedfromfile 313TESTS+= varname-dot-libs 314TESTS+= varname-dot-make-dependfile 315TESTS+= varname-dot-make-expand_variables 316TESTS+= varname-dot-make-exported 317TESTS+= varname-dot-make-jobs 318TESTS+= varname-dot-make-jobs-prefix 319TESTS+= varname-dot-make-level 320TESTS+= varname-dot-make-makefile_preference 321TESTS+= varname-dot-make-makefiles 322TESTS+= varname-dot-make-meta-bailiwick 323TESTS+= varname-dot-make-meta-created 324TESTS+= varname-dot-make-meta-files 325TESTS+= varname-dot-make-meta-ignore_filter 326TESTS+= varname-dot-make-meta-ignore_paths 327TESTS+= varname-dot-make-meta-ignore_patterns 328TESTS+= varname-dot-make-meta-prefix 329TESTS+= varname-dot-make-mode 330TESTS+= varname-dot-make-path_filemon 331TESTS+= varname-dot-make-pid 332TESTS+= varname-dot-make-ppid 333TESTS+= varname-dot-make-save_dollars 334TESTS+= varname-dot-makeoverrides 335TESTS+= varname-dot-newline 336TESTS+= varname-dot-objdir 337TESTS+= varname-dot-parsedir 338TESTS+= varname-dot-parsefile 339TESTS+= varname-dot-path 340TESTS+= varname-dot-shell 341TESTS+= varname-dot-targets 342TESTS+= varname-empty 343TESTS+= varname-make 344TESTS+= varname-make_print_var_on_error 345TESTS+= varname-makefile 346TESTS+= varname-makeflags 347TESTS+= varname-pwd 348TESTS+= varname-vpath 349TESTS+= varparse-dynamic 350TESTS+= varquote 351TESTS+= varshell 352 353# Additional environment variables for some of the tests. 354# The base environment is -i PATH="$PATH". 355ENV.envfirst= FROM_ENV=value-from-env 356ENV.varmisc= FROM_ENV=env 357ENV.varmisc+= FROM_ENV_BEFORE=env 358ENV.varmisc+= FROM_ENV_AFTER=env 359 360# Override make flags for some of the tests; default is -k. 361# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of 362# settings FLAGS.test=-dv here, since that is closer to the test code. 363FLAGS.directive-ifmake= first second 364FLAGS.doterror= # none 365FLAGS.envfirst= -e 366FLAGS.export= # none 367FLAGS.opt-ignore= -i 368FLAGS.opt-keep-going= -k 369FLAGS.opt-no-action= -n 370FLAGS.opt-query= -q 371FLAGS.opt-var-expanded= -v VAR -v VALUE 372FLAGS.opt-var-literal= -V VAR -V VALUE 373FLAGS.opt-warnings-as-errors= -W 374FLAGS.order= -j1 375FLAGS.recursive= -dL 376FLAGS.sh-leading-plus= -n 377FLAGS.vardebug= -k -dv FROM_CMDLINE= 378FLAGS.varmod-match-escape= -dv 379FLAGS.varname-dot-shell= -dpv 380FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain' 381 382# Some tests need extra postprocessing. 383SED_CMDS.opt-debug-graph1= \ 384 -e 's,${.CURDIR},CURDIR,' 385SED_CMDS.opt-debug-graph1+= \ 386 -e '/Global Variables:/,/Suffixes:/d' 387SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<normalized: ...: not found>,' 388SED_CMDS.varmod-subst-regex+= \ 389 -e 's,\(Regex compilation error:\).*,\1 (details omitted),' 390SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,' 391SED_CMDS.varshell+= -e 's,^${.SHELL:T}: ,,' 392SED_CMDS.varshell+= -e '/command/s,No such.*,not found,' 393SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,' 394SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,' 395SED_CMDS.varname-dot-shell= -e 's, = /.*, = (details omitted),' 396SED_CMDS.varname-dot-shell+= -e 's,"/[^"]*","(details omitted)",' 397SED_CMDS.varname-dot-shell+= -e 's,\[/[^]]*\],[(details omitted)],' 398 399# Some tests need an additional round of postprocessing. 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