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