Fri Aug 28 18:16:22 2020 UTC ()
make(1): fix test for interrupted command execution

In the first version of this test, I had completely misunderstood the
whole topic.

To test the interrupt, the make process has to be interrupted, not the
shell.  This generates the correct message that the target is removed.

The filename for .PHONY targets is removed even though .PHONY targets
usually don't correspond to a file.  The message is only printed if
there actually is a corresponding file.  That's why this message does
not appear when interrupting "make clean".

Finally, since files get created and removed during a single run of
make, the file cache needs to be disabled.  This is done by prefixing
the filenames with "././", see Dir_FindFile.


(rillig)
diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/cmd-interrupt.exp
diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/cmd-interrupt.mk

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

--- src/usr.bin/make/unit-tests/cmd-interrupt.exp 2020/08/28 15:40:53 1.1
+++ src/usr.bin/make/unit-tests/cmd-interrupt.exp 2020/08/28 18:16:22 1.2
@@ -1,17 +1,9 @@ @@ -1,17 +1,9 @@
1make -r -k -f cmd-interrupt.mk cmd-interrupt-ordinary || true 
2> cmd-interrupt-ordinary 1> cmd-interrupt-ordinary
3kill -INT $$ 2make: *** cmd-interrupt-ordinary removed
4*** Signal 2 (continuing) 3interrupt-ordinary: ok
5 
6Stop. 
7make: stopped in unit-tests 
8ok 
9make -r -k -f cmd-interrupt.mk cmd-interrupt-phony || true 
10> cmd-interrupt-phony 4> cmd-interrupt-phony
11kill -INT $$ 5make: *** cmd-interrupt-phony removed
12*** Signal 2 (continuing) 6interrupt-phony: ok
13 7> cmd-interrupt-precious
14Stop. 8interrupt-precious: ok
15make: stopped in unit-tests 
16ok 
17exit status 0 9exit status 0

cvs diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/cmd-interrupt.mk (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/cmd-interrupt.mk 2020/08/28 15:40:53 1.1
+++ src/usr.bin/make/unit-tests/cmd-interrupt.mk 2020/08/28 18:16:22 1.2
@@ -1,35 +1,50 @@ @@ -1,35 +1,50 @@
1# $NetBSD: cmd-interrupt.mk,v 1.1 2020/08/28 15:40:53 rillig Exp $ 1# $NetBSD: cmd-interrupt.mk,v 1.2 2020/08/28 18:16:22 rillig Exp $
2# 2#
3# Tests for interrupting a command. 3# Tests for interrupting a command.
4# 4#
5# If a command is interrupted (usually by the user, here by itself), the 5# If a command is interrupted (usually by the user, here by itself), the
6# target is removed. This is to avoid having an unfinished target that 6# target is removed. This is to avoid having an unfinished target that
7# would be newer than all of its sources and would therefore not be 7# would be newer than all of its sources and would therefore not be
8# tried again in the next run. 8# tried again in the next run.
9# 9#
10# For .PHONY targets, there is usually no corresponding file and therefore 10# This happens for ordinary targets as well as for .PHONY targets, even
11# nothing that could be removed. These .PHONY targets need to ensure for 11# though the .PHONY targets usually do not correspond to a file.
12# themselves that interrupting them does not leave an inconsistent state 12#
13# behind. 13# To protect the target from being removed, the target has to be marked with
14 14# the special source .PRECIOUS. These targets need to ensure for themselves
15SELF:= ${.PARSEDIR}/${.PARSEFILE} 15# that interrupting them does not leave an inconsistent state behind.
16 16#
17_!= rm -f cmd-interrupt-ordinary cmd-interrupt-phony 17# See also:
 18# CompatDeleteTarget
18 19
19all: interrupt-ordinary interrupt-phony 20all: clean-before interrupt-ordinary interrupt-phony interrupt-precious clean-after
20 21
21interrupt-ordinary: 22clean-before clean-after: .PHONY
22 ${.MAKE} ${MAKEFLAGS} -f ${SELF} cmd-interrupt-ordinary || true 23 @rm -f cmd-interrupt-ordinary cmd-interrupt-phony cmd-interrupt-precious
23 @echo ${exists(cmd-interrupt-ordinary) :? error : ok } 
24 24
25interrupt-phony: 25interrupt-ordinary: .PHONY
26 ${.MAKE} ${MAKEFLAGS} -f ${SELF} cmd-interrupt-phony || true 26 @${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-ordinary || true
27 @echo ${exists(cmd-interrupt-phony) :? ok : error } 27 # The ././ is necessary to work around the file cache.
 28 @echo ${.TARGET}: ${exists(././cmd-interrupt-ordinary) :? error : ok }
 29
 30interrupt-phony: .PHONY
 31 @${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-phony || true
 32 # The ././ is necessary to work around the file cache.
 33 @echo ${.TARGET}: ${exists(././cmd-interrupt-phony) :? error : ok }
 34
 35interrupt-precious: .PRECIOUS
 36 @${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-precious || true
 37 # The ././ is necessary to work around the file cache.
 38 @echo ${.TARGET}: ${exists(././cmd-interrupt-precious) :? ok : error }
28 39
29cmd-interrupt-ordinary: 40cmd-interrupt-ordinary:
30 > ${.TARGET} 41 > ${.TARGET}
31 kill -INT $$$$ 42 @kill -INT ${.MAKE.PID}
32 43
33cmd-interrupt-phony: .PHONY 44cmd-interrupt-phony: .PHONY
34 > ${.TARGET} 45 > ${.TARGET}
35 kill -INT $$$$ 46 @kill -INT ${.MAKE.PID}
 47
 48cmd-interrupt-precious: .PRECIOUS
 49 > ${.TARGET}
 50 @kill -INT ${.MAKE.PID}