tests/make: refine comments for parsing and evaluating conditions

This commit is contained in:
rillig 2021-12-12 09:36:00 +00:00
parent 0e6a3361ec
commit fb0e49c8d2
3 changed files with 29 additions and 22 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cond.c,v 1.301 2021/12/12 08:55:28 rillig Exp $ */
/* $NetBSD: cond.c,v 1.302 2021/12/12 09:36:00 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.301 2021/12/12 08:55:28 rillig Exp $");
MAKE_RCSID("$NetBSD: cond.c,v 1.302 2021/12/12 09:36:00 rillig Exp $");
/*
* The parsing of conditional expressions is based on this grammar:
@ -782,8 +782,11 @@ CondParser_FuncCall(CondParser *par, bool doEval, Token *out_token)
}
/*
* Parse a comparison such as '${VAR} == "value"', or a simple leaf without
* Parse a comparison that neither starts with '"' nor '$', such as the
* unusual 'bare == right' or '3 == ${VAR}', or a simple leaf without
* operator, which is a number, a variable expression or a string literal.
*
* TODO: Can this be merged into CondParser_Comparison?
*/
static Token
CondParser_ComparisonOrLeaf(CondParser *par, bool doEval)

View File

@ -27,35 +27,35 @@ lhs = "var&&name", rhs = "var&&name", op = !=
CondParser_Eval: ${:Uvar}||name != "var||name"
lhs = "var||name", rhs = "var||name", op = !=
CondParser_Eval: bare
make: "cond-token-plain.mk" line 102: A bare word is treated like defined(...), and the variable 'bare' is not defined.
make: "cond-token-plain.mk" line 106: A bare word is treated like defined(...), and the variable 'bare' is not defined.
CondParser_Eval: VAR
make: "cond-token-plain.mk" line 107: A bare word is treated like defined(...).
make: "cond-token-plain.mk" line 111: A bare word is treated like defined(...).
CondParser_Eval: V${:UA}R
make: "cond-token-plain.mk" line 114: ok
make: "cond-token-plain.mk" line 118: ok
CondParser_Eval: V${UNDEF}AR
make: "cond-token-plain.mk" line 122: Undefined variables in bare words expand to an empty string.
make: "cond-token-plain.mk" line 126: Undefined variables in bare words expand to an empty string.
CondParser_Eval: 0${:Ux00}
make: "cond-token-plain.mk" line 130: Numbers can be composed from literals and variable expressions.
CondParser_Eval: 0${:Ux01}
make: "cond-token-plain.mk" line 134: Numbers can be composed from literals and variable expressions.
CondParser_Eval: 0${:Ux01}
make: "cond-token-plain.mk" line 138: Numbers can be composed from literals and variable expressions.
CondParser_Eval: "" ==
make: "cond-token-plain.mk" line 140: Missing right-hand side of operator '=='
make: "cond-token-plain.mk" line 144: Missing right-hand side of operator '=='
CondParser_Eval: == ""
make: "cond-token-plain.mk" line 148: Malformed conditional (== "")
make: "cond-token-plain.mk" line 152: Malformed conditional (== "")
CondParser_Eval: \\
make: "cond-token-plain.mk" line 163: The variable '\\' is not defined.
make: "cond-token-plain.mk" line 167: The variable '\\' is not defined.
CondParser_Eval: \\
make: "cond-token-plain.mk" line 168: Now the variable '\\' is defined.
make: "cond-token-plain.mk" line 172: Now the variable '\\' is defined.
CondParser_Eval: "unquoted\"quoted" != unquoted"quoted
lhs = "unquoted"quoted", rhs = "unquoted"quoted", op = !=
CondParser_Eval: $$$$$$$$ != ""
CondParser_Eval: left == right
make: "cond-token-plain.mk" line 191: Malformed conditional (left == right)
make: "cond-token-plain.mk" line 195: Malformed conditional (left == right)
CondParser_Eval: ${0:?:} || left == right
CondParser_Eval: 0
make: "cond-token-plain.mk" line 197: Malformed conditional (${0:?:} || left == right)
make: "cond-token-plain.mk" line 201: Malformed conditional (${0:?:} || left == right)
CondParser_Eval: left == right || ${0:?:}
make: "cond-token-plain.mk" line 202: Malformed conditional (left == right || ${0:?:})
make: "cond-token-plain.mk" line 206: Malformed conditional (left == right || ${0:?:})
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1

View File

@ -1,17 +1,18 @@
# $NetBSD: cond-token-plain.mk,v 1.13 2021/12/12 08:55:28 rillig Exp $
# $NetBSD: cond-token-plain.mk,v 1.14 2021/12/12 09:36:00 rillig Exp $
#
# Tests for plain tokens (that is, string literals without quotes)
# in .if conditions.
# in .if conditions. These are also called bare words.
.MAKEFLAGS: -dc
# The word 'value' after the '!=' is a bare word.
.if ${:Uvalue} != value
. error
.endif
# Malformed condition since comment parsing is done in an early phase
# and removes the '#' and everything behind it long before the condition
# parser gets to see it.
# Using a '#' in a string literal in a condition leads to a malformed
# condition since comment parsing is done in an early phase and removes the
# '#' and everything after it long before the condition parser gets to see it.
#
# XXX: The error message is missing for this malformed condition.
# The right-hand side of the comparison is just a '"', before unescaping.
@ -32,7 +33,10 @@
# in a very early parsing phase.
#
# See https://gnats.netbsd.org/19596 for example makefiles demonstrating the
# original problems. This workaround is probably not needed anymore.
# original problems. At that time, the parser didn't recognize the comment in
# the line '.else # comment3'. This workaround is not needed anymore since
# comments are stripped in an earlier phase. See "case '#'" in
# CondParser_Token.
#
# XXX: Missing error message for the malformed condition. The right-hand
# side before unescaping is double-quotes, backslash, backslash.