freebsd-src/unit-tests/cond-token-var.mk
Simon J. Gerraty ee914ef902 Import bmake-20210621
Lots more unit tests and code cleanup

Relevant changes from ChangeLog

	o job.c: Print -de error information when running multiple jobs
	o var.c: only report error for unmatched regex subexpression
	when linting (-dL) since we cannot tell when an unmatched
	subexpression is an expected result.
	reduce memory allocations in the modifiers ':D' and ':U'
	reduce memory allocation and strlen calls in modifier ':from=to'
	in the ':Q' modifier, only allocate memory if necessary
	improve performance for LazyBuf
	reduce debug logging and memory allocation for ${:U...}
	reduce verbosity of the -dv debug logging for standard cases
	fix double varname expansion in the variable modifier '::='
	o var.c: avoid evaluating many modifiers in parse only mode
	in strict mode (-dL) many variable references are parsed twice,
	the first time just to report parse errors early, so we want to
	avoid side effects and wasted effort to the extent possible.
2021-06-25 11:16:24 -07:00

70 lines
1.8 KiB
Makefile

# $NetBSD: cond-token-var.mk,v 1.6 2021/04/25 21:05:38 rillig Exp $
#
# Tests for variable expressions in .if conditions.
#
# Note the fine distinction between a variable and a variable expression.
# A variable has a name and a value. To access the value, one writes a
# variable expression of the form ${VAR}. This is a simple variable
# expression. Variable expressions can get more complicated by adding
# variable modifiers such as in ${VAR:Mpattern}.
#
# XXX: Strictly speaking, variable modifiers should be called expression
# modifiers instead since they only modify the expression, not the variable.
# Well, except for the assignment modifiers, these do indeed change the value
# of the variable.
DEF= defined
# A defined variable may appear on either side of the comparison.
.if ${DEF} == ${DEF}
. info ok
.else
. error
.endif
# A variable that appears on the left-hand side must be defined.
# The following line thus generates a parse error.
.if ${UNDEF} == ${DEF}
. error
.endif
# A variable that appears on the right-hand side must be defined.
# The following line thus generates a parse error.
.if ${DEF} == ${UNDEF}
. error
.endif
# A defined variable may appear as an expression of its own.
.if ${DEF}
.endif
# An undefined variable on its own generates a parse error.
.if ${UNDEF}
.endif
# The :U modifier turns an undefined expression into a defined expression.
# Since the expression is defined now, it doesn't generate any parse error.
.if ${UNDEF:U}
.endif
# If the value of the variable expression is a number, it is compared against
# zero.
.if ${:U0}
. error
.endif
.if !${:U1}
. error
.endif
# If the value of the variable expression is not a number, any non-empty
# value evaluates to true, even if there is only whitespace.
.if ${:U}
. error
.endif
.if !${:U }
. error
.endif
.if !${:Uanything}
. error
.endif