Module Name:    src
Committed By:   rillig
Date:           Tue Nov 10 20:44:18 UTC 2020

Modified Files:
        src/usr.bin/make: cond.c
        src/usr.bin/make/unit-tests: cond-func.exp cond-func.mk
            directive-if.exp directive-if.mk

Log Message:
make(1): add tests for parsing conditionals, document a parsing bug


To generate a diff of this commit:
cvs rdiff -u -r1.200 -r1.201 src/usr.bin/make/cond.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cond-func.exp
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/cond-func.mk
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/directive-if.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-if.mk

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.200 src/usr.bin/make/cond.c:1.201
--- src/usr.bin/make/cond.c:1.200	Tue Nov 10 08:02:35 2020
+++ src/usr.bin/make/cond.c	Tue Nov 10 20:44:18 2020
@@ -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 @@ ParseFuncArg(const char **pp, Boolean do
 	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);

Index: src/usr.bin/make/unit-tests/cond-func.exp
diff -u src/usr.bin/make/unit-tests/cond-func.exp:1.3 src/usr.bin/make/unit-tests/cond-func.exp:1.4
--- src/usr.bin/make/unit-tests/cond-func.exp:1.3	Tue Nov 10 19:36:50 2020
+++ src/usr.bin/make/unit-tests/cond-func.exp	Tue Nov 10 20:44:18 2020
@@ -9,6 +9,7 @@ make: "cond-func.mk" line 100: A plain f
 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

Index: src/usr.bin/make/unit-tests/cond-func.mk
diff -u src/usr.bin/make/unit-tests/cond-func.mk:1.7 src/usr.bin/make/unit-tests/cond-func.mk:1.8
--- src/usr.bin/make/unit-tests/cond-func.mk:1.7	Tue Nov 10 19:36:50 2020
+++ src/usr.bin/make/unit-tests/cond-func.mk	Tue Nov 10 20:44:18 2020
@@ -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 @@ defined-var=	non-empty
 .  error
 .endif
 
+# Missing closing parenthesis when parsing the function argument.
+.if defined(
+.  error
+.else
+.  error
+.endif
+
 all:
 	@:;

Index: src/usr.bin/make/unit-tests/directive-if.exp
diff -u src/usr.bin/make/unit-tests/directive-if.exp:1.1 src/usr.bin/make/unit-tests/directive-if.exp:1.2
--- src/usr.bin/make/unit-tests/directive-if.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/directive-if.exp	Tue Nov 10 20:44:18 2020
@@ -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

Index: src/usr.bin/make/unit-tests/directive-if.mk
diff -u src/usr.bin/make/unit-tests/directive-if.mk:1.2 src/usr.bin/make/unit-tests/directive-if.mk:1.3
--- src/usr.bin/make/unit-tests/directive-if.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/directive-if.mk	Tue Nov 10 20:44:18 2020
@@ -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:
-	@:;

Reply via email to