Module Name: src
Committed By: rillig
Date: Tue Jan 19 17:49:13 UTC 2021
Modified Files:
src/usr.bin/make: cond.c
src/usr.bin/make/unit-tests: cond-op-not.exp cond-op-not.mk
cond-op-parentheses.exp cond-op-parentheses.mk
Log Message:
make(1): demonstrate wrong return value in CondParser_Term
To generate a diff of this commit:
cvs rdiff -u -r1.235 -r1.236 src/usr.bin/make/cond.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cond-op-not.exp \
src/usr.bin/make/unit-tests/cond-op-parentheses.mk
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/cond-op-not.mk
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/cond-op-parentheses.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/cond.c
diff -u src/usr.bin/make/cond.c:1.235 src/usr.bin/make/cond.c:1.236
--- src/usr.bin/make/cond.c:1.235 Sun Jan 10 21:20:46 2021
+++ src/usr.bin/make/cond.c Tue Jan 19 17:49:13 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.235 2021/01/10 21:20:46 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.236 2021/01/19 17:49:13 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.235 2021/01/10 21:20:46 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.236 2021/01/19 17:49:13 rillig Exp $");
/*
* The parsing of conditional expressions is based on this grammar:
@@ -949,6 +949,12 @@ CondParser_Term(CondParser *par, Boolean
t = TOK_TRUE;
}
}
+
+ /*
+ * FIXME: Can at least return TOK_AND, TOK_OR, TOK_RPAREN, maybe
+ * others as well.
+ */
+ /* TODO: assert(t == TOK_ERROR); */
return t;
}
Index: src/usr.bin/make/unit-tests/cond-op-not.exp
diff -u src/usr.bin/make/unit-tests/cond-op-not.exp:1.3 src/usr.bin/make/unit-tests/cond-op-not.exp:1.4
--- src/usr.bin/make/unit-tests/cond-op-not.exp:1.3 Sun Nov 15 14:58:14 2020
+++ src/usr.bin/make/unit-tests/cond-op-not.exp Tue Jan 19 17:49:13 2021
@@ -3,4 +3,7 @@ make: "cond-op-not.mk" line 37: Not spac
make: "cond-op-not.mk" line 41: Not 0 evaluates to true.
make: "cond-op-not.mk" line 49: Not 1 evaluates to false.
make: "cond-op-not.mk" line 55: Not word evaluates to false.
-exit status 0
+make: "cond-op-not.mk" line 59: Malformed conditional (!)
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
Index: src/usr.bin/make/unit-tests/cond-op-parentheses.mk
diff -u src/usr.bin/make/unit-tests/cond-op-parentheses.mk:1.3 src/usr.bin/make/unit-tests/cond-op-parentheses.mk:1.4
--- src/usr.bin/make/unit-tests/cond-op-parentheses.mk:1.3 Sun Nov 15 14:58:14 2020
+++ src/usr.bin/make/unit-tests/cond-op-parentheses.mk Tue Jan 19 17:49:13 2021
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op-parentheses.mk,v 1.3 2020/11/15 14:58:14 rillig Exp $
+# $NetBSD: cond-op-parentheses.mk,v 1.4 2021/01/19 17:49:13 rillig Exp $
#
# Tests for parentheses in .if conditions.
@@ -15,5 +15,22 @@
. error
.endif
+# An unbalanced opening parenthesis is a parse error.
+.if (
+. error
+.else
+. error
+.endif
+
+# An unbalanced closing parenthesis is a parse error.
+#
+# As of 2021-01-19, CondParser_Term returned TOK_RPAREN even though this
+# function promised to only ever return TOK_TRUE, TOK_FALSE or TOK_ERROR.
+.if )
+. error
+.else
+. error
+.endif
+
all:
@:;
Index: src/usr.bin/make/unit-tests/cond-op-not.mk
diff -u src/usr.bin/make/unit-tests/cond-op-not.mk:1.6 src/usr.bin/make/unit-tests/cond-op-not.mk:1.7
--- src/usr.bin/make/unit-tests/cond-op-not.mk:1.6 Sun Nov 15 14:58:14 2020
+++ src/usr.bin/make/unit-tests/cond-op-not.mk Tue Jan 19 17:49:13 2021
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op-not.mk,v 1.6 2020/11/15 14:58:14 rillig Exp $
+# $NetBSD: cond-op-not.mk,v 1.7 2021/01/19 17:49:13 rillig Exp $
#
# Tests for the ! operator in .if conditions, which negates its argument.
@@ -55,5 +55,12 @@
. info Not word evaluates to false.
.endif
+# A single exclamation mark is a parse error.
+.if !
+. error
+.else
+. error
+.endif
+
all:
@:;
Index: src/usr.bin/make/unit-tests/cond-op-parentheses.exp
diff -u src/usr.bin/make/unit-tests/cond-op-parentheses.exp:1.2 src/usr.bin/make/unit-tests/cond-op-parentheses.exp:1.3
--- src/usr.bin/make/unit-tests/cond-op-parentheses.exp:1.2 Sun Nov 15 14:58:14 2020
+++ src/usr.bin/make/unit-tests/cond-op-parentheses.exp Tue Jan 19 17:49:13 2021
@@ -1,2 +1,6 @@
make: "cond-op-parentheses.mk" line 13: Parentheses can be nested at least to depth 112.
-exit status 0
+make: "cond-op-parentheses.mk" line 19: Malformed conditional (()
+make: "cond-op-parentheses.mk" line 29: Malformed conditional ())
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1