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