Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests make(1): move tests for the :gmtime ...



details:   https://anonhg.NetBSD.org/src/rev/521f5c200479
branches:  trunk
changeset: 1012943:521f5c200479
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 16 12:48:55 2020 +0000

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

diffstat:

 usr.bin/make/unit-tests/modmisc.exp            |  20 -------
 usr.bin/make/unit-tests/modmisc.mk             |  66 +-------------------------
 usr.bin/make/unit-tests/varmod-assign.exp      |  12 ++++
 usr.bin/make/unit-tests/varmod-assign.mk       |  26 ++++++++-
 usr.bin/make/unit-tests/varmod-exclam-shell.mk |  26 +++++++++-
 usr.bin/make/unit-tests/varmod-gmtime.exp      |   8 +++
 usr.bin/make/unit-tests/varmod-gmtime.mk       |  33 +++++++++++-
 7 files changed, 95 insertions(+), 96 deletions(-)

diffs (279 lines):

diff -r 7c0b4be109e2 -r 521f5c200479 usr.bin/make/unit-tests/modmisc.exp
--- a/usr.bin/make/unit-tests/modmisc.exp       Sun Aug 16 12:30:45 2020 +0000
+++ b/usr.bin/make/unit-tests/modmisc.exp       Sun Aug 16 12:48:55 2020 +0000
@@ -18,18 +18,6 @@
 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 @@
 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
diff -r 7c0b4be109e2 -r 521f5c200479 usr.bin/make/unit-tests/modmisc.mk
--- a/usr.bin/make/unit-tests/modmisc.mk        Sun Aug 16 12:30:45 2020 +0000
+++ b/usr.bin/make/unit-tests/modmisc.mk        Sun Aug 16 12:48:55 2020 +0000
@@ -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_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 @@
        @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 @@
        @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 @@
 .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
diff -r 7c0b4be109e2 -r 521f5c200479 usr.bin/make/unit-tests/varmod-assign.exp
--- a/usr.bin/make/unit-tests/varmod-assign.exp Sun Aug 16 12:30:45 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-assign.exp Sun Aug 16 12:48:55 2020 +0000
@@ -1,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
diff -r 7c0b4be109e2 -r 521f5c200479 usr.bin/make/unit-tests/varmod-assign.mk
--- a/usr.bin/make/unit-tests/varmod-assign.mk  Sun Aug 16 12:30:45 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-assign.mk  Sun Aug 16 12:48:55 2020 +0000
@@ -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.
+
+all:   mod-assign
+all:   mod-assign-nested
 
-# TODO: Implementation
+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}.
 
-all:
-       @:;
+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}
diff -r 7c0b4be109e2 -r 521f5c200479 usr.bin/make/unit-tests/varmod-exclam-shell.mk
--- a/usr.bin/make/unit-tests/varmod-exclam-shell.mk    Sun Aug 16 12:30:45 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-exclam-shell.mk    Sun Aug 16 12:48:55 2020 +0000
@@ -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.
+
+.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
 
-# TODO: Implementation
+.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:
        @:;
diff -r 7c0b4be109e2 -r 521f5c200479 usr.bin/make/unit-tests/varmod-gmtime.exp
--- a/usr.bin/make/unit-tests/varmod-gmtime.exp Sun Aug 16 12:30:45 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-gmtime.exp Sun Aug 16 12:48:55 2020 +0000
@@ -1,1 +1,9 @@
+mod-gmtime:
+%Y
+2020
+%Y
+%Y
+mod-gmtime-indirect:
+make: Unknown modifier '1'
+
 exit status 0
diff -r 7c0b4be109e2 -r 521f5c200479 usr.bin/make/unit-tests/varmod-gmtime.mk
--- a/usr.bin/make/unit-tests/varmod-gmtime.mk  Sun Aug 16 12:30:45 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-gmtime.mk  Sun Aug 16 12:48:55 2020 +0000
@@ -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).
+
+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*}
 
-# TODO: Implementation
+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:
        @:;



Home | Main Index | Thread Index | Old Index