1# $Id: Makefile,v 1.107 2020/11/02 00:40:25 sjg Exp $ 2# 3# $NetBSD: Makefile,v 1.181 2020/11/01 19:02:22 rillig Exp $ 4# 5# Unit tests for make(1) 6# 7# The main targets are: 8# 9# all: 10# run all the tests 11# test: 12# run 'all', and compare to expected results 13# accept: 14# move generated output to expected results 15# 16# Settable variables 17# 18# TEST_MAKE 19# The make program to be tested. 20# 21# 22# Adding a test case 23# 24# Each feature should get its own set of tests in its own suitably 25# named makefile (*.mk), with its own set of expected results (*.exp), 26# and it should be added to the TESTS list. 27# 28# A few *.mk files are helper files for other tests (such as include-sub.mk) 29# and are thus not added to TESTS. Such files must be ignored in 30# src/tests/usr.bin/make/t_make.sh. 31# 32 33# Each test is in a sub-makefile. 34# Keep the list sorted. 35# Any test that is commented out must be ignored in 36# src/tests/usr.bin/make/t_make.sh as well. 37#TESTS+= archive 38TESTS+= archive-suffix 39TESTS+= cmd-interrupt 40TESTS+= cmdline 41TESTS+= comment 42TESTS+= cond-cmp-numeric 43TESTS+= cond-cmp-numeric-eq 44TESTS+= cond-cmp-numeric-ge 45TESTS+= cond-cmp-numeric-gt 46TESTS+= cond-cmp-numeric-le 47TESTS+= cond-cmp-numeric-lt 48TESTS+= cond-cmp-numeric-ne 49TESTS+= cond-cmp-string 50TESTS+= cond-cmp-unary 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+= cond-undef-lint 70TESTS+= cond1 71TESTS+= counter 72TESTS+= counter-append 73TESTS+= dep 74TESTS+= dep-colon 75TESTS+= dep-colon-bug-cross-file 76TESTS+= dep-double-colon 77TESTS+= dep-double-colon-indep 78TESTS+= dep-exclam 79TESTS+= dep-none 80TESTS+= dep-percent 81TESTS+= dep-var 82TESTS+= dep-wildcards 83TESTS+= depsrc 84TESTS+= depsrc-end 85TESTS+= depsrc-exec 86TESTS+= depsrc-ignore 87TESTS+= depsrc-made 88TESTS+= depsrc-make 89TESTS+= depsrc-meta 90TESTS+= depsrc-nometa 91TESTS+= depsrc-nometa_cmp 92TESTS+= depsrc-nopath 93TESTS+= depsrc-notmain 94TESTS+= depsrc-optional 95TESTS+= depsrc-phony 96TESTS+= depsrc-precious 97TESTS+= depsrc-recursive 98TESTS+= depsrc-silent 99TESTS+= depsrc-use 100TESTS+= depsrc-usebefore 101TESTS+= depsrc-usebefore-double-colon 102TESTS+= depsrc-wait 103TESTS+= deptgt 104TESTS+= deptgt-begin 105TESTS+= deptgt-default 106TESTS+= deptgt-delete_on_error 107TESTS+= deptgt-end 108TESTS+= deptgt-end-jobs 109TESTS+= deptgt-error 110TESTS+= deptgt-ignore 111TESTS+= deptgt-interrupt 112TESTS+= deptgt-main 113TESTS+= deptgt-makeflags 114TESTS+= deptgt-no_parallel 115TESTS+= deptgt-nopath 116TESTS+= deptgt-notparallel 117TESTS+= deptgt-objdir 118TESTS+= deptgt-order 119TESTS+= deptgt-path 120TESTS+= deptgt-path-suffix 121TESTS+= deptgt-phony 122TESTS+= deptgt-precious 123TESTS+= deptgt-shell 124TESTS+= deptgt-silent 125TESTS+= deptgt-stale 126TESTS+= deptgt-suffixes 127TESTS+= dir 128TESTS+= dir-expand-path 129TESTS+= directive 130TESTS+= directive-dinclude 131TESTS+= directive-elif 132TESTS+= directive-elifdef 133TESTS+= directive-elifmake 134TESTS+= directive-elifndef 135TESTS+= directive-elifnmake 136TESTS+= directive-else 137TESTS+= directive-endif 138TESTS+= directive-error 139TESTS+= directive-export 140TESTS+= directive-export-env 141TESTS+= directive-export-gmake 142TESTS+= directive-export-literal 143TESTS+= directive-for 144TESTS+= directive-for-generating-endif 145TESTS+= directive-hyphen-include 146TESTS+= directive-if 147TESTS+= directive-ifdef 148TESTS+= directive-ifmake 149TESTS+= directive-ifndef 150TESTS+= directive-ifnmake 151TESTS+= directive-include 152TESTS+= directive-include-fatal 153TESTS+= directive-info 154TESTS+= directive-sinclude 155TESTS+= directive-undef 156TESTS+= directive-unexport 157TESTS+= directive-unexport-env 158TESTS+= directive-warning 159TESTS+= directives 160TESTS+= dollar 161TESTS+= doterror 162TESTS+= dotwait 163TESTS+= envfirst 164TESTS+= error 165TESTS+= # escape # broken by reverting POSIX changes 166TESTS+= export 167TESTS+= export-all 168TESTS+= export-env 169TESTS+= export-variants 170TESTS+= forloop 171TESTS+= forsubst 172TESTS+= hanoi-include 173TESTS+= impsrc 174TESTS+= include-main 175#TESTS+= job-output-long-lines 176TESTS+= lint 177TESTS+= make-exported 178TESTS+= moderrs 179TESTS+= modmatch 180TESTS+= modmisc 181TESTS+= modts 182TESTS+= modword 183TESTS+= opt 184TESTS+= opt-backwards 185TESTS+= opt-chdir 186TESTS+= opt-debug 187TESTS+= opt-debug-all 188TESTS+= opt-debug-archive 189TESTS+= opt-debug-curdir 190TESTS+= opt-debug-cond 191TESTS+= opt-debug-dir 192TESTS+= opt-debug-errors 193TESTS+= opt-debug-file 194TESTS+= opt-debug-for 195TESTS+= opt-debug-graph1 196TESTS+= opt-debug-graph2 197TESTS+= opt-debug-graph3 198TESTS+= opt-debug-hash 199#TESTS+= opt-debug-jobs 200TESTS+= opt-debug-lint 201TESTS+= opt-debug-loud 202TESTS+= opt-debug-meta 203TESTS+= opt-debug-making 204TESTS+= opt-debug-no-rm 205TESTS+= opt-debug-parse 206TESTS+= opt-debug-suff 207TESTS+= opt-debug-targets 208TESTS+= opt-debug-varraw 209TESTS+= opt-debug-var 210TESTS+= opt-debug-x-trace 211TESTS+= opt-define 212TESTS+= opt-env 213TESTS+= opt-file 214TESTS+= opt-ignore 215TESTS+= opt-include-dir 216TESTS+= opt-jobs 217TESTS+= opt-jobs-internal 218TESTS+= opt-keep-going 219TESTS+= opt-m-include-dir 220TESTS+= opt-no-action 221TESTS+= opt-no-action-at-all 222TESTS+= opt-query 223TESTS+= opt-raw 224TESTS+= opt-silent 225TESTS+= opt-touch 226TESTS+= opt-tracefile 227TESTS+= opt-var-expanded 228TESTS+= opt-var-literal 229TESTS+= opt-warnings-as-errors 230TESTS+= opt-where-am-i 231TESTS+= opt-x-reduce-exported 232TESTS+= order 233TESTS+= parse-var 234TESTS+= phony-end 235TESTS+= posix 236TESTS+= # posix1 # broken by reverting POSIX changes 237TESTS+= qequals 238TESTS+= recursive 239TESTS+= sh 240TESTS+= sh-dots 241TESTS+= sh-jobs 242TESTS+= sh-jobs-error 243TESTS+= sh-leading-at 244TESTS+= sh-leading-hyphen 245TESTS+= sh-leading-plus 246TESTS+= sh-meta-chars 247TESTS+= sh-multi-line 248TESTS+= sh-single-line 249TESTS+= shell-csh 250TESTS+= shell-custom 251TESTS+= shell-ksh 252TESTS+= shell-sh 253TESTS+= suff-add-later 254TESTS+= suff-clear-regular 255TESTS+= suff-clear-single 256TESTS+= suff-lookup 257TESTS+= suff-main 258TESTS+= suff-rebuild 259TESTS+= suff-transform-endless 260TESTS+= suff-transform-expand 261TESTS+= suff-transform-select 262TESTS+= sunshcmd 263TESTS+= ternary 264TESTS+= unexport 265TESTS+= unexport-env 266TESTS+= use-inference 267TESTS+= var-class 268TESTS+= var-class-cmdline 269TESTS+= var-class-env 270TESTS+= var-class-global 271TESTS+= var-class-local 272TESTS+= var-class-local-legacy 273TESTS+= var-op 274TESTS+= var-op-append 275TESTS+= var-op-assign 276TESTS+= var-op-default 277TESTS+= var-op-expand 278TESTS+= var-op-shell 279TESTS+= var-op-sunsh 280TESTS+= var-recursive 281TESTS+= varcmd 282TESTS+= vardebug 283TESTS+= varfind 284TESTS+= varmisc 285TESTS+= varmod 286TESTS+= varmod-assign 287TESTS+= varmod-defined 288TESTS+= varmod-edge 289TESTS+= varmod-exclam-shell 290TESTS+= varmod-extension 291TESTS+= varmod-gmtime 292TESTS+= varmod-hash 293TESTS+= varmod-head 294TESTS+= varmod-ifelse 295TESTS+= varmod-l-name-to-value 296TESTS+= varmod-localtime 297TESTS+= varmod-loop 298TESTS+= varmod-match 299TESTS+= varmod-match-escape 300TESTS+= varmod-no-match 301TESTS+= varmod-order 302TESTS+= varmod-order-reverse 303TESTS+= varmod-order-shuffle 304TESTS+= varmod-path 305TESTS+= varmod-quote 306TESTS+= varmod-quote-dollar 307TESTS+= varmod-range 308TESTS+= varmod-remember 309TESTS+= varmod-root 310TESTS+= varmod-select-words 311TESTS+= varmod-shell 312TESTS+= varmod-subst 313TESTS+= varmod-subst-regex 314TESTS+= varmod-sysv 315TESTS+= varmod-tail 316TESTS+= varmod-to-abs 317TESTS+= varmod-to-lower 318TESTS+= varmod-to-many-words 319TESTS+= varmod-to-one-word 320TESTS+= varmod-to-separator 321TESTS+= varmod-to-upper 322TESTS+= varmod-undefined 323TESTS+= varmod-unique 324TESTS+= varname 325TESTS+= varname-dollar 326TESTS+= varname-dot-alltargets 327TESTS+= varname-dot-curdir 328TESTS+= varname-dot-includes 329TESTS+= varname-dot-includedfromdir 330TESTS+= varname-dot-includedfromfile 331TESTS+= varname-dot-libs 332TESTS+= varname-dot-make-dependfile 333TESTS+= varname-dot-make-expand_variables 334TESTS+= varname-dot-make-exported 335TESTS+= varname-dot-make-jobs 336TESTS+= varname-dot-make-jobs-prefix 337TESTS+= varname-dot-make-level 338TESTS+= varname-dot-make-makefile_preference 339TESTS+= varname-dot-make-makefiles 340TESTS+= varname-dot-make-meta-bailiwick 341TESTS+= varname-dot-make-meta-created 342TESTS+= varname-dot-make-meta-files 343TESTS+= varname-dot-make-meta-ignore_filter 344TESTS+= varname-dot-make-meta-ignore_paths 345TESTS+= varname-dot-make-meta-ignore_patterns 346TESTS+= varname-dot-make-meta-prefix 347TESTS+= varname-dot-make-mode 348TESTS+= varname-dot-make-path_filemon 349TESTS+= varname-dot-make-pid 350TESTS+= varname-dot-make-ppid 351TESTS+= varname-dot-make-save_dollars 352TESTS+= varname-dot-makeoverrides 353TESTS+= varname-dot-newline 354TESTS+= varname-dot-objdir 355TESTS+= varname-dot-parsedir 356TESTS+= varname-dot-parsefile 357TESTS+= varname-dot-path 358TESTS+= varname-dot-shell 359TESTS+= varname-dot-targets 360TESTS+= varname-empty 361TESTS+= varname-make 362TESTS+= varname-make_print_var_on_error 363TESTS+= varname-make_print_var_on_error-jobs 364TESTS+= varname-makefile 365TESTS+= varname-makeflags 366TESTS+= varname-pwd 367TESTS+= varname-vpath 368TESTS+= varparse-dynamic 369TESTS+= varparse-mod 370TESTS+= varparse-undef-partial 371TESTS+= varquote 372TESTS+= varshell 373 374# Additional environment variables for some of the tests. 375# The base environment is -i PATH="$PATH". 376ENV.envfirst= FROM_ENV=value-from-env 377ENV.varmisc= FROM_ENV=env 378ENV.varmisc+= FROM_ENV_BEFORE=env 379ENV.varmisc+= FROM_ENV_AFTER=env 380ENV.varmod-localtime+= TZ=Europe/Berlin 381 382# Override make flags for some of the tests; default is -k. 383# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of 384# settings FLAGS.test=-dv here, since that is closer to the test code. 385FLAGS.cond-func-make= via-cmdline 386FLAGS.directive-ifmake= first second 387FLAGS.doterror= # none 388FLAGS.envfirst= -e 389FLAGS.export= # none 390FLAGS.opt-ignore= -i 391FLAGS.opt-keep-going= -k 392FLAGS.opt-no-action= -n 393FLAGS.opt-query= -q 394FLAGS.opt-var-expanded= -v VAR -v VALUE 395FLAGS.opt-var-literal= -V VAR -V VALUE 396FLAGS.opt-warnings-as-errors= -W 397FLAGS.order= -j1 398FLAGS.recursive= -dL 399FLAGS.sh-leading-plus= -n 400FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain' 401 402# Some tests need extra postprocessing. 403SED_CMDS.export= \ 404 -e '/^[^=_A-Za-z0-9]*=/d' 405# these all share the same requirement 406.for t in export-all export-env 407SED_CMDS.$t= ${SED_CMDS.export} 408.endfor 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.varname= ${TOOL_SED} -n -e '/^MAGIC/p' -e '/^ORDER_/p' 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 457.-include "Makefile.inc" 458.-include "Makefile.config" 459 460UNIT_TESTS:= ${.PARSEDIR} 461.PATH: ${UNIT_TESTS} 462 463.if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes 464OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@} 465.else 466OUTFILES= ${TESTS:=.out} 467.endif 468 469all: ${OUTFILES} 470 471CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp 472CLEANFILES+= obj*.[och] lib*.a # posix1.mk 473CLEANFILES+= issue* .[ab]* # suffixes.mk 474CLEANDIRS= dir dummy # posix1.mk 475 476clean: 477 rm -f ${CLEANFILES} 478 rm -rf ${CLEANDIRS} 479 480TEST_MAKE?= ${.MAKE} 481TOOL_SED?= sed 482TOOL_TR?= tr 483TOOL_DIFF?= diff 484DIFF_FLAGS?= -u 485 486.if defined(.PARSEDIR) 487# ensure consistent results from sort(1) 488LC_ALL= C 489LANG= C 490.export LANG LC_ALL 491.endif 492 493.if ${.MAKE.MODE:Unormal:Mmeta} != "" 494# we don't need the noise 495_MKMSG_TEST= : 496.endif 497 498MAKE_TEST_ENV?= MALLOC_OPTIONS="JA" # for jemalloc 499 500# Each test is run in a sub-make, to keep the tests for interfering with 501# each other, and because they use different environment variables and 502# command line options. 503.SUFFIXES: .mk .rawout .out 504.mk.rawout: 505 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX} 506 @set -eu; \ 507 cd ${.OBJDIR}; \ 508 env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \ 509 ${TEST_MAKE} \ 510 -r -C ${.CURDIR} -f ${.IMPSRC} \ 511 ${FLAGS.${.PREFIX:T}:U-k} \ 512 > ${.TARGET}.tmp 2>&1 \ 513 && status=$$? || status=$$?; \ 514 echo $$status > ${.TARGET:R}.status 515 @mv ${.TARGET}.tmp ${.TARGET} 516 517# Postprocess the test output so that the results can be compared. 518# 519# always pretend .MAKE was called 'make' 520_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 521_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 522# replace anything after 'stopped in' with unit-tests 523_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' 524# strip ${.CURDIR}/ from the output 525_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' 526_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 527 528.rawout.out: 529 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \ 530 < ${.IMPSRC} > ${.TARGET}.tmp1 531 @${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 532 @rm ${.TARGET}.tmp1 533 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 534 @mv ${.TARGET}.tmp2 ${.TARGET} 535 536# Compare all output files 537test: ${OUTFILES} .PHONY 538 @failed= ; \ 539 for test in ${TESTS}; do \ 540 ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \ 541 || failed="$${failed}$${failed:+ }$${test}" ; \ 542 done ; \ 543 if [ -n "$${failed}" ]; then \ 544 echo "Failed tests: $${failed}" ; false ; \ 545 else \ 546 echo "All tests passed" ; \ 547 fi 548 549accept: 550 @for test in ${TESTS}; do \ 551 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 552 || { echo "Replacing $${test}.exp" ; \ 553 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 554 done 555 556.if exists(${TEST_MAKE}) 557${TESTS:=.rawout}: ${TEST_MAKE} 558# in meta mode, we *know* if a target script is impacted 559# by a makefile change. 560.if ${.MAKE.MODE:Unormal:Mmeta} == "" 561${TESTS:=.rawout}: ${.PARSEDIR}/Makefile 562.endif 563.endif 564 565.-include <obj.mk> 566