Module Name:    src
Committed By:   rillig
Date:           Tue Nov 30 20:48:01 UTC 2021

Modified Files:
        src/usr.bin/make/unit-tests: varmod-assign.exp varmod-assign.mk

Log Message:
tests/make: convert tests for modifier '::=' to parse time

This puts the expected result of the expressions closer to the
expressions, making the tests self-contained.

The error messages that used to produce trailing spaces have been fixed
in var.c 1.853 from 2021-02-23. The error message now encloses the
variable name in quotes.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/make/unit-tests/varmod-assign.exp
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/varmod-assign.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/unit-tests/varmod-assign.exp
diff -u src/usr.bin/make/unit-tests/varmod-assign.exp:1.16 src/usr.bin/make/unit-tests/varmod-assign.exp:1.17
--- src/usr.bin/make/unit-tests/varmod-assign.exp:1.16	Tue Apr  6 01:38:39 2021
+++ src/usr.bin/make/unit-tests/varmod-assign.exp	Tue Nov 30 20:48:01 2021
@@ -12,18 +12,6 @@ Var_Parse: ${${VARNAME}} != "assigned-va
 Var_Parse: ${VARNAME}} != "assigned-value" (eval-defined)
 Global: .MAKEFLAGS =  -r -k -d v -d
 Global: .MAKEFLAGS =  -r -k -d v -d 0
-mod-assign: first=1.
-mod-assign: last=3.
-mod-assign: appended=1 2 3.
-1
-2
-3
-mod-assign: ran:3.
-mod-assign: global: 1, 3, 1 2 3, 3.
-mod-assign-nested: then1t1
-mod-assign-nested: else2e2
-mod-assign-nested: then3t3
-mod-assign-nested: else4e4
 make: Bad modifier ":" for variable ""
 mod-assign-empty: value}
 make: Bad modifier ":" for variable ""

Index: src/usr.bin/make/unit-tests/varmod-assign.mk
diff -u src/usr.bin/make/unit-tests/varmod-assign.mk:1.12 src/usr.bin/make/unit-tests/varmod-assign.mk:1.13
--- src/usr.bin/make/unit-tests/varmod-assign.mk:1.12	Mon Mar 15 18:56:38 2021
+++ src/usr.bin/make/unit-tests/varmod-assign.mk	Tue Nov 30 20:48:01 2021
@@ -1,70 +1,79 @@
-# $NetBSD: varmod-assign.mk,v 1.12 2021/03/15 18:56:38 rillig Exp $
+# $NetBSD: varmod-assign.mk,v 1.13 2021/11/30 20:48:01 rillig Exp $
 #
 # Tests for the obscure ::= variable modifiers, which perform variable
 # assignments during evaluation, just like the = operator in C.
 
-all:	mod-assign
-all:	mod-assign-nested
 all:	mod-assign-empty
 all:	mod-assign-parse
 all:	mod-assign-shell-error
 
-mod-assign:
-	# The ::?= modifier applies the ?= assignment operator 3 times.
-	# The ?= operator only has an effect for the first time, therefore
-	# the variable FIRST ends up with the value 1.
-	@echo $@: ${1 2 3:L:@i@${FIRST::?=$i}@} first=${FIRST}.
-
-	# The ::= modifier applies the = assignment operator 3 times.
-	# The = operator overwrites the previous value, therefore the
-	# variable LAST ends up with the value 3.
-	@echo $@: ${1 2 3:L:@i@${LAST::=$i}@} last=${LAST}.
-
-	# The ::+= modifier applies the += assignment operator 3 times.
-	# The += operator appends 3 times to the variable, therefore
-	# the variable APPENDED ends up with the value "1 2 3".
-	@echo $@: ${1 2 3:L:@i@${APPENDED::+=$i}@} appended=${APPENDED}.
-
-	# The ::!= modifier applies the != assignment operator 3 times.
-	# The side effects of the shell commands are visible in the output.
-	# Just as with the ::= modifier, the last value is stored in the
-	# RAN variable.
-	@echo $@: ${echo.1 echo.2 echo.3:L:@i@${RAN::!=${i:C,.*,&; & 1>\&2,:S,., ,g}}@} ran:${RAN}.
-
-	# The assignments happen in the global scope and thus are
-	# preserved even after the shell command has been run.
-	@echo $@: global: ${FIRST:Q}, ${LAST:Q}, ${APPENDED:Q}, ${RAN:Q}.
-
-mod-assign-nested:
-	# The condition "1" is true, therefore THEN1 gets assigned a value,
-	# and IT1 as well.  Nothing surprising here.
-	@echo $@: ${1:?${THEN1::=then1${IT1::=t1}}:${ELSE1::=else1${IE1::=e1}}}${THEN1}${ELSE1}${IT1}${IE1}
-
-	# The condition "0" is false, therefore ELSE1 gets assigned a value,
-	# and IE1 as well.  Nothing surprising here as well.
-	@echo $@: ${0:?${THEN2::=then2${IT2::=t2}}:${ELSE2::=else2${IE2::=e2}}}${THEN2}${ELSE2}${IT2}${IE2}
-
-	# The same effects happen when the variables are defined elsewhere.
-	@echo $@: ${SINK3:Q}
-	@echo $@: ${SINK4:Q}
+# The modifier '::?=' applies the assignment operator '?=' 3 times. The
+# operator '?=' only has an effect for the first time, therefore the variable
+# FIRST ends up with the value 1.
+.if "${1 2 3:L:@i@${FIRST::?=$i}@} first=${FIRST}" != " first=1"
+.  error
+.endif
+
+# The modifier '::=' applies the assignment operator '=' 3 times. The
+# operator '=' overwrites the previous value, therefore the variable LAST ends
+# up with the value 3.
+.if "${1 2 3:L:@i@${LAST::=$i}@} last=${LAST}" != " last=3"
+.  error
+.endif
+
+# The modifier '::+=' applies the assignment operator '+=' 3 times. The
+# operator '+=' appends 3 times to the variable, therefore the variable
+# APPENDED ends up with the value "1 2 3".
+.if "${1 2 3:L:@i@${APPENDED::+=$i}@} appended=${APPENDED}" != " appended=1 2 3"
+.  error
+.endif
+
+# The modifier '::!=' applies the assignment operator '!=' 3 times. Just as
+# with the modifier '::=', the last value is stored in the RAN variable.
+.if "${1 2 3:L:@i@${RAN::!=${i:%=echo '<%>';}}@} ran=${RAN}" != " ran=<3>"
+.  error
+.endif
+
+# The assignments happen in the global scope and thus are preserved even after
+# the shell command has been run and the condition has been evaluated.
+.if "${FIRST}, ${LAST}, ${APPENDED}, ${RAN}" != "1, 3, 1 2 3, <3>"
+.  error
+.endif
+
+# Tests for nested assignments, which are hard to read and therefore seldom
+# used in practice.
+
+# The condition "1" is true, therefore THEN1 gets assigned a value,
+# and IT1 as well.  Nothing surprising here.
+.if "${1:?${THEN1::=then1${IT1::=t1}}:${ELSE1::=else1${IE1::=e1}}}${THEN1}${ELSE1}${IT1}${IE1}" != "then1t1"
+.  error
+.endif
+
+# The condition "0" is false, therefore ELSE1 gets assigned a value,
+# and IE1 as well.  Nothing surprising here as well.
+.if "${0:?${THEN2::=then2${IT2::=t2}}:${ELSE2::=else2${IE2::=e2}}}${THEN2}${ELSE2}${IT2}${IE2}" != "else2e2"
+.  error
+.endif
+
+# The same effects happen when the variables are defined elsewhere.
 SINK3:=	${1:?${THEN3::=then3${IT3::=t3}}:${ELSE3::=else3${IE3::=e3}}}${THEN3}${ELSE3}${IT3}${IE3}
 SINK4:=	${0:?${THEN4::=then4${IT4::=t4}}:${ELSE4::=else4${IE4::=e4}}}${THEN4}${ELSE4}${IT4}${IE4}
+.if ${SINK3} != "then3t3"
+.  error
+.endif
+.if ${SINK4} != "else4e4"
+.  error
+.endif
 
 mod-assign-empty:
 	# Assigning to the empty variable would obviously not work since that
 	# variable is write-protected.  Therefore it is rejected early with a
 	# "Bad modifier" message.
-	#
-	# XXX: The error message is hard to read since the variable name is
-	# empty.  This leads to a trailing space in the error message.
 	@echo $@: ${::=value}
 
 	# In this variant, it is not as obvious that the name of the
 	# expression is empty.  Assigning to it is rejected as well, with the
 	# same "Bad modifier" message.
-	#
-	# XXX: The error message is hard to read since the variable name is
-	# empty.  This leads to a trailing space in the error message.
 	@echo $@: ${:Uvalue::=overwritten}
 
 	# The :L modifier sets the value of the expression to its variable

Reply via email to