Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): add enough tests to cover the ApplyMod...



details:   https://anonhg.NetBSD.org/src/rev/94d89423af62
branches:  trunk
changeset: 936548:94d89423af62
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Jul 29 19:48:33 2020 +0000

description:
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.

diffstat:

 usr.bin/make/unit-tests/Makefile    |   3 +-
 usr.bin/make/unit-tests/moderrs.exp |  72 +++++++++++++++++++++++++++++++++++++
 usr.bin/make/unit-tests/moderrs.mk  |  70 +++++++++++++++++++++++++++++++++++-
 usr.bin/make/var.c                  |   8 ++--
 4 files changed, 147 insertions(+), 6 deletions(-)

diffs (225 lines):

diff -r 5e4080bff629 -r 94d89423af62 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Wed Jul 29 18:48:47 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Wed Jul 29 19:48:33 2020 +0000
@@ -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,'
diff -r 5e4080bff629 -r 94d89423af62 usr.bin/make/unit-tests/moderrs.exp
--- a/usr.bin/make/unit-tests/moderrs.exp       Wed Jul 29 18:48:47 2020 +0000
+++ b/usr.bin/make/unit-tests/moderrs.exp       Wed Jul 29 19:48:33 2020 +0000
@@ -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
diff -r 5e4080bff629 -r 94d89423af62 usr.bin/make/unit-tests/moderrs.mk
--- a/usr.bin/make/unit-tests/moderrs.mk        Wed Jul 29 18:48:47 2020 +0000
+++ b/usr.bin/make/unit-tests/moderrs.mk        Wed Jul 29 19:48:33 2020 +0000
@@ -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
diff -r 5e4080bff629 -r 94d89423af62 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Wed Jul 29 18:48:47 2020 +0000
+++ b/usr.bin/make/var.c        Wed Jul 29 19:48:33 2020 +0000
@@ -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] == ':') {



Home | Main Index | Thread Index | Old Index