Module Name: src
Committed By: rillig
Date: Fri Aug 28 15:40:54 UTC 2020
Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make/unit-tests: Makefile
Added Files:
src/usr.bin/make/unit-tests: cmd-interrupt.exp cmd-interrupt.mk
Log Message:
make(1): add test for interrupting a command
To generate a diff of this commit:
cvs rdiff -u -r1.911 -r1.912 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.123 -r1.124 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/cmd-interrupt.exp \
src/usr.bin/make/unit-tests/cmd-interrupt.mk
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.911 src/distrib/sets/lists/tests/mi:1.912
--- src/distrib/sets/lists/tests/mi:1.911 Fri Aug 28 03:51:06 2020
+++ src/distrib/sets/lists/tests/mi Fri Aug 28 15:40:53 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.911 2020/08/28 03:51:06 rillig Exp $
+# $NetBSD: mi,v 1.912 2020/08/28 15:40:53 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -4540,6 +4540,8 @@
./usr/tests/usr.bin/make/unit-tests/Makefile tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/archive.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/archive.mk tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cmd-interrupt.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cmd-interrupt.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cmdline.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cmdline.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/comment.exp tests-usr.bin-tests compattestfile,atf
Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.123 src/usr.bin/make/unit-tests/Makefile:1.124
--- src/usr.bin/make/unit-tests/Makefile:1.123 Fri Aug 28 04:05:35 2020
+++ src/usr.bin/make/unit-tests/Makefile Fri Aug 28 15:40:53 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.123 2020/08/28 04:05:35 rillig Exp $
+# $NetBSD: Makefile,v 1.124 2020/08/28 15:40:53 rillig Exp $
#
# Unit tests for make(1)
#
@@ -36,6 +36,7 @@
# Any test that is commented out must be ignored in
# src/tests/usr.bin/make/t_make.sh as well.
TESTS+= # archive # broken on FreeBSD, enabled in t_make.sh
+TESTS+= cmd-interrupt
TESTS+= cmdline
TESTS+= comment
TESTS+= cond-cmp-numeric
Added files:
Index: src/usr.bin/make/unit-tests/cmd-interrupt.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cmd-interrupt.exp:1.1
--- /dev/null Fri Aug 28 15:40:54 2020
+++ src/usr.bin/make/unit-tests/cmd-interrupt.exp Fri Aug 28 15:40:53 2020
@@ -0,0 +1,17 @@
+make -r -k -f cmd-interrupt.mk cmd-interrupt-ordinary || true
+> cmd-interrupt-ordinary
+kill -INT $$
+*** Signal 2 (continuing)
+
+Stop.
+make: stopped in unit-tests
+ok
+make -r -k -f cmd-interrupt.mk cmd-interrupt-phony || true
+> cmd-interrupt-phony
+kill -INT $$
+*** Signal 2 (continuing)
+
+Stop.
+make: stopped in unit-tests
+ok
+exit status 0
Index: src/usr.bin/make/unit-tests/cmd-interrupt.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cmd-interrupt.mk:1.1
--- /dev/null Fri Aug 28 15:40:54 2020
+++ src/usr.bin/make/unit-tests/cmd-interrupt.mk Fri Aug 28 15:40:53 2020
@@ -0,0 +1,35 @@
+# $NetBSD: cmd-interrupt.mk,v 1.1 2020/08/28 15:40:53 rillig Exp $
+#
+# Tests for interrupting a command.
+#
+# If a command is interrupted (usually by the user, here by itself), the
+# target is removed. This is to avoid having an unfinished target that
+# would be newer than all of its sources and would therefore not be
+# tried again in the next run.
+#
+# For .PHONY targets, there is usually no corresponding file and therefore
+# nothing that could be removed. These .PHONY targets need to ensure for
+# themselves that interrupting them does not leave an inconsistent state
+# behind.
+
+SELF:= ${.PARSEDIR}/${.PARSEFILE}
+
+_!= rm -f cmd-interrupt-ordinary cmd-interrupt-phony
+
+all: interrupt-ordinary interrupt-phony
+
+interrupt-ordinary:
+ ${.MAKE} ${MAKEFLAGS} -f ${SELF} cmd-interrupt-ordinary || true
+ @echo ${exists(cmd-interrupt-ordinary) :? error : ok }
+
+interrupt-phony:
+ ${.MAKE} ${MAKEFLAGS} -f ${SELF} cmd-interrupt-phony || true
+ @echo ${exists(cmd-interrupt-phony) :? ok : error }
+
+cmd-interrupt-ordinary:
+ > ${.TARGET}
+ kill -INT $$$$
+
+cmd-interrupt-phony: .PHONY
+ > ${.TARGET}
+ kill -INT $$$$