Module Name:    src
Committed By:   rillig
Date:           Sun Aug 16 12:48:55 UTC 2020

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

Log Message:
make(1): move tests for the :gmtime and ::= modifiers to separate files


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/make/unit-tests/modmisc.exp \
    src/usr.bin/make/unit-tests/modmisc.mk
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/varmod-assign.exp \
    src/usr.bin/make/unit-tests/varmod-assign.mk \
    src/usr.bin/make/unit-tests/varmod-exclam-shell.mk \
    src/usr.bin/make/unit-tests/varmod-gmtime.exp \
    src/usr.bin/make/unit-tests/varmod-gmtime.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/modmisc.exp
diff -u src/usr.bin/make/unit-tests/modmisc.exp:1.42 src/usr.bin/make/unit-tests/modmisc.exp:1.43
--- src/usr.bin/make/unit-tests/modmisc.exp:1.42	Sun Aug 16 12:30:45 2020
+++ src/usr.bin/make/unit-tests/modmisc.exp	Sun Aug 16 12:48:55 2020
@@ -18,18 +18,6 @@ C:
 S:empty
 C:empty
 @:
-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
 mod-tu-space: A   B
 mod-quote: new
 
@@ -37,14 +25,6 @@ line
 mod-break-many-words: 500
 mod-remember: 1 2 3 1 2 3 1 2 3
 mod-remember: 1 2 3, SAVED=3
-mod-gmtime:
-%Y
-2020
-%Y
-%Y
-mod-gmtime-indirect:
-make: Unknown modifier '1'
-
 mod-localtime:
 %Y
 2020
Index: src/usr.bin/make/unit-tests/modmisc.mk
diff -u src/usr.bin/make/unit-tests/modmisc.mk:1.42 src/usr.bin/make/unit-tests/modmisc.mk:1.43
--- src/usr.bin/make/unit-tests/modmisc.mk:1.42	Sun Aug 16 12:30:45 2020
+++ src/usr.bin/make/unit-tests/modmisc.mk	Sun Aug 16 12:48:55 2020
@@ -1,4 +1,4 @@
-# $Id: modmisc.mk,v 1.42 2020/08/16 12:30:45 rillig Exp $
+# $Id: modmisc.mk,v 1.43 2020/08/16 12:48:55 rillig Exp $
 #
 # miscellaneous modifier tests
 
@@ -16,14 +16,10 @@ MOD_OPT=@d@$${exists($$d):?$$d:$${d:S,/u
 MOD_SEP=S,:, ,g
 
 all:	modvar modvarloop modsysv mod-HTE emptyvar undefvar
-all:	mod-assign
-all:	mod-assign-nested
 all:	mod-tu-space
 all:	mod-quote
 all:	mod-break-many-words
 all:	mod-remember
-all:	mod-gmtime
-all:	mod-gmtime-indirect
 all:	mod-localtime
 all:	mod-hash
 all:	mod-range
@@ -72,24 +68,6 @@ undefvar:
 	@echo C:${:U:C,^$,empty,}
 	@echo @:${:U:@var@empty@}
 
-# Just a bit of basic code coverage for the obscure ::= assignment modifiers.
-mod-assign:
-	@echo $@: ${1 2 3:L:@i@${FIRST::?=$i}@} first=${FIRST}.
-	@echo $@: ${1 2 3:L:@i@${LAST::=$i}@} last=${LAST}.
-	@echo $@: ${1 2 3:L:@i@${APPENDED::+=$i}@} appended=${APPENDED}.
-	@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:
-	@echo $@: ${1:?${THEN1::=then1${IT1::=t1}}:${ELSE1::=else1${IE1::=e1}}}${THEN1}${ELSE1}${IT1}${IE1}
-	@echo $@: ${0:?${THEN2::=then2${IT2::=t2}}:${ELSE2::=else2${IE2::=e2}}}${THEN2}${ELSE2}${IT2}${IE2}
-	@echo $@: ${SINK3:Q}
-	@echo $@: ${SINK4:Q}
-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}
-
 mod-tu-space:
 	# The :tu and :tl modifiers operate on the variable value
 	# as a single string, not as a list of words. Therefore,
@@ -111,23 +89,6 @@ mod-remember:
 	@echo $@: ${1 2 3:L:_:@var@${_}@}
 	@echo $@: ${1 2 3:L:@var@${var:_=SAVED:}@}, SAVED=${SAVED}
 
-mod-gmtime:
-	@echo $@:
-	@echo ${%Y:L:gmtim=1593536400}		# modifier name too short
-	@echo ${%Y:L:gmtime=1593536400}		# 2020-07-01T00:00:00Z
-	@echo ${%Y:L:gmtimer=1593536400}	# modifier name too long
-	@echo ${%Y:L:gm=gm:M*}
-
-mod-gmtime-indirect:
-	@echo $@:
-	# It's not possible to pass the seconds via a variable expression.
-	# Parsing of the :gmtime modifier stops at the '$' and returns to
-	# ApplyModifiers.  There, a colon would be skipped but not a dollar.
-	# Parsing continues by looking at the next modifier.  Now the ${:U}
-	# is expanded and interpreted as a variable modifier, which results
-	# in the error message "Unknown modifier '1'".
-	@echo ${%Y:L:gmtime=${:U1593536400}}
-
 mod-localtime:
 	@echo $@:
 	@echo ${%Y:L:localtim=1593536400}	# modifier name too short
@@ -175,28 +136,3 @@ mod-range:
 .warning unexpected
 .endif
 
-# begin mod-shell
-
-.if ${:!echo hello | tr 'l' 'l'!} != "hello"
-.warning unexpected
-.endif
-
-# The output is truncated at the first null byte.
-# Cmd_Exec returns only a string pointer without length information.
-.if ${:!echo hello | tr 'l' '\0'!} != "he"
-.warning unexpected
-.endif
-
-.if ${:!echo!} != ""
-.warning A newline at the end of the output must be stripped.
-.endif
-
-.if ${:!echo;echo!} != " "
-.warning Only a single newline at the end of the output is stripped.
-.endif
-
-.if ${:!echo;echo;echo;echo!} != "   "
-.warning Other newlines in the output are converted to spaces.
-.endif
-
-# end mod-shell

Index: src/usr.bin/make/unit-tests/varmod-assign.exp
diff -u src/usr.bin/make/unit-tests/varmod-assign.exp:1.1 src/usr.bin/make/unit-tests/varmod-assign.exp:1.2
--- src/usr.bin/make/unit-tests/varmod-assign.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/varmod-assign.exp	Sun Aug 16 12:48:55 2020
@@ -1 +1,13 @@
+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
 exit status 0
Index: src/usr.bin/make/unit-tests/varmod-assign.mk
diff -u src/usr.bin/make/unit-tests/varmod-assign.mk:1.1 src/usr.bin/make/unit-tests/varmod-assign.mk:1.2
--- src/usr.bin/make/unit-tests/varmod-assign.mk:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/varmod-assign.mk	Sun Aug 16 12:48:55 2020
@@ -1,8 +1,24 @@
-# $NetBSD: varmod-assign.mk,v 1.1 2020/08/16 12:07:51 rillig Exp $
+# $NetBSD: varmod-assign.mk,v 1.2 2020/08/16 12:48:55 rillig Exp $
 #
-# TODO: Description
+# Tests for the obscure ::= variable modifiers, which perform variable
+# assignments during evaluation, just like the = operator in C.
 
-# TODO: Implementation
+all:	mod-assign
+all:	mod-assign-nested
 
-all:
-	@:;
+mod-assign:
+	@echo $@: ${1 2 3:L:@i@${FIRST::?=$i}@} first=${FIRST}.
+	@echo $@: ${1 2 3:L:@i@${LAST::=$i}@} last=${LAST}.
+	@echo $@: ${1 2 3:L:@i@${APPENDED::+=$i}@} appended=${APPENDED}.
+	@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:
+	@echo $@: ${1:?${THEN1::=then1${IT1::=t1}}:${ELSE1::=else1${IE1::=e1}}}${THEN1}${ELSE1}${IT1}${IE1}
+	@echo $@: ${0:?${THEN2::=then2${IT2::=t2}}:${ELSE2::=else2${IE2::=e2}}}${THEN2}${ELSE2}${IT2}${IE2}
+	@echo $@: ${SINK3:Q}
+	@echo $@: ${SINK4:Q}
+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}
Index: src/usr.bin/make/unit-tests/varmod-exclam-shell.mk
diff -u src/usr.bin/make/unit-tests/varmod-exclam-shell.mk:1.1 src/usr.bin/make/unit-tests/varmod-exclam-shell.mk:1.2
--- src/usr.bin/make/unit-tests/varmod-exclam-shell.mk:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/varmod-exclam-shell.mk	Sun Aug 16 12:48:55 2020
@@ -1,8 +1,28 @@
-# $NetBSD: varmod-exclam-shell.mk,v 1.1 2020/08/16 12:07:51 rillig Exp $
+# $NetBSD: varmod-exclam-shell.mk,v 1.2 2020/08/16 12:48:55 rillig Exp $
 #
-# TODO: Description
+# Tests for the :!cmd! variable modifier.
 
-# TODO: Implementation
+.if ${:!echo hello | tr 'l' 'l'!} != "hello"
+.warning unexpected
+.endif
+
+# The output is truncated at the first null byte.
+# Cmd_Exec returns only a string pointer without length information.
+.if ${:!echo hello | tr 'l' '\0'!} != "he"
+.warning unexpected
+.endif
+
+.if ${:!echo!} != ""
+.warning A newline at the end of the output must be stripped.
+.endif
+
+.if ${:!echo;echo!} != " "
+.warning Only a single newline at the end of the output is stripped.
+.endif
+
+.if ${:!echo;echo;echo;echo!} != "   "
+.warning Other newlines in the output are converted to spaces.
+.endif
 
 all:
 	@:;
Index: src/usr.bin/make/unit-tests/varmod-gmtime.exp
diff -u src/usr.bin/make/unit-tests/varmod-gmtime.exp:1.1 src/usr.bin/make/unit-tests/varmod-gmtime.exp:1.2
--- src/usr.bin/make/unit-tests/varmod-gmtime.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/varmod-gmtime.exp	Sun Aug 16 12:48:55 2020
@@ -1 +1,9 @@
+mod-gmtime:
+%Y
+2020
+%Y
+%Y
+mod-gmtime-indirect:
+make: Unknown modifier '1'
+
 exit status 0
Index: src/usr.bin/make/unit-tests/varmod-gmtime.mk
diff -u src/usr.bin/make/unit-tests/varmod-gmtime.mk:1.1 src/usr.bin/make/unit-tests/varmod-gmtime.mk:1.2
--- src/usr.bin/make/unit-tests/varmod-gmtime.mk:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/varmod-gmtime.mk	Sun Aug 16 12:48:55 2020
@@ -1,8 +1,35 @@
-# $NetBSD: varmod-gmtime.mk,v 1.1 2020/08/16 12:07:51 rillig Exp $
+# $NetBSD: varmod-gmtime.mk,v 1.2 2020/08/16 12:48:55 rillig Exp $
 #
-# TODO: Description
+# Tests for the :gmtime variable modifier, which formats a timestamp
+# using strftime(3).
 
-# TODO: Implementation
+all:	mod-gmtime
+all:	mod-gmtime-indirect
+
+mod-gmtime:
+	@echo $@:
+	@echo ${%Y:L:gmtim=1593536400}		# modifier name too short
+	@echo ${%Y:L:gmtime=1593536400}		# 2020-07-01T00:00:00Z
+	@echo ${%Y:L:gmtimer=1593536400}	# modifier name too long
+	@echo ${%Y:L:gm=gm:M*}
+
+mod-gmtime-indirect:
+	@echo $@:
+
+	# As of 2020-08-16, it is not possible to pass the seconds via a
+	# variable expression.  This is because parsing of the :gmtime
+	# modifier stops at the '$' and returns to ApplyModifiers.
+	#
+	# There, a colon would be skipped but not a dollar.
+	# Parsing therefore continues at the '$' of the ${:U159...}, looking
+	# for an ordinary variable modifier.
+	#
+	# At this point, the ${:U} is expanded and interpreted as a variable
+	# modifier, which results in the error message "Unknown modifier '1'".
+	#
+	# If ApplyModifier_Gmtime were to pass its argument through
+	# ParseModifierPart, this would work.
+	@echo ${%Y:L:gmtime=${:U1593536400}}
 
 all:
 	@:;

Reply via email to