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