aboutsummaryrefslogtreecommitdiff
path: root/unit-tests/varmod-gmtime.mk
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2020-11-07 19:39:21 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2020-11-07 19:39:21 +0000
commit302da1a3d35c15cb29d76e0a939f8bcb13f7ad80 (patch)
treec2146dca82d530521c4d2cc46a95c26964311a2c /unit-tests/varmod-gmtime.mk
parent6bbc783f48498b808e19db4441299dc7d85a278b (diff)
downloadsrc-302da1a3d35c15cb29d76e0a939f8bcb13f7ad80.tar.gz
src-302da1a3d35c15cb29d76e0a939f8bcb13f7ad80.zip
Notes
Diffstat (limited to 'unit-tests/varmod-gmtime.mk')
-rw-r--r--unit-tests/varmod-gmtime.mk68
1 files changed, 60 insertions, 8 deletions
diff --git a/unit-tests/varmod-gmtime.mk b/unit-tests/varmod-gmtime.mk
index 0a05ad58d982..b404d1c2768e 100644
--- a/unit-tests/varmod-gmtime.mk
+++ b/unit-tests/varmod-gmtime.mk
@@ -1,17 +1,35 @@
-# $NetBSD: varmod-gmtime.mk,v 1.2 2020/08/16 12:48:55 rillig Exp $
+# $NetBSD: varmod-gmtime.mk,v 1.6 2020/10/31 20:30:06 rillig Exp $
#
# Tests for the :gmtime variable modifier, which formats a timestamp
-# using strftime(3).
+# using strftime(3) in UTC.
all: mod-gmtime
all: mod-gmtime-indirect
+all: parse-errors
+
+# Test for the default time format, %c. Since the time always varies, it's
+# only possible to check for the general format here. The names of the
+# month and weekday are always in English, independent from the locale.
+# Example: Thu Oct 29 18:56:41 2020
+.if ${:U:gmtime:tW:M??? ??? ?? ??\:??\:?? ????} == ""
+. error
+.endif
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*}
+
+ # modifier name too short
+ @echo ${%Y:L:gmtim=1593536400}
+
+ # 2020-07-01T00:00:00Z
+ @echo ${%Y:L:gmtime=1593536400}
+
+ # modifier name too long
+ @echo ${%Y:L:gmtimer=1593536400}
+
+ # If the modifier name is not matched exactly, fall back to the
+ # :from=to modifier.
+ @echo ${gmtime:L:gm%=local%} == localtime
mod-gmtime-indirect:
@echo $@:
@@ -31,5 +49,39 @@ mod-gmtime-indirect:
# ParseModifierPart, this would work.
@echo ${%Y:L:gmtime=${:U1593536400}}
-all:
- @:;
+parse-errors:
+ @echo $@:
+
+ # As of 2020-10-31, it is possible to pass negative time stamps
+ # to the :gmtime modifier, resulting in dates before 1970.
+ # Going back 50 years in the past is not a practical use case for
+ # make.
+ : -1 becomes ${:L:gmtime=-1}.
+
+ # Spaces are allowed, not because it would make sense but just as
+ # a side-effect from using strtoul.
+ : space 1 becomes ${:L:gmtime= 1}.
+
+ # 0 means now; to get consistent test results, the actual value has
+ # to be normalized.
+ : 0 becomes ${:L:gmtime=0:C,^... ... .. ..:..:.. 20..$,ok,W}.
+
+ : 1 becomes ${:L:gmtime=1}.
+
+ : INT32_MAX becomes ${:L:gmtime=2147483647}.
+
+ # This may be different if time_t is still a 32-bit signed integer.
+ : INT32_MAX + 1 becomes ${:L:gmtime=2147483648}.
+
+ # Integer overflow.
+ # Because this modifier is implemented using strtoul, the parsed
+ # time is ULONG_MAX, which gets converted to -1. This results
+ # in a time stamp of the second before 1970.
+ : overflow becomes ${:L:gmtime=10000000000000000000000000000000}.
+
+ # As of 2020-10-31, there is no error handling while parsing the
+ # :gmtime modifier, thus no error message is printed. Parsing
+ # stops after the '=', and the remaining string is parsed for
+ # more variable modifiers. Because of the unknown modifier 'e',
+ # the whole variable value is discarded and thus not printed.
+ : letter becomes ${:L:gmtime=error}.