Module Name:    src
Committed By:   sjg
Date:           Sun Mar  6 00:02:15 UTC 2011

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: Makefile cond1 test.exp
Added Files:
        src/usr.bin/make/unit-tests: misc sysv

Log Message:
Add unit tests to check that exists(some/dir/) works

Also fix handling of sysV substitutions when lhs and variable are empty.

Also that modifiers do not cause errors during conditional tests
when undefined variables should otherwise be ok.
Ie. .if defined(nosuch) && ${nosuch:Mx} != ""


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/usr.bin/make/var.c
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cond1
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/misc \
    src/usr.bin/make/unit-tests/sysv
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/make/unit-tests/test.exp

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.161 src/usr.bin/make/var.c:1.162
--- src/usr.bin/make/var.c:1.161	Thu Dec  2 16:46:22 2010
+++ src/usr.bin/make/var.c	Sun Mar  6 00:02:15 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.161 2010/12/02 16:46:22 christos Exp $	*/
+/*	$NetBSD: var.c,v 1.162 2011/03/06 00:02:15 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.161 2010/12/02 16:46:22 christos Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.162 2011/03/06 00:02:15 sjg 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.161 2010/12/02 16:46:22 christos Exp $");
+__RCSID("$NetBSD: var.c,v 1.162 2011/03/06 00:02:15 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -3346,9 +3346,13 @@
 		 */
 		termc = *--cp;
 		delim = '\0';
-		newStr = VarModify(ctxt, &parsestate, nstr,
-				   VarSYSVMatch,
-				   &pattern);
+		if (pattern.leftLen == 0 && *nstr == '\0') {
+		    newStr = nstr;	/* special case */
+		} else {
+		    newStr = VarModify(ctxt, &parsestate, nstr,
+				       VarSYSVMatch,
+				       &pattern);
+		}
 		free(UNCONST(pattern.lhs));
 		free(UNCONST(pattern.rhs));
 	    } else
@@ -3746,7 +3750,7 @@
 		nstr = bmake_strndup(start, *lengthPtr);
 		*freePtr = nstr;
 	    } else {
-		nstr = var_Error;
+		nstr = errnum ? var_Error : varNoError;
 	    }
 	}
 	if (nstr != Buf_GetAll(&v->val, NULL))

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.30 src/usr.bin/make/unit-tests/Makefile:1.31
--- src/usr.bin/make/unit-tests/Makefile:1.30	Fri Dec 10 00:37:23 2010
+++ src/usr.bin/make/unit-tests/Makefile	Sun Mar  6 00:02:14 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.30 2010/12/10 00:37:23 sjg Exp $
+# $NetBSD: Makefile,v 1.31 2011/03/06 00:02:14 sjg Exp $
 #
 # Unit tests for make(1)
 # The main targets are:
@@ -27,6 +27,7 @@
 	doterror \
 	dotwait \
 	forsubst \
+	misc \
 	moderrs \
 	modmatch \
 	modmisc \
@@ -35,6 +36,7 @@
 	modword \
 	posix \
 	qequals \
+	sysv \
 	ternary \
 	unexport \
 	unexport-env \

Index: src/usr.bin/make/unit-tests/cond1
diff -u src/usr.bin/make/unit-tests/cond1:1.4 src/usr.bin/make/unit-tests/cond1:1.5
--- src/usr.bin/make/unit-tests/cond1:1.4	Wed Oct 29 15:37:08 2008
+++ src/usr.bin/make/unit-tests/cond1	Sun Mar  6 00:02:14 2011
@@ -1,4 +1,4 @@
-# $Id: cond1,v 1.4 2008/10/29 15:37:08 sjg Exp $
+# $Id: cond1,v 1.5 2011/03/06 00:02:14 sjg Exp $
 
 # hard code these!
 TEST_UNAME_S= NetBSD
@@ -95,6 +95,11 @@
 C=dim
 .endif
 
+.if defined(nosuch) && ${nosuch:Mx} != ""
+# this should not happen
+.info nosuch is x
+.endif
+
 all:
 	@echo "$n is $X prime"
 	@echo "A='$A' B='$B' C='$C' o='$o,${o2}'"

Index: src/usr.bin/make/unit-tests/test.exp
diff -u src/usr.bin/make/unit-tests/test.exp:1.34 src/usr.bin/make/unit-tests/test.exp:1.35
--- src/usr.bin/make/unit-tests/test.exp:1.34	Fri Apr 23 15:43:28 2010
+++ src/usr.bin/make/unit-tests/test.exp	Sun Mar  6 00:02:14 2011
@@ -306,6 +306,8 @@
 *** Error code 1 (continuing)
 `all' not remade because of errors.
 V.i386 ?= OK
+FOOBAR =
+FOOBAR = foobar fubar
 The answer is unknown
 The answer is unknown
 The answer is empty

Added files:

Index: src/usr.bin/make/unit-tests/misc
diff -u /dev/null src/usr.bin/make/unit-tests/misc:1.1
--- /dev/null	Sun Mar  6 00:02:15 2011
+++ src/usr.bin/make/unit-tests/misc	Sun Mar  6 00:02:14 2011
@@ -0,0 +1,16 @@
+# $Id: misc,v 1.1 2011/03/06 00:02:14 sjg Exp $
+
+.if !exists(${.CURDIR}/)
+.warning ${.CURDIR}/ doesn't exist ?
+.endif
+
+.if !exists(${.CURDIR}/.)
+.warning ${.CURDIR}/. doesn't exist ?
+.endif
+
+.if !exists(${.CURDIR}/..)
+.warning ${.CURDIR}/.. doesn't exist ?
+.endif
+
+all:
+	@: all is well
Index: src/usr.bin/make/unit-tests/sysv
diff -u /dev/null src/usr.bin/make/unit-tests/sysv:1.1
--- /dev/null	Sun Mar  6 00:02:15 2011
+++ src/usr.bin/make/unit-tests/sysv	Sun Mar  6 00:02:14 2011
@@ -0,0 +1,13 @@
+# $Id: sysv,v 1.1 2011/03/06 00:02:14 sjg Exp $
+
+FOO ?=
+FOOBAR = $(FOO:=bar)
+
+_this := ${.PARSEDIR}/${.PARSEFILE}
+
+# we expect nothing when FOO is empty
+all:
+	@echo FOOBAR = $(FOOBAR)
+.if empty(FOO)
+	@FOO="foo fu" ${.MAKE} -f ${_this}
+.endif

Reply via email to