]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/varmod-localtime.mk
zfs: merge openzfs/zfs@afa7b3484 (master) into main
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / varmod-localtime.mk
1 # $NetBSD: varmod-localtime.mk,v 1.8 2021/01/19 05:26:34 rillig Exp $
2 #
3 # Tests for the :localtime variable modifier, which formats a timestamp
4 # using strftime(3) in local time.
5
6 .if ${TZ} != "Europe/Berlin"    # see unit-tests/Makefile
7 .  error
8 .endif
9
10 # Test for the default time format, %c.  Since the time always varies, it's
11 # only possible to check for the general format here.  The names of the
12 # month and weekday are always in English, independent from the locale.
13 # Example: Thu Oct 29 18:56:41 2020
14 .if ${:U:localtime:tW:M??? ??? ?? ??\:??\:?? ????} == ""
15 .  error
16 .endif
17
18
19 # modifier name too short, falling back to the SysV modifier.
20 .if ${%Y:L:localtim=1593536400} != "%Y"
21 .  error
22 .endif
23
24
25 # 2020-07-01T00:00:00Z
26 .if ${%Y:L:localtime=1593536400} != "2020"
27 .  error
28 .endif
29
30
31 # modifier name too long, falling back to the SysV modifier.
32 .if ${%Y:L:localtimer=1593536400} != "%Y"
33 .  error
34 .endif
35
36
37 # If the modifier name is not matched exactly, fall back to the
38 # :from=to modifier.
39 .if ${localtime:L:local%=gm%} != "gmtime"
40 .  error
41 .endif
42
43
44 # As of 2020-08-16, it is not possible to pass the seconds via a
45 # variable expression.  This is because parsing of the :localtime
46 # modifier stops at the '$' and returns to ApplyModifiers.
47 #
48 # There, a colon would be skipped but not a dollar.
49 # Parsing therefore continues at the '$' of the ${:U159...}, looking
50 # for an ordinary variable modifier.
51 #
52 # At this point, the ${:U} is expanded and interpreted as a variable
53 # modifier, which results in the error message "Unknown modifier '1'".
54 #
55 # If ApplyModifier_Localtime were to pass its argument through
56 # ParseModifierPart, this would work.
57 .if ${%Y:L:localtime=${: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 :localtime 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:localtime=-1} != ""
68 .  error
69 .else
70 .  error
71 .endif
72
73
74 # Spaces were allowed before var.c 1.631 from 2020-10-31 21:40:20, not
75 # because it would make sense but just as a side-effect from using strtoul.
76 .if ${:L:localtime= 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:localtime=0:tW:M??? ??? ?? ??\:??\:?? 20??}
85 .  error
86 .endif
87
88
89 .if ${:L:localtime=1} != "Thu Jan  1 01:00:01 1970"
90 .  error
91 .endif
92
93
94 # INT32_MAX
95 .if ${:L:localtime=2147483647} != "Tue Jan 19 04:14:07 2038"
96 .  error
97 .endif
98
99
100 .if ${:L:localtime=2147483648} == "Tue Jan 19 04:14:08 2038"
101 # All systems that have unsigned time_t or 64-bit time_t.
102 .elif ${:L:localtime=2147483648} == "Fri Dec 13 21:45:52 1901"
103 # FreeBSD-12.0-i386 still has 32-bit signed time_t, see
104 # sys/x86/include/_types.h, __LP64__.
105 #
106 # Linux on 32-bit systems may still have 32-bit signed time_t, see
107 # sysdeps/unix/sysv/linux/generic/bits/typesizes.h, __TIMESIZE.
108 .else
109 .  error
110 .endif
111
112
113 # Integer overflow, at least before var.c 1.631 from 2020-10-31.
114 # Because this modifier is implemented using strtoul, the parsed time was
115 # ULONG_MAX, which got converted to -1.  This resulted in a time stamp of
116 # the second before 1970.
117 #
118 # Since var.c 1.631, the overflow is detected and produces a parse error.
119 .if ${:L:localtime=10000000000000000000000000000000} != ""
120 .  error
121 .else
122 .  error
123 .endif
124
125 # Before var.c 1.631 from 2020-10-31, there was no error handling while
126 # parsing the :localtime modifier, thus no error message was printed.  Parsing
127 # stopped after the '=', and the remaining string was parsed for more variable
128 # modifiers.  Because of the unknown modifier 'e' from the 'error', the whole
129 # variable value was discarded and thus not printed.
130 .if ${:L:localtime=error} != ""
131 .  error
132 .else
133 .  error
134 .endif
135
136
137 all: