1# $Id: Makefile,v 1.92 2020/09/02 18:39:29 sjg Exp $ 2# 3# $NetBSD: Makefile,v 1.130 2020/09/02 05:33:57 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. 37TESTS+= # archive # broken on FreeBSD, enabled in t_make.sh 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-func 51TESTS+= cond-func-commands 52TESTS+= cond-func-defined 53TESTS+= cond-func-empty 54TESTS+= cond-func-exists 55TESTS+= cond-func-make 56TESTS+= cond-func-target 57TESTS+= cond-late 58TESTS+= cond-op 59TESTS+= cond-op-and 60TESTS+= cond-op-not 61TESTS+= cond-op-or 62TESTS+= cond-op-parentheses 63TESTS+= cond-short 64TESTS+= cond-token-number 65TESTS+= cond-token-plain 66TESTS+= cond-token-string 67TESTS+= cond-token-var 68TESTS+= cond1 69TESTS+= cond2 70TESTS+= counter 71TESTS+= dep 72TESTS+= dep-colon 73TESTS+= dep-double-colon 74TESTS+= dep-exclam 75TESTS+= dep-none 76TESTS+= dep-var 77TESTS+= dep-wildcards 78TESTS+= depsrc 79TESTS+= depsrc-exec 80TESTS+= depsrc-ignore 81TESTS+= depsrc-made 82TESTS+= depsrc-make 83TESTS+= depsrc-meta 84TESTS+= depsrc-nometa 85TESTS+= depsrc-nometa_cmp 86TESTS+= depsrc-nopath 87TESTS+= depsrc-notmain 88TESTS+= depsrc-optional 89TESTS+= depsrc-phony 90TESTS+= depsrc-precious 91TESTS+= depsrc-recursive 92TESTS+= depsrc-silent 93TESTS+= depsrc-use 94TESTS+= depsrc-usebefore 95TESTS+= depsrc-usebefore-double-colon 96TESTS+= depsrc-wait 97TESTS+= deptgt 98TESTS+= deptgt-begin 99TESTS+= deptgt-default 100TESTS+= deptgt-delete_on_error 101TESTS+= deptgt-end 102TESTS+= deptgt-error 103TESTS+= deptgt-ignore 104TESTS+= deptgt-interrupt 105TESTS+= deptgt-main 106TESTS+= deptgt-makeflags 107TESTS+= deptgt-no_parallel 108TESTS+= deptgt-nopath 109TESTS+= deptgt-notparallel 110TESTS+= deptgt-objdir 111TESTS+= deptgt-order 112TESTS+= deptgt-path 113TESTS+= deptgt-path-suffix 114TESTS+= deptgt-phony 115TESTS+= deptgt-precious 116TESTS+= deptgt-shell 117TESTS+= deptgt-silent 118TESTS+= deptgt-stale 119TESTS+= deptgt-suffixes 120TESTS+= dir 121TESTS+= dir-expand-path 122TESTS+= directive 123TESTS+= directive-elif 124TESTS+= directive-elifdef 125TESTS+= directive-elifmake 126TESTS+= directive-elifndef 127TESTS+= directive-elifnmake 128TESTS+= directive-else 129TESTS+= directive-endif 130TESTS+= directive-error 131TESTS+= directive-export 132TESTS+= directive-export-env 133TESTS+= directive-export-literal 134TESTS+= directive-for 135TESTS+= directive-for-generating-endif 136TESTS+= directive-if 137TESTS+= directive-ifdef 138TESTS+= directive-ifmake 139TESTS+= directive-ifndef 140TESTS+= directive-ifnmake 141TESTS+= directive-info 142TESTS+= directive-undef 143TESTS+= directive-unexport 144TESTS+= directive-unexport-env 145TESTS+= directive-warning 146TESTS+= directives 147TESTS+= dollar 148TESTS+= doterror 149TESTS+= dotwait 150TESTS+= envfirst 151TESTS+= error 152TESTS+= # escape # broken by reverting POSIX changes 153TESTS+= export 154TESTS+= export-all 155TESTS+= export-env 156TESTS+= export-variants 157TESTS+= forloop 158TESTS+= forsubst 159TESTS+= hash 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-g1 175TESTS+= opt-define 176TESTS+= opt-env 177TESTS+= opt-file 178TESTS+= opt-ignore 179TESTS+= opt-include-dir 180TESTS+= opt-jobs 181TESTS+= opt-jobs-internal 182TESTS+= opt-keep-going 183TESTS+= opt-m-include-dir 184TESTS+= opt-no-action 185TESTS+= opt-no-action-at-all 186TESTS+= opt-query 187TESTS+= opt-raw 188TESTS+= opt-silent 189TESTS+= opt-touch 190TESTS+= opt-tracefile 191TESTS+= opt-var-expanded 192TESTS+= opt-var-literal 193TESTS+= opt-warnings-as-errors 194TESTS+= opt-where-am-i 195TESTS+= opt-x-reduce-exported 196TESTS+= order 197TESTS+= phony-end 198TESTS+= posix 199TESTS+= # posix1 # broken by reverting POSIX changes 200TESTS+= qequals 201TESTS+= recursive 202TESTS+= sh 203TESTS+= sh-dots 204TESTS+= sh-jobs 205TESTS+= sh-jobs-error 206TESTS+= sh-leading-at 207TESTS+= sh-leading-hyphen 208TESTS+= sh-leading-plus 209TESTS+= sh-meta-chars 210TESTS+= sh-multi-line 211TESTS+= sh-single-line 212TESTS+= # suffixes # runs into an endless loop (try -dA) 213TESTS+= sunshcmd 214TESTS+= sysv 215TESTS+= ternary 216TESTS+= unexport 217TESTS+= unexport-env 218TESTS+= use-inference 219TESTS+= var-class 220TESTS+= var-class-cmdline 221TESTS+= var-class-env 222TESTS+= var-class-global 223TESTS+= var-class-local 224TESTS+= var-class-local-legacy 225TESTS+= var-op 226TESTS+= var-op-append 227TESTS+= var-op-assign 228TESTS+= var-op-default 229TESTS+= var-op-expand 230TESTS+= var-op-shell 231TESTS+= varcmd 232TESTS+= vardebug 233TESTS+= varfind 234TESTS+= varmisc 235TESTS+= varmod 236TESTS+= varmod-assign 237TESTS+= varmod-defined 238TESTS+= varmod-edge 239TESTS+= varmod-exclam-shell 240TESTS+= varmod-extension 241TESTS+= varmod-gmtime 242TESTS+= varmod-hash 243TESTS+= varmod-head 244TESTS+= varmod-ifelse 245TESTS+= varmod-l-name-to-value 246TESTS+= varmod-localtime 247TESTS+= varmod-loop 248TESTS+= varmod-match 249TESTS+= varmod-match-escape 250TESTS+= varmod-no-match 251TESTS+= varmod-order 252TESTS+= varmod-order-reverse 253TESTS+= varmod-order-shuffle 254TESTS+= varmod-path 255TESTS+= varmod-quote 256TESTS+= varmod-quote-dollar 257TESTS+= varmod-range 258TESTS+= varmod-remember 259TESTS+= varmod-root 260TESTS+= varmod-select-words 261TESTS+= varmod-shell 262TESTS+= varmod-subst 263TESTS+= varmod-subst-regex 264TESTS+= varmod-sysv 265TESTS+= varmod-tail 266TESTS+= varmod-to-abs 267TESTS+= varmod-to-lower 268TESTS+= varmod-to-many-words 269TESTS+= varmod-to-one-word 270TESTS+= varmod-to-separator 271TESTS+= varmod-to-upper 272TESTS+= varmod-undefined 273TESTS+= varmod-unique 274TESTS+= varname 275TESTS+= varname-dollar 276TESTS+= varname-dot-alltargets 277TESTS+= varname-dot-curdir 278TESTS+= varname-dot-includes 279TESTS+= varname-dot-includedfromdir 280TESTS+= varname-dot-includedfromfile 281TESTS+= varname-dot-libs 282TESTS+= varname-dot-make-dependfile 283TESTS+= varname-dot-make-expand_variables 284TESTS+= varname-dot-make-exported 285TESTS+= varname-dot-make-jobs 286TESTS+= varname-dot-make-jobs-prefix 287TESTS+= varname-dot-make-level 288TESTS+= varname-dot-make-makefile_preference 289TESTS+= varname-dot-make-makefiles 290TESTS+= varname-dot-make-meta-bailiwick 291TESTS+= varname-dot-make-meta-created 292TESTS+= varname-dot-make-meta-files 293TESTS+= varname-dot-make-meta-ignore_filter 294TESTS+= varname-dot-make-meta-ignore_paths 295TESTS+= varname-dot-make-meta-ignore_patterns 296TESTS+= varname-dot-make-meta-prefix 297TESTS+= varname-dot-make-mode 298TESTS+= varname-dot-make-path_filemon 299TESTS+= varname-dot-make-pid 300TESTS+= varname-dot-make-ppid 301TESTS+= varname-dot-make-save_dollars 302TESTS+= varname-dot-makeoverrides 303TESTS+= varname-dot-newline 304TESTS+= varname-dot-objdir 305TESTS+= varname-dot-parsedir 306TESTS+= varname-dot-parsefile 307TESTS+= varname-dot-path 308TESTS+= varname-dot-shell 309TESTS+= varname-dot-targets 310TESTS+= varname-empty 311TESTS+= varname-make 312TESTS+= varname-make_print_var_on_error 313TESTS+= varname-makeflags 314TESTS+= varname-pwd 315TESTS+= varname-vpath 316TESTS+= varparse-dynamic 317TESTS+= varquote 318TESTS+= varshell 319 320# Additional environment variables for some of the tests. 321# The base environment is -i PATH="$PATH". 322ENV.envfirst= FROM_ENV=value-from-env 323ENV.varmisc= FROM_ENV=env 324ENV.varmisc+= FROM_ENV_BEFORE=env 325ENV.varmisc+= FROM_ENV_AFTER=env 326 327# Override make flags for some of the tests; default is -k. 328# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of 329# settings FLAGS.test=-dv here, since that is closer to the test code. 330FLAGS.archive= -dA 331FLAGS.counter= -dv 332FLAGS.directive-ifmake= first second 333FLAGS.doterror= # none 334FLAGS.envfirst= -e 335FLAGS.export= # none 336FLAGS.lint= -dL -k 337FLAGS.opt-debug-g1= -dg1 338FLAGS.opt-ignore= -i 339FLAGS.opt-keep-going= -k 340FLAGS.opt-no-action= -n 341FLAGS.opt-query= -q 342FLAGS.opt-var-expanded= -v VAR -v VALUE 343FLAGS.opt-var-literal= -V VAR -V VALUE 344FLAGS.opt-warnings-as-errors= -W 345FLAGS.order= -j1 346FLAGS.recursive= -dL 347FLAGS.sh-leading-plus= -n 348FLAGS.vardebug= -k -dv FROM_CMDLINE= 349FLAGS.varmod-match-escape= -dv 350FLAGS.varname-dot-shell= -dpv 351FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain' 352 353# Some tests need extra post-processing. 354SED_CMDS.opt-debug-g1= -e 's,${.CURDIR},CURDIR,' 355SED_CMDS.opt-debug-g1+= -e '/Global Variables:/,/Suffixes:/d' 356SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<normalized: ...: not found>,' 357SED_CMDS.varmod-subst-regex+= \ 358 -e 's,\(Regex compilation error:\).*,\1 (details omitted),' 359SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,' 360SED_CMDS.varshell+= -e 's,^${.SHELL:T}: ,,' 361SED_CMDS.varshell+= -e '/command/s,No such.*,not found,' 362SED_CMDS.varname-dot-shell= -e 's, = /.*, = (details omitted),' 363SED_CMDS.varname-dot-shell+= -e 's,"/[^"]*","(details omitted)",' 364SED_CMDS.varname-dot-shell+= -e 's,\[/[^]]*\],[(details omitted)],' 365 366# Some tests need an additional round of postprocessing. 367POSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' 368POSTPROC.deptgt-suffixes= \ 369 ${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p' 370POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' 371POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p' 372POSTPROC.varname-dot-shell= \ 373 awk '/\.SHELL/ || /^ParseReadLine/' 374POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p' 375 376# Some tests reuse other tests, which makes them unnecessarily fragile. 377export-all.rawout: export.mk 378unexport.rawout: export.mk 379unexport-env.rawout: export.mk 380 381# End of the configuration section. 382 383.MAIN: all 384 385.-include "Makefile.inc" 386.-include "Makefile.config" 387 388UNIT_TESTS:= ${.PARSEDIR} 389.PATH: ${UNIT_TESTS} 390 391OUTFILES= ${TESTS:=.out} 392 393all: ${OUTFILES} 394 395CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp 396CLEANFILES+= obj*.[och] lib*.a # posix1.mk 397CLEANFILES+= issue* .[ab]* # suffixes.mk 398CLEANDIRS= dir dummy # posix1.mk 399 400clean: 401 rm -f ${CLEANFILES} 402 rm -rf ${CLEANDIRS} 403 404TEST_MAKE?= ${.MAKE} 405TOOL_SED?= sed 406TOOL_TR?= tr 407TOOL_DIFF?= diff 408DIFF_FLAGS?= -u 409 410.if defined(.PARSEDIR) 411# ensure consistent results from sort(1) 412LC_ALL= C 413LANG= C 414.export LANG LC_ALL 415.endif 416 417.if ${.MAKE.MODE:Unormal:Mmeta} != "" 418# we don't need the noise 419_MKMSG_TEST= : 420.endif 421 422# the tests are actually done with sub-makes. 423.SUFFIXES: .mk .rawout .out 424.mk.rawout: 425 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX} 426 @set -eu; \ 427 cd ${.OBJDIR}; \ 428 env -i PATH="$$PATH" ${ENV.${.TARGET:R}} \ 429 ${TEST_MAKE} \ 430 -r -C ${.CURDIR} -f ${.IMPSRC} \ 431 ${FLAGS.${.TARGET:R}:U-k} \ 432 > ${.TARGET}.tmp 2>&1 \ 433 && status=$$? || status=$$?; \ 434 echo $$status > ${.TARGET:R}.status 435 @mv ${.TARGET}.tmp ${.TARGET} 436 437# Post-process the test output so that the results can be compared. 438# 439# always pretend .MAKE was called 'make' 440_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 441_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 442# replace anything after 'stopped in' with unit-tests 443_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' 444# strip ${.CURDIR}/ from the output 445_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' 446_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 447 448.rawout.out: 449 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \ 450 < ${.IMPSRC} > ${.TARGET}.tmp1 451 @${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 452 @rm ${.TARGET}.tmp1 453 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 454 @mv ${.TARGET}.tmp2 ${.TARGET} 455 456# Compare all output files 457test: ${OUTFILES} .PHONY 458 @failed= ; \ 459 for test in ${TESTS}; do \ 460 ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \ 461 || failed="$${failed}$${failed:+ }$${test}" ; \ 462 done ; \ 463 if [ -n "$${failed}" ]; then \ 464 echo "Failed tests: $${failed}" ; false ; \ 465 else \ 466 echo "All tests passed" ; \ 467 fi 468 469accept: 470 @for test in ${TESTS}; do \ 471 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 472 || { echo "Replacing $${test}.exp" ; \ 473 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 474 done 475 476.if exists(${TEST_MAKE}) 477${TESTS:=.rawout}: ${TEST_MAKE} ${.PARSEDIR}/Makefile 478.endif 479 480.-include <obj.mk> 481