Makefile revision 1.171
1# $NetBSD: Makefile,v 1.171 2020/10/23 14:38:39 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+= counter 73TESTS+= counter-append 74TESTS+= dep 75TESTS+= dep-colon 76TESTS+= dep-colon-bug-cross-file 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-gmake 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+= hanoi-include 171TESTS+= impsrc 172TESTS+= include-main 173TESTS+= job-output-long-lines 174TESTS+= lint 175TESTS+= make-exported 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+= parse-var 232TESTS+= phony-end 233TESTS+= posix 234TESTS+= # posix1 # broken by reverting POSIX changes 235TESTS+= qequals 236TESTS+= recursive 237TESTS+= sh 238TESTS+= sh-dots 239TESTS+= sh-jobs 240TESTS+= sh-jobs-error 241TESTS+= sh-leading-at 242TESTS+= sh-leading-hyphen 243TESTS+= sh-leading-plus 244TESTS+= sh-meta-chars 245TESTS+= sh-multi-line 246TESTS+= sh-single-line 247TESTS+= shell-csh 248TESTS+= shell-custom 249TESTS+= shell-ksh 250TESTS+= shell-sh 251TESTS+= suff-add-later 252TESTS+= suff-clear-regular 253TESTS+= suff-clear-single 254TESTS+= suff-main 255TESTS+= suff-rebuild 256TESTS+= suff-transform-endless 257TESTS+= suff-transform-expand 258TESTS+= suff-transform-select 259TESTS+= sunshcmd 260TESTS+= sysv 261TESTS+= ternary 262TESTS+= unexport 263TESTS+= unexport-env 264TESTS+= use-inference 265TESTS+= var-class 266TESTS+= var-class-cmdline 267TESTS+= var-class-env 268TESTS+= var-class-global 269TESTS+= var-class-local 270TESTS+= var-class-local-legacy 271TESTS+= var-op 272TESTS+= var-op-append 273TESTS+= var-op-assign 274TESTS+= var-op-default 275TESTS+= var-op-expand 276TESTS+= var-op-shell 277TESTS+= var-op-sunsh 278TESTS+= varcmd 279TESTS+= vardebug 280TESTS+= varfind 281TESTS+= varmisc 282TESTS+= varmod 283TESTS+= varmod-assign 284TESTS+= varmod-defined 285TESTS+= varmod-edge 286TESTS+= varmod-exclam-shell 287TESTS+= varmod-extension 288TESTS+= varmod-gmtime 289TESTS+= varmod-hash 290TESTS+= varmod-head 291TESTS+= varmod-ifelse 292TESTS+= varmod-l-name-to-value 293TESTS+= varmod-localtime 294TESTS+= varmod-loop 295TESTS+= varmod-match 296TESTS+= varmod-match-escape 297TESTS+= varmod-no-match 298TESTS+= varmod-order 299TESTS+= varmod-order-reverse 300TESTS+= varmod-order-shuffle 301TESTS+= varmod-path 302TESTS+= varmod-quote 303TESTS+= varmod-quote-dollar 304TESTS+= varmod-range 305TESTS+= varmod-remember 306TESTS+= varmod-root 307TESTS+= varmod-select-words 308TESTS+= varmod-shell 309TESTS+= varmod-subst 310TESTS+= varmod-subst-regex 311TESTS+= varmod-sysv 312TESTS+= varmod-tail 313TESTS+= varmod-to-abs 314TESTS+= varmod-to-lower 315TESTS+= varmod-to-many-words 316TESTS+= varmod-to-one-word 317TESTS+= varmod-to-separator 318TESTS+= varmod-to-upper 319TESTS+= varmod-undefined 320TESTS+= varmod-unique 321TESTS+= varname 322TESTS+= varname-dollar 323TESTS+= varname-dot-alltargets 324TESTS+= varname-dot-curdir 325TESTS+= varname-dot-includes 326TESTS+= varname-dot-includedfromdir 327TESTS+= varname-dot-includedfromfile 328TESTS+= varname-dot-libs 329TESTS+= varname-dot-make-dependfile 330TESTS+= varname-dot-make-expand_variables 331TESTS+= varname-dot-make-exported 332TESTS+= varname-dot-make-jobs 333TESTS+= varname-dot-make-jobs-prefix 334TESTS+= varname-dot-make-level 335TESTS+= varname-dot-make-makefile_preference 336TESTS+= varname-dot-make-makefiles 337TESTS+= varname-dot-make-meta-bailiwick 338TESTS+= varname-dot-make-meta-created 339TESTS+= varname-dot-make-meta-files 340TESTS+= varname-dot-make-meta-ignore_filter 341TESTS+= varname-dot-make-meta-ignore_paths 342TESTS+= varname-dot-make-meta-ignore_patterns 343TESTS+= varname-dot-make-meta-prefix 344TESTS+= varname-dot-make-mode 345TESTS+= varname-dot-make-path_filemon 346TESTS+= varname-dot-make-pid 347TESTS+= varname-dot-make-ppid 348TESTS+= varname-dot-make-save_dollars 349TESTS+= varname-dot-makeoverrides 350TESTS+= varname-dot-newline 351TESTS+= varname-dot-objdir 352TESTS+= varname-dot-parsedir 353TESTS+= varname-dot-parsefile 354TESTS+= varname-dot-path 355TESTS+= varname-dot-shell 356TESTS+= varname-dot-targets 357TESTS+= varname-empty 358TESTS+= varname-make 359TESTS+= varname-make_print_var_on_error 360TESTS+= varname-make_print_var_on_error-jobs 361TESTS+= varname-makefile 362TESTS+= varname-makeflags 363TESTS+= varname-pwd 364TESTS+= varname-vpath 365TESTS+= varparse-dynamic 366TESTS+= varparse-mod 367TESTS+= varparse-undef-partial 368TESTS+= varquote 369TESTS+= varshell 370 371# Additional environment variables for some of the tests. 372# The base environment is -i PATH="$PATH". 373ENV.envfirst= FROM_ENV=value-from-env 374ENV.varmisc= FROM_ENV=env 375ENV.varmisc+= FROM_ENV_BEFORE=env 376ENV.varmisc+= FROM_ENV_AFTER=env 377 378# Override make flags for some of the tests; default is -k. 379# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of 380# settings FLAGS.test=-dv here, since that is closer to the test code. 381FLAGS.cond-func-make= via-cmdline 382FLAGS.directive-ifmake= first second 383FLAGS.doterror= # none 384FLAGS.envfirst= -e 385FLAGS.export= # none 386FLAGS.opt-ignore= -i 387FLAGS.opt-keep-going= -k 388FLAGS.opt-no-action= -n 389FLAGS.opt-query= -q 390FLAGS.opt-var-expanded= -v VAR -v VALUE 391FLAGS.opt-var-literal= -V VAR -V VALUE 392FLAGS.opt-warnings-as-errors= -W 393FLAGS.order= -j1 394FLAGS.recursive= -dL 395FLAGS.sh-leading-plus= -n 396FLAGS.vardebug= -k -dv FROM_CMDLINE= 397FLAGS.varmod-match-escape= -dv 398FLAGS.varname-dot-shell= -dpv 399FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain' 400 401# Some tests need extra postprocessing. 402SED_CMDS.job-output-long-lines= \ 403 ${:D Job separators on their own line are ok. } \ 404 -e '/^--- job-[ab] ---$$/d' \ 405 ${:D Plain output lines are ok as well. } \ 406 ${:D They may come in multiples of 1024 or as 10000. } \ 407 -e '/^aa*$$/d' \ 408 -e '/^bb*$$/d' \ 409 ${:D The following lines should rather not occur since the job } \ 410 ${:D marker should always be at the beginning of the line. } \ 411 -e '/^aa*--- job-b ---$$/d' \ 412 -e '/^bb*--- job-a ---$$/d' 413SED_CMDS.opt-debug-graph1= \ 414 -e 's,${.CURDIR},CURDIR,' 415SED_CMDS.opt-debug-graph1+= \ 416 -e '/Global Variables:/,/Suffixes:/d' 417SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<normalized: ...: not found>,' 418SED_CMDS.opt-debug-jobs= -e 's,([0-9][0-9]*),(<pid>),' 419SED_CMDS.opt-debug-jobs+= -e 's,pid [0-9][0-9]*,pid <pid>,' 420SED_CMDS.opt-debug-jobs+= -e 's,Process [0-9][0-9]*,Process <pid>,' 421SED_CMDS.opt-debug-jobs+= -e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,' 422# The "-q" may be there or not, see jobs.c, variable shells. 423SED_CMDS.opt-debug-jobs+= -e 's,^\(.Command: sh\) -q,\1,' 424SED_CMDS.varmod-subst-regex+= \ 425 -e 's,\(Regex compilation error:\).*,\1 (details omitted),' 426SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,' 427SED_CMDS.varshell+= -e 's,^${.SHELL:T}: ,,' 428SED_CMDS.varshell+= -e '/command/s,No such.*,not found,' 429SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,' 430SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,' 431SED_CMDS.varname-dot-shell= -e 's, = /.*, = (details omitted),' 432SED_CMDS.varname-dot-shell+= -e 's,"/[^"]*","(details omitted)",' 433SED_CMDS.varname-dot-shell+= -e 's,\[/[^]]*\],[(details omitted)],' 434 435# Some tests need an additional round of postprocessing. 436POSTPROC.deptgt-suffixes= \ 437 ${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p' 438POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' 439POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p' 440POSTPROC.varname= ${TOOL_SED} -n -e '/^MAGIC/p' -e '/^ORDER_/p' 441POSTPROC.varname-dot-shell= \ 442 awk '/\.SHELL/ || /^ParseReadLine/' 443POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p' 444 445# Some tests reuse other tests, which makes them unnecessarily fragile. 446export-all.rawout: export.mk 447unexport.rawout: export.mk 448unexport-env.rawout: export.mk 449 450# End of the configuration section. 451 452.MAIN: all 453 454UNIT_TESTS:= ${.PARSEDIR} 455.PATH: ${UNIT_TESTS} 456 457.if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes 458OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@} 459.else 460OUTFILES= ${TESTS:=.out} 461.endif 462 463all: ${OUTFILES} 464 465CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp 466CLEANFILES+= obj*.[och] lib*.a # posix1.mk 467CLEANFILES+= issue* .[ab]* # suffixes.mk 468CLEANDIRS= dir dummy # posix1.mk 469 470clean: 471 rm -f ${CLEANFILES} 472 rm -rf ${CLEANDIRS} 473 474TEST_MAKE?= ${.MAKE} 475TOOL_SED?= sed 476 477# ensure consistent results from sort(1) 478LC_ALL= C 479LANG= C 480.export LANG LC_ALL 481 482MAKE_TEST_ENV?= MALLOC_OPTIONS="JA" # for jemalloc 483 484# Each test is run in a sub-make, to keep the tests for interfering with 485# each other, and because they use different environment variables and 486# command line options. 487.SUFFIXES: .mk .rawout .out 488.mk.rawout: 489 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX} 490 @set -eu; \ 491 cd ${.OBJDIR}; \ 492 env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \ 493 ${TEST_MAKE} \ 494 -r -C ${.CURDIR} -f ${.IMPSRC} \ 495 ${FLAGS.${.PREFIX:T}:U-k} \ 496 > ${.TARGET}.tmp 2>&1 \ 497 && status=$$? || status=$$?; \ 498 echo $$status > ${.TARGET:R}.status 499 @mv ${.TARGET}.tmp ${.TARGET} 500 501# Postprocess the test output so that the results can be compared. 502# 503# always pretend .MAKE was called 'make' 504_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 505_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 506# replace anything after 'stopped in' with unit-tests 507_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' 508# strip ${.CURDIR}/ from the output 509_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' 510_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 511 512.rawout.out: 513 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \ 514 < ${.IMPSRC} > ${.TARGET}.tmp1 515 @${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 516 @rm ${.TARGET}.tmp1 517 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 518 @mv ${.TARGET}.tmp2 ${.TARGET} 519 520# Compare all output files 521test: ${OUTFILES} .PHONY 522 @failed= ; \ 523 for test in ${TESTS}; do \ 524 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 525 || failed="$${failed}$${failed:+ }$${test}" ; \ 526 done ; \ 527 if [ -n "$${failed}" ]; then \ 528 echo "Failed tests: $${failed}" ; false ; \ 529 else \ 530 echo "All tests passed" ; \ 531 fi 532 533accept: 534 @for test in ${TESTS}; do \ 535 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 536 || { echo "Replacing $${test}.exp" ; \ 537 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 538 done 539 540# Note: only works for adding tests. 541# To remove a test, the $$mi file must be edited manually. 542sync-mi: 543 @set -eu; \ 544 cd "${MAKEFILE:tA:H}/../../.."; \ 545 mi="distrib/sets/lists/tests/mi"; \ 546 cvs update "$$mi"; \ 547 testsdir="usr.bin/make/unit-tests"; \ 548 fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \ 549 (cd "$$testsdir" && ls *.exp *.mk) | xargs printf "$$fmt" >> "$$mi"; \ 550 distrib/sets/fmt-list "$$mi"; \ 551 cvs diff "$$mi" || true 552 553.if exists(${TEST_MAKE}) 554${TESTS:=.rawout}: ${TEST_MAKE} 555# in meta mode, we *know* if a target script is impacted 556# by a makefile change. 557.if ${.MAKE.MODE:Unormal:Mmeta} == "" 558${TESTS:=.rawout}: ${.PARSEDIR}/Makefile 559.endif 560.endif 561 562.-include <bsd.obj.mk> 563