Wed Jul 29 19:48:33 2020 UTC ()
make(1): add enough tests to cover the ApplyModifier functions

Only a few return statements are still missing from the code coverage.

In ApplyModifier_Assign, the test for an empty variable name is skipped
for now since it segfaults.

In ApplyModifier_SysV after the second ParseModifierPart, the branch for
the missing delimiter is not reached since this case is already checked
for in the first part of the function. To trigger this branch, a
specially crafted, unrealistic string needs to be created, and that's too
complicated for the moment.


(rillig)
diff -r1.353 -r1.354 src/usr.bin/make/var.c
diff -r1.75 -r1.76 src/usr.bin/make/unit-tests/Makefile
diff -r1.7 -r1.8 src/usr.bin/make/unit-tests/moderrs.exp
diff -r1.6 -r1.7 src/usr.bin/make/unit-tests/moderrs.mk

cvs diff -r1.353 -r1.354 src/usr.bin/make/var.c (expand / switch to context diff)
--- src/usr.bin/make/var.c 2020/07/28 17:18:40 1.353
+++ src/usr.bin/make/var.c 2020/07/29 19:48:33 1.354
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.353 2020/07/28 17:18:40 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.354 2020/07/29 19:48:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.353 2020/07/28 17:18:40 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.354 2020/07/29 19:48:33 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.353 2020/07/28 17:18:40 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.354 2020/07/29 19:48:33 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2523,7 +2523,7 @@
 ApplyModifier_ToSep(const char *sep, ApplyModifiersState *st)
 {
     if (sep[0] != st->endc && (sep[1] == st->endc || sep[1] == ':')) {
-	/* ":ts<unrecognised><endc>" or ":ts<unrecognised>:" */
+	/* ":ts<any><endc>" or ":ts<any>:" */
 	st->sep = sep[0];
 	st->next = sep + 1;
     } else if (sep[0] == st->endc || sep[0] == ':') {

cvs diff -r1.75 -r1.76 src/usr.bin/make/unit-tests/Makefile (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/Makefile 2020/07/28 22:44:44 1.75
+++ src/usr.bin/make/unit-tests/Makefile 2020/07/29 19:48:33 1.76
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.75 2020/07/28 22:44:44 rillig Exp $
+# $NetBSD: Makefile,v 1.76 2020/07/29 19:48:33 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -94,6 +94,7 @@
 FLAGS.vardebug=		-k -dv FROM_CMDLINE=
 
 # Some tests need extra post-processing.
+SED_CMDS.moderrs+=	-e 's,\(substitution error:\).*,\1 (details omitted),'
 SED_CMDS.modmisc+=	-e 's,\(substitution error:\).*,\1 (details omitted),'
 SED_CMDS.varshell+=	-e 's,^[a-z]*sh: ,,'
 SED_CMDS.varshell+=	-e '/command/s,No such.*,not found,'

cvs diff -r1.7 -r1.8 src/usr.bin/make/unit-tests/moderrs.exp (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/moderrs.exp 2020/07/29 18:48:47 1.7
+++ src/usr.bin/make/unit-tests/moderrs.exp 2020/07/29 19:48:33 1.8
@@ -62,4 +62,76 @@
 make: Unclosed variable specification (expecting '}') for "VAR" (value "TheVariable") modifier S
 TheVariable
 TheVariable
+mod-regex-delimiter:
+make: RE substitution error: (details omitted)
+make: Unclosed substitution for VAR (, missing)
+echo
+make: Unclosed substitution for VAR (, missing)
+
+make: Unclosed substitution for VAR (, missing)
+
+make: Unclosed substitution for VAR (, missing)
+
+make: Unclosed substitution for VAR (, missing)
+
+make: Unclosed variable specification (expecting '}') for "VAR" (value "TheVariable") modifier C
+TheVariable
+TheVariable
+make: RE substitution error: (details omitted)
+1:
+make: Unclosed substitution for VAR (, missing)
+2:
+make: Unclosed substitution for VAR (, missing)
+3:
+make: Unclosed substitution for VAR (, missing)
+
+make: Unclosed substitution for VAR (, missing)
+
+make: Unclosed variable specification (expecting '}') for "VAR" (value "TheVariable") modifier C
+TheVariable
+TheVariable
+mod-ts-parse:
+112358132134
+15152535558513521534
+make: Bad modifier `:ts\65oct' for FIB
+65oct}
+make: Bad modifier `:tsxy' for FIB
+xy}
+mod-t-parse:
+make: Bad modifier `:txy' for FIB
+y}
+make: Bad modifier `:t' for FIB
+
+make: Bad modifier `:t' for FIB
+M*}
+mod-ifelse-parse:
+make: Unclosed substitution for FIB (: missing)
+
+make: Unclosed substitution for FIB (: missing)
+
+make: Unclosed substitution for FIB (} missing)
+
+make: Unclosed substitution for FIB (} missing)
+
+then
+mod-assign-parse:
+make: Unknown modifier ':'
+
+make: Unclosed substitution for ASSIGN (} missing)
+
+mod-remember-parse:
+1 1 2 3 5 8 13 21 34
+make: Unknown modifier '_'
+
+mod-sysv-parse:
+make: Unknown modifier '3'
+make: Unclosed variable specification (expecting '}') for "FIB" (value "") modifier 3
+
+make: Unknown modifier '3'
+make: Unclosed variable specification (expecting '}') for "FIB" (value "") modifier 3
+
+make: Unknown modifier '3'
+make: Unclosed variable specification (expecting '}') for "FIB" (value "") modifier 3
+
+1 1 2 x3 5 8 1x3 21 34
 exit status 0

cvs diff -r1.6 -r1.7 src/usr.bin/make/unit-tests/moderrs.mk (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/moderrs.mk 2020/07/29 18:48:47 1.6
+++ src/usr.bin/make/unit-tests/moderrs.mk 2020/07/29 19:48:33 1.7
@@ -1,4 +1,4 @@
-# $Id: moderrs.mk,v 1.6 2020/07/29 18:48:47 rillig Exp $
+# $Id: moderrs.mk,v 1.7 2020/07/29 19:48:33 rillig Exp $
 #
 # various modifier error tests
 
@@ -8,11 +8,20 @@
 MOD_TERM=S,V,v
 MOD_S:= ${MOD_TERM},
 
+FIB=	1 1 2 3 5 8 13 21 34
+
 all:	modunkn modunknV varterm vartermV modtermV modloop
 all:	modloop-close
 all:	modwords
 all:	modexclam
 all:	mod-subst-delimiter
+all:	mod-regex-delimiter
+all:	mod-ts-parse
+all:	mod-t-parse
+all:	mod-ifelse-parse
+all:	mod-assign-parse
+all:	mod-remember-parse
+all:	mod-sysv-parse
 
 modunkn:
 	@echo "Expect: Unknown modifier 'Z'"
@@ -99,3 +108,62 @@
 	@echo ${VAR:S,from,to
 	@echo ${VAR:S,from,to,
 	@echo ${VAR:S,from,to,}
+
+# XXX: Where does the "echo" in the output of "${VAR:C" come from?
+mod-regex-delimiter:
+	@echo $@:
+	@echo ${VAR:C
+	@echo ${VAR:C,
+	@echo ${VAR:C,from
+	@echo ${VAR:C,from,
+	@echo ${VAR:C,from,to
+	@echo ${VAR:C,from,to,
+	@echo ${VAR:C,from,to,}
+	@echo 1: ${VAR:C
+	@echo 2: ${VAR:C,
+	@echo 3: ${VAR:C,from
+	@echo ${VAR:C,from,
+	@echo ${VAR:C,from,to
+	@echo ${VAR:C,from,to,
+	@echo ${VAR:C,from,to,}
+
+mod-ts-parse:
+	@echo $@:
+	@echo ${FIB:ts}
+	@echo ${FIB:ts\65}	# octal 065 == U+0035 == '5'
+	@echo ${FIB:ts\65oct}	# bad modifier
+	@echo ${FIB:tsxy}	# modifier too long
+
+mod-t-parse:
+	@echo $@:
+	@echo ${FIB:txy}
+	@echo ${FIB:t}
+	@echo ${FIB:t:M*}
+
+mod-ifelse-parse:
+	@echo $@:
+	@echo ${FIB:?
+	@echo ${FIB:?then
+	@echo ${FIB:?then:
+	@echo ${FIB:?then:else
+	@echo ${FIB:?then:else}
+
+mod-assign-parse:
+	@echo $@:
+	@echo ${ASSIGN::x}	# 'x' is an unknown assignment operator
+# disabled for now; segfaults on NetBSD-8.0-x86_64 in Var_Parse line 3636:
+# *lengthPtr = tstr - str + (*tstr ? 1 : 0);
+#	@echo ${::=value}	# trying to set the empty variable
+	@echo ${ASSIGN::=value	# missing closing brace
+
+mod-remember-parse:
+	@echo $@:
+	@echo ${FIB:_}		# ok
+	@echo ${FIB:__}		# modifier name too long
+
+mod-sysv-parse:
+	@echo $@:
+	@echo ${FIB:3
+	@echo ${FIB:3=
+	@echo ${FIB:3=x3
+	@echo ${FIB:3=x3}	# ok