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} != ""
This commit is contained in:
sjg 2011-03-06 00:02:14 +00:00
parent be4a1e2c49
commit 8892f885fd
6 changed files with 51 additions and 9 deletions

View File

@ -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 @@ SUBFILES= \
doterror \
dotwait \
forsubst \
misc \
moderrs \
modmatch \
modmisc \
@ -35,6 +36,7 @@ SUBFILES= \
modword \
posix \
qequals \
sysv \
ternary \
unexport \
unexport-env \

View File

@ -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=clever
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}'"

View File

@ -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

View File

@ -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

View File

@ -306,6 +306,8 @@ Now we expect an error...
*** 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

View File

@ -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 @@ ApplyModifiers(char *nstr, const char *tstr,
*/
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 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr,
nstr = bmake_strndup(start, *lengthPtr);
*freePtr = nstr;
} else {
nstr = var_Error;
nstr = errnum ? var_Error : varNoError;
}
}
if (nstr != Buf_GetAll(&v->val, NULL))