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 tests for parsing conditionals, do...
details: https://anonhg.NetBSD.org/src/rev/a350ad28190f
branches: trunk
changeset: 1016185:a350ad28190f
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Nov 10 20:44:18 2020 +0000
description:
make(1): add tests for parsing conditionals, document a parsing bug
diffstat:
usr.bin/make/cond.c | 14 +++--------
usr.bin/make/unit-tests/cond-func.exp | 1 +
usr.bin/make/unit-tests/cond-func.mk | 9 ++++++-
usr.bin/make/unit-tests/directive-if.exp | 8 +++++-
usr.bin/make/unit-tests/directive-if.mk | 39 ++++++++++++++++++++++++++++++-
5 files changed, 57 insertions(+), 14 deletions(-)
diffs (129 lines):
diff -r a7d2a904dd1d -r a350ad28190f usr.bin/make/cond.c
--- a/usr.bin/make/cond.c Tue Nov 10 19:36:50 2020 +0000
+++ b/usr.bin/make/cond.c Tue Nov 10 20:44:18 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.200 2020/11/10 08:02:35 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.201 2020/11/10 20:44:18 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -93,7 +93,7 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.200 2020/11/10 08:02:35 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.201 2020/11/10 20:44:18 rillig Exp $");
/*
* The parsing of conditional expressions is based on this grammar:
@@ -219,14 +219,8 @@
p++; /* Skip opening '(' - verified by caller */
if (*p == '\0') {
- /*
- * No arguments whatsoever. Because 'make' and 'defined' aren't really
- * "reserved words", we don't print a message. I think this is better
- * than hitting the user with a warning message every time s/he uses
- * the word 'make' or 'defined' at the beginning of a symbol...
- */
- *out_arg = NULL;
- return 0;
+ *out_arg = NULL; /* Missing closing parenthesis: */
+ return 0; /* .if defined( */
}
cpp_skip_hspace(&p);
diff -r a7d2a904dd1d -r a350ad28190f usr.bin/make/unit-tests/cond-func.exp
--- a/usr.bin/make/unit-tests/cond-func.exp Tue Nov 10 19:36:50 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-func.exp Tue Nov 10 20:44:18 2020 +0000
@@ -9,6 +9,7 @@
make: "cond-func.mk" line 107: A plain function name is parsed as !empty(...).
make: "cond-func.mk" line 117: Symbols may start with a function name.
make: "cond-func.mk" line 122: Symbols may start with a function name.
+make: "cond-func.mk" line 128: Malformed conditional (defined()
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff -r a7d2a904dd1d -r a350ad28190f usr.bin/make/unit-tests/cond-func.mk
--- a/usr.bin/make/unit-tests/cond-func.mk Tue Nov 10 19:36:50 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-func.mk Tue Nov 10 20:44:18 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cond-func.mk,v 1.7 2020/11/10 19:36:50 rillig Exp $
+# $NetBSD: cond-func.mk,v 1.8 2020/11/10 20:44:18 rillig Exp $
#
# Tests for those parts of the functions in .if conditions that are common
# among several functions.
@@ -124,5 +124,12 @@
. error
.endif
+# Missing closing parenthesis when parsing the function argument.
+.if defined(
+. error
+.else
+. error
+.endif
+
all:
@:;
diff -r a7d2a904dd1d -r a350ad28190f usr.bin/make/unit-tests/directive-if.exp
--- a/usr.bin/make/unit-tests/directive-if.exp Tue Nov 10 19:36:50 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-if.exp Tue Nov 10 20:44:18 2020 +0000
@@ -1,1 +1,7 @@
-exit status 0
+make: "directive-if.mk" line 10: 0 evaluates to false.
+make: "directive-if.mk" line 14: 1 evaluates to true.
+make: "directive-if.mk" line 30: Malformed conditional (x 123)
+make: "directive-if.mk" line 37: Malformed conditional ()
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff -r a7d2a904dd1d -r a350ad28190f usr.bin/make/unit-tests/directive-if.mk
--- a/usr.bin/make/unit-tests/directive-if.mk Tue Nov 10 19:36:50 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-if.mk Tue Nov 10 20:44:18 2020 +0000
@@ -1,8 +1,43 @@
-# $NetBSD: directive-if.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: directive-if.mk,v 1.3 2020/11/10 20:44:18 rillig Exp $
#
# Tests for the .if directive.
# TODO: Implementation
+.if 0
+. error
+.else
+. info 0 evaluates to false.
+.endif
+
+.if 1
+. info 1 evaluates to true.
+.else
+. error
+.endif
+
+# There is no '.ifx'.
+#
+# The commit from 2005-05-01 intended to detect this situation, but it failed
+# to do this since the call to is_token has its arguments switched. They are
+# expected as (str, token, token_len) but are actually passed as (token, str,
+# token_len). This made is_token return true even if the directive was
+# directly followed by alphanumerical characters.
+#
+# Back at that time, the commits only modified the main code but did not add
+# the corresponding unit tests. This allowed the bug to hide for more than
+# 15 years.
+.ifx 123
+. error
+.else
+. error
+.endif
+
+# Missing condition.
+.if
+. error
+.else
+. error
+.endif
+
all:
- @:;
Home |
Main Index |
Thread Index |
Old Index