summaryrefslogtreecommitdiff
path: root/usr.bin/make
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2021-01-19 17:49:13 +0000
committerrillig <rillig@NetBSD.org>2021-01-19 17:49:13 +0000
commitc5cdcf83d6bd6a67cd29d4c3da03cf6eb794dde3 (patch)
tree9d0ac8e86e2c004d7a83902961245518866844f9 /usr.bin/make
parent8a82e20990b297064df0445b283a2c9103b7cb10 (diff)
make(1): demonstrate wrong return value in CondParser_Term
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/cond.c10
-rw-r--r--usr.bin/make/unit-tests/cond-op-not.exp5
-rw-r--r--usr.bin/make/unit-tests/cond-op-not.mk9
-rw-r--r--usr.bin/make/unit-tests/cond-op-parentheses.exp6
-rw-r--r--usr.bin/make/unit-tests/cond-op-parentheses.mk19
5 files changed, 43 insertions, 6 deletions
diff --git a/usr.bin/make/cond.c b/usr.bin/make/cond.c
index 1a8aba637fe..80329e62ffd 100644
--- a/usr.bin/make/cond.c
+++ b/usr.bin/make/cond.c
@@ -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 doEval)
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;
}
diff --git a/usr.bin/make/unit-tests/cond-op-not.exp b/usr.bin/make/unit-tests/cond-op-not.exp
index 37f57b7fdfa..440670ca724 100644
--- a/usr.bin/make/unit-tests/cond-op-not.exp
+++ b/usr.bin/make/unit-tests/cond-op-not.exp
@@ -3,4 +3,7 @@ make: "cond-op-not.mk" line 37: Not space evaluates to false.
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
diff --git a/usr.bin/make/unit-tests/cond-op-not.mk b/usr.bin/make/unit-tests/cond-op-not.mk
index 388c62d8898..ffd5bc89e4b 100644
--- a/usr.bin/make/unit-tests/cond-op-not.mk
+++ b/usr.bin/make/unit-tests/cond-op-not.mk
@@ -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:
@:;
diff --git a/usr.bin/make/unit-tests/cond-op-parentheses.exp b/usr.bin/make/unit-tests/cond-op-parentheses.exp
index a0fa137af4c..b4409330410 100644
--- a/usr.bin/make/unit-tests/cond-op-parentheses.exp
+++ b/usr.bin/make/unit-tests/cond-op-parentheses.exp
@@ -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
diff --git a/usr.bin/make/unit-tests/cond-op-parentheses.mk b/usr.bin/make/unit-tests/cond-op-parentheses.mk
index 39ebc160745..ca288cad582 100644
--- a/usr.bin/make/unit-tests/cond-op-parentheses.mk
+++ b/usr.bin/make/unit-tests/cond-op-parentheses.mk
@@ -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:
@:;