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