Module Name:    src
Committed By:   rillig
Date:           Wed Jul 29 19:48:33 UTC 2020

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: Makefile moderrs.exp moderrs.mk

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.353 -r1.354 src/usr.bin/make/var.c
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/moderrs.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/moderrs.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.353 src/usr.bin/make/var.c:1.354
--- src/usr.bin/make/var.c:1.353	Tue Jul 28 17:18:40 2020
+++ src/usr.bin/make/var.c	Wed Jul 29 19:48:33 2020
@@ -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 @@ static Boolean
 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] == ':') {

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.75 src/usr.bin/make/unit-tests/Makefile:1.76
--- src/usr.bin/make/unit-tests/Makefile:1.75	Tue Jul 28 22:44:44 2020
+++ src/usr.bin/make/unit-tests/Makefile	Wed Jul 29 19:48:33 2020
@@ -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.order=		-j1
 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,'

Index: src/usr.bin/make/unit-tests/moderrs.exp
diff -u src/usr.bin/make/unit-tests/moderrs.exp:1.7 src/usr.bin/make/unit-tests/moderrs.exp:1.8
--- src/usr.bin/make/unit-tests/moderrs.exp:1.7	Wed Jul 29 18:48:47 2020
+++ src/usr.bin/make/unit-tests/moderrs.exp	Wed Jul 29 19:48:33 2020
@@ -62,4 +62,76 @@ make: Unclosed substitution for VAR (, m
 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

Index: src/usr.bin/make/unit-tests/moderrs.mk
diff -u src/usr.bin/make/unit-tests/moderrs.mk:1.6 src/usr.bin/make/unit-tests/moderrs.mk:1.7
--- src/usr.bin/make/unit-tests/moderrs.mk:1.6	Wed Jul 29 18:48:47 2020
+++ src/usr.bin/make/unit-tests/moderrs.mk	Wed Jul 29 19:48:33 2020
@@ -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_UNKN=Z
 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 @@ mod-subst-delimiter:
 	@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

Reply via email to