Sat Aug 29 19:07:32 2020 UTC ()
make(1): add test for the .ifmake directive


(rillig)
diff -r1.127 -r1.128 src/usr.bin/make/unit-tests/Makefile
diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/directive-ifmake.exp
diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-ifmake.mk

cvs diff -r1.127 -r1.128 src/usr.bin/make/unit-tests/Makefile (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/Makefile 2020/08/29 18:50:25 1.127
+++ src/usr.bin/make/unit-tests/Makefile 2020/08/29 19:07:32 1.128
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: Makefile,v 1.127 2020/08/29 18:50:25 rillig Exp $ 1# $NetBSD: Makefile,v 1.128 2020/08/29 19:07:32 rillig Exp $
2# 2#
3# Unit tests for make(1) 3# Unit tests for make(1)
4# 4#
5# The main targets are: 5# The main targets are:
6# 6#
7# all: 7# all:
8# run all the tests 8# run all the tests
9# test: 9# test:
10# run 'all', and compare to expected results 10# run 'all', and compare to expected results
11# accept: 11# accept:
12# move generated output to expected results 12# move generated output to expected results
13# 13#
14# Settable variables 14# Settable variables
@@ -319,26 +319,27 @@ TESTS+= varshell @@ -319,26 +319,27 @@ TESTS+= varshell
319 319
320# Additional environment variables for some of the tests. 320# Additional environment variables for some of the tests.
321# The base environment is -i PATH="$PATH". 321# The base environment is -i PATH="$PATH".
322ENV.envfirst= FROM_ENV=value-from-env 322ENV.envfirst= FROM_ENV=value-from-env
323ENV.varmisc= FROM_ENV=env 323ENV.varmisc= FROM_ENV=env
324ENV.varmisc+= FROM_ENV_BEFORE=env 324ENV.varmisc+= FROM_ENV_BEFORE=env
325ENV.varmisc+= FROM_ENV_AFTER=env 325ENV.varmisc+= FROM_ENV_AFTER=env
326 326
327# Override make flags for some of the tests; default is -k. 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 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. 329# settings FLAGS.test=-dv here, since that is closer to the test code.
330FLAGS.archive= -dA 330FLAGS.archive= -dA
331FLAGS.counter= -dv 331FLAGS.counter= -dv
 332FLAGS.directive-ifmake= first second
332FLAGS.doterror= # none 333FLAGS.doterror= # none
333FLAGS.envfirst= -e 334FLAGS.envfirst= -e
334FLAGS.export= # none 335FLAGS.export= # none
335FLAGS.lint= -dL -k 336FLAGS.lint= -dL -k
336FLAGS.opt-debug-g1= -dg1 337FLAGS.opt-debug-g1= -dg1
337FLAGS.opt-ignore= -i 338FLAGS.opt-ignore= -i
338FLAGS.opt-keep-going= -k 339FLAGS.opt-keep-going= -k
339FLAGS.opt-no-action= -n 340FLAGS.opt-no-action= -n
340FLAGS.opt-query= -q 341FLAGS.opt-query= -q
341FLAGS.opt-var-expanded= -v VAR -v VALUE 342FLAGS.opt-var-expanded= -v VAR -v VALUE
342FLAGS.opt-var-literal= -V VAR -V VALUE 343FLAGS.opt-var-literal= -V VAR -V VALUE
343FLAGS.opt-warnings-as-errors= -W 344FLAGS.opt-warnings-as-errors= -W
344FLAGS.order= -j1 345FLAGS.order= -j1

cvs diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/directive-ifmake.exp (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/directive-ifmake.exp 2020/08/16 12:07:51 1.1
+++ src/usr.bin/make/unit-tests/directive-ifmake.exp 2020/08/29 19:07:32 1.2

cvs diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-ifmake.mk (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/directive-ifmake.mk 2020/08/16 14:25:16 1.2
+++ src/usr.bin/make/unit-tests/directive-ifmake.mk 2020/08/29 19:07:32 1.3
@@ -1,8 +1,45 @@ @@ -1,8 +1,45 @@
1# $NetBSD: directive-ifmake.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $ 1# $NetBSD: directive-ifmake.mk,v 1.3 2020/08/29 19:07:32 rillig Exp $
2# 2#
3# Tests for the .ifmake directive. 3# Tests for the .ifmake directive, which provides a shortcut for asking
 4# whether a certain target is requested to be made from the command line.
4 5
5# TODO: Implementation 6# This is the most basic form.
 7.ifmake first
 8.info ok: positive condition works
 9.else
 10.warning positive condition fails
 11.endif
6 12
7all: 13# The not operator works as expected.
8 @:; 14# An alternative interpretation were that this condition is asking whether
 15# the target "!first" was requested. To distinguish this, see the next test.
 16.ifmake !first
 17.warning unexpected
 18.else
 19.info ok: negation works
 20.endif
 21
 22# See if the exclamation mark really means "not", or if it is just part of
 23# the target name.
 24.ifmake !!first
 25.info ok: double negation works
 26.else
 27.warning double negation fails
 28.endif
 29
 30# Multiple targets can be combined using the && and || operators.
 31.ifmake first && second
 32.info ok: both mentioned
 33.else
 34.warning && does not work as expected
 35.endif
 36
 37# Negation also works in complex conditions.
 38.ifmake first && !unmentioned
 39.info ok: only those mentioned
 40.else
 41.warning && with ! does not work as expected
 42.endif
 43
 44first second unmentioned:
 45 : $@