varmod-gmtime.mk revision 1.7 1 1.7 rillig # $NetBSD: varmod-gmtime.mk,v 1.7 2020/12/21 20:35:17 rillig Exp $
2 1.1 rillig #
3 1.2 rillig # Tests for the :gmtime variable modifier, which formats a timestamp
4 1.6 rillig # using strftime(3) in UTC.
5 1.1 rillig
6 1.2 rillig
7 1.3 rillig # Test for the default time format, %c. Since the time always varies, it's
8 1.3 rillig # only possible to check for the general format here. The names of the
9 1.3 rillig # month and weekday are always in English, independent from the locale.
10 1.3 rillig # Example: Thu Oct 29 18:56:41 2020
11 1.3 rillig .if ${:U:gmtime:tW:M??? ??? ?? ??\:??\:?? ????} == ""
12 1.3 rillig . error
13 1.3 rillig .endif
14 1.3 rillig
15 1.6 rillig
16 1.7 rillig # modifier name too short, falling back to the SysV modifier.
17 1.7 rillig .if ${%Y:L:gmtim=1593536400} != "%Y"
18 1.7 rillig . error
19 1.7 rillig .endif
20 1.7 rillig
21 1.7 rillig
22 1.7 rillig # 2020-07-01T00:00:00Z
23 1.7 rillig .if ${%Y:L:gmtime=1593536400} != "2020"
24 1.7 rillig . error
25 1.7 rillig .endif
26 1.7 rillig
27 1.7 rillig
28 1.7 rillig # modifier name too long, falling back to the SysV modifier.
29 1.7 rillig .if ${%Y:L:gmtimer=1593536400} != "%Y"
30 1.7 rillig . error
31 1.7 rillig .endif
32 1.7 rillig
33 1.7 rillig
34 1.7 rillig # If the modifier name is not matched exactly, fall back to the
35 1.7 rillig # :from=to modifier.
36 1.7 rillig .if ${gmtime:L:gm%=local%} != "localtime"
37 1.7 rillig . error
38 1.7 rillig .endif
39 1.7 rillig
40 1.7 rillig
41 1.7 rillig # As of 2020-08-16, it is not possible to pass the seconds via a
42 1.7 rillig # variable expression. This is because parsing of the :gmtime
43 1.7 rillig # modifier stops at the '$' and returns to ApplyModifiers.
44 1.7 rillig #
45 1.7 rillig # There, a colon would be skipped but not a dollar.
46 1.7 rillig # Parsing therefore continues at the '$' of the ${:U159...}, looking
47 1.7 rillig # for an ordinary variable modifier.
48 1.7 rillig #
49 1.7 rillig # At this point, the ${:U} is expanded and interpreted as a variable
50 1.7 rillig # modifier, which results in the error message "Unknown modifier '1'".
51 1.7 rillig #
52 1.7 rillig # If ApplyModifier_Gmtime were to pass its argument through
53 1.7 rillig # ParseModifierPart, this would work.
54 1.7 rillig #
55 1.7 rillig # XXX: Where does the empty line 4 in varmod-gmtime.exp come from?
56 1.7 rillig # TODO: Remove the \n from "Invalid time value: %s\n" in var.c.
57 1.7 rillig .if ${%Y:L:gmtime=${:U1593536400}} != "mtime=11593536400}"
58 1.7 rillig . error
59 1.7 rillig .endif
60 1.7 rillig
61 1.7 rillig
62 1.7 rillig # Before var.c 1.631 from 2020-10-31 21:40:20, it was possible to pass
63 1.7 rillig # negative time stamps to the :gmtime modifier, resulting in dates before
64 1.7 rillig # 1970. Going back 50 years in the past is not a practical use case for
65 1.7 rillig # make. Therefore, since var.c 1.631, negative time stamps produce a
66 1.7 rillig # parse error.
67 1.7 rillig .if ${:L:gmtime=-1} != ""
68 1.7 rillig . error
69 1.7 rillig .else
70 1.7 rillig . error
71 1.7 rillig .endif
72 1.7 rillig
73 1.7 rillig
74 1.7 rillig # Spaces were allowed before var.c 1.631, not because it would make sense
75 1.7 rillig # but just as a side-effect from using strtoul.
76 1.7 rillig .if ${:L:gmtime= 1} != ""
77 1.7 rillig . error
78 1.7 rillig .endif
79 1.7 rillig
80 1.7 rillig
81 1.7 rillig # 0 means now; this differs from GNode.mtime, where a 0 means nonexistent.
82 1.7 rillig # Since "now" constantly changes, the strongest possible test is to match the
83 1.7 rillig # resulting pattern.
84 1.7 rillig .if !${:L:gmtime=0:tW:M??? ??? ?? ??\:??\:?? 20??}
85 1.7 rillig . error
86 1.7 rillig .endif
87 1.7 rillig
88 1.7 rillig
89 1.7 rillig .if ${:L:gmtime=1} != "Thu Jan 1 00:00:01 1970"
90 1.7 rillig . error
91 1.7 rillig .endif
92 1.7 rillig
93 1.7 rillig
94 1.7 rillig # INT32_MAX
95 1.7 rillig .if ${:L:gmtime=2147483647} != "Tue Jan 19 03:14:07 2038"
96 1.7 rillig . error
97 1.7 rillig .endif
98 1.7 rillig
99 1.7 rillig
100 1.7 rillig .if ${:L:gmtime=2147483648} == "Tue Jan 19 03:14:08 2038"
101 1.7 rillig # All systems that have unsigned time_t or 64-bit time_t.
102 1.7 rillig .elif ${:L:gmtime=2147483648} != "Fri Dec 13 20:45:52 1901"
103 1.7 rillig # FreeBSD-12.0-i386 still has 32-bit signed time_t.
104 1.7 rillig .else
105 1.7 rillig . error
106 1.7 rillig .endif
107 1.7 rillig
108 1.7 rillig
109 1.7 rillig # Integer overflow, at least before var.c 1.631 from 2020-10-31.
110 1.7 rillig # Because this modifier is implemented using strtoul, the parsed time was
111 1.7 rillig # ULONG_MAX, which got converted to -1. This resulted in a time stamp of
112 1.7 rillig # the second before 1970.
113 1.7 rillig #
114 1.7 rillig # Since var.c 1.613, the overflow is detected and produces a parse error.
115 1.7 rillig .if ${:L:gmtime=10000000000000000000000000000000} != ""
116 1.7 rillig . error
117 1.7 rillig .else
118 1.7 rillig . error
119 1.7 rillig .endif
120 1.7 rillig
121 1.7 rillig # Before var.c 1.613 from 2020-10-31, there was no error handling while
122 1.7 rillig # parsing the :gmtime modifier, thus no error message is printed. Parsing
123 1.7 rillig # stopped after the '=', and the remaining string was parsed for more variable
124 1.7 rillig # modifiers. Because of the unknown modifier 'e' from the 'error', the whole
125 1.7 rillig # variable value was discarded and thus not printed.
126 1.7 rillig .if ${:L:gmtime=error} != ""
127 1.7 rillig . error
128 1.7 rillig .else
129 1.7 rillig . error
130 1.7 rillig .endif
131 1.6 rillig
132 1.6 rillig
133 1.7 rillig all:
134