aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/unit-tests/varmod-gmtime.mk
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bmake/unit-tests/varmod-gmtime.mk')
-rw-r--r--contrib/bmake/unit-tests/varmod-gmtime.mk83
1 files changed, 67 insertions, 16 deletions
diff --git a/contrib/bmake/unit-tests/varmod-gmtime.mk b/contrib/bmake/unit-tests/varmod-gmtime.mk
index cb3d4e7eb241..db24b1680c46 100644
--- a/contrib/bmake/unit-tests/varmod-gmtime.mk
+++ b/contrib/bmake/unit-tests/varmod-gmtime.mk
@@ -1,7 +1,10 @@
-# $NetBSD: varmod-gmtime.mk,v 1.10 2021/01/19 05:26:34 rillig Exp $
+# $NetBSD: varmod-gmtime.mk,v 1.22 2024/04/20 10:18:55 rillig Exp $
#
# Tests for the :gmtime variable modifier, which formats a timestamp
# using strftime(3) in UTC.
+#
+# See also:
+# varmod-localtime.mk
.if ${TZ:Uundefined} != "undefined" # see unit-tests/Makefile
. error
@@ -41,20 +44,9 @@
.endif
-# 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.
-.if ${%Y:L:gmtime=${:U1593536400}} != "mtime=11593536400}"
+# Before var.c 1.1050 from 2023-05-09, it was not possible to pass the
+# seconds via an expression.
+.if ${%Y:L:gmtime=${:U1593536400}} != "2020"
. error
.endif
@@ -64,6 +56,8 @@
# 1970. Going back 50 years in the past is not a practical use case for
# make. Therefore, since var.c 1.631, negative time stamps produce a
# parse error.
+# expect+2: while evaluating "${:L:gmtime=-1} != """: Invalid time value "-1"
+# expect+1: Malformed conditional (${:L:gmtime=-1} != "")
.if ${:L:gmtime=-1} != ""
. error
.else
@@ -73,8 +67,12 @@
# Spaces were allowed before var.c 1.631 from 2020-10-31 21:40:20, not
# because it would make sense but just as a side-effect from using strtoul.
+# expect+2: while evaluating "${:L:gmtime= 1} != """: Invalid time value " 1"
+# expect+1: Malformed conditional (${:L:gmtime= 1} != "")
.if ${:L:gmtime= 1} != ""
. error
+.else
+. error
.endif
@@ -115,7 +113,10 @@
# ULONG_MAX, which got converted to -1. This resulted in a time stamp of
# the second before 1970.
#
-# Since var.c 1.631, the overflow is detected and produces a parse error.
+# Since var.c 1.631 from 2020-10-31, the overflow is detected and produces a
+# parse error.
+# expect+2: while evaluating "${:L:gmtime=10000000000000000000000000000000} != """: Invalid time value "10000000000000000000000000000000"
+# expect+1: Malformed conditional (${:L:gmtime=10000000000000000000000000000000} != "")
.if ${:L:gmtime=10000000000000000000000000000000} != ""
. error
.else
@@ -127,11 +128,61 @@
# stopped after the '=', and the remaining string was parsed for more variable
# modifiers. Because of the unknown modifier 'e' from the 'error', the whole
# variable value was discarded and thus not printed.
+# expect+2: while evaluating "${:L:gmtime=error} != """: Invalid time value "error"
+# expect+1: Malformed conditional (${:L:gmtime=error} != "")
.if ${:L:gmtime=error} != ""
. error
.else
. error
.endif
+# Before var.c 1.1050 from 2023-05-09, the timestamp could be directly
+# followed by the next modifier, without a ':' separator. This was the same
+# bug as for the ':L' and ':P' modifiers.
+# expect+2: while evaluating variable "%Y": Invalid time value "100000S,1970,bad,"
+# expect+1: Malformed conditional (${%Y:L:gmtime=100000S,1970,bad,} != "bad")
+.if ${%Y:L:gmtime=100000S,1970,bad,} != "bad"
+. error
+.endif
+
+
+# Before var.c 1.1062 from 2023-08-19, ':gmtime' but not ':localtime' reported
+# wrong values for '%s', depending on the operating system and the timezone.
+export TZ=UTC
+.for t in ${%s:L:gmtime} ${%s:L:localtime}
+TIMESTAMPS+= $t
+.endfor
+export TZ=Europe/Berlin
+.for t in ${%s:L:gmtime} ${%s:L:localtime}
+TIMESTAMPS+= $t
+.endfor
+export TZ=UTC
+.for t in ${%s:L:gmtime} ${%s:L:localtime}
+TIMESTAMPS+= $t
+.endfor
+export TZ=America/Los_Angeles
+.for t in ${%s:L:gmtime} ${%s:L:localtime}
+TIMESTAMPS+= $t
+.endfor
+export TZ=UTC
+.for t in ${%s:L:gmtime} ${%s:L:localtime}
+TIMESTAMPS+= $t
+.endfor
+.for a b in ${TIMESTAMPS:[1]} ${TIMESTAMPS:@t@$t $t@} ${TIMESTAMPS:[-1]}
+. if $a > $b
+. warning timestamp $a > $b
+. endif
+.endfor
+
+
+.if ${year=%Y month=%m day=%d:L:gmtime=1459494000} != "year=2016 month=04 day=01"
+. error
+.endif
+# Slightly contorted syntax to convert a UTC timestamp from an expression to a
+# formatted timestamp.
+.if ${%Y%m%d:L:${gmtime=${:U1459494000}:L}} != "20160401"
+. error
+.endif
+
all: