| @@ -1,77 +1,81 @@ | | | @@ -1,77 +1,81 @@ |
1 | # $NetBSD: varmod-gmtime.mk,v 1.4 2020/10/31 19:48:23 rillig Exp $ | | 1 | # $NetBSD: varmod-gmtime.mk,v 1.5 2020/10/31 19:55:26 rillig Exp $ |
2 | # | | 2 | # |
3 | # Tests for the :gmtime variable modifier, which formats a timestamp | | 3 | # Tests for the :gmtime variable modifier, which formats a timestamp |
4 | # using strftime(3). | | 4 | # using strftime(3). |
5 | | | 5 | |
6 | all: mod-gmtime | | 6 | all: mod-gmtime |
7 | all: mod-gmtime-indirect | | 7 | all: mod-gmtime-indirect |
8 | all: parse-errors | | 8 | all: parse-errors |
9 | | | 9 | |
10 | # Test for the default time format, %c. Since the time always varies, it's | | 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 | | 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. | | 12 | # month and weekday are always in English, independent from the locale. |
13 | # Example: Thu Oct 29 18:56:41 2020 | | 13 | # Example: Thu Oct 29 18:56:41 2020 |
14 | .if ${:U:gmtime:tW:M??? ??? ?? ??\:??\:?? ????} == "" | | 14 | .if ${:U:gmtime:tW:M??? ??? ?? ??\:??\:?? ????} == "" |
15 | . error | | 15 | . error |
16 | .endif | | 16 | .endif |
17 | | | 17 | |
18 | mod-gmtime: | | 18 | mod-gmtime: |
19 | @echo $@: | | 19 | @echo $@: |
20 | @echo ${%Y:L:gmtim=1593536400} # modifier name too short | | 20 | @echo ${%Y:L:gmtim=1593536400} # modifier name too short |
21 | @echo ${%Y:L:gmtime=1593536400} # 2020-07-01T00:00:00Z | | 21 | @echo ${%Y:L:gmtime=1593536400} # 2020-07-01T00:00:00Z |
22 | @echo ${%Y:L:gmtimer=1593536400} # modifier name too long | | 22 | @echo ${%Y:L:gmtimer=1593536400} # modifier name too long |
23 | @echo ${%Y:L:gm=gm:M*} | | 23 | @echo ${%Y:L:gm=gm:M*} |
24 | | | 24 | |
25 | mod-gmtime-indirect: | | 25 | mod-gmtime-indirect: |
26 | @echo $@: | | 26 | @echo $@: |
27 | | | 27 | |
28 | # As of 2020-08-16, it is not possible to pass the seconds via a | | 28 | # As of 2020-08-16, it is not possible to pass the seconds via a |
29 | # variable expression. This is because parsing of the :gmtime | | 29 | # variable expression. This is because parsing of the :gmtime |
30 | # modifier stops at the '$' and returns to ApplyModifiers. | | 30 | # modifier stops at the '$' and returns to ApplyModifiers. |
31 | # | | 31 | # |
32 | # There, a colon would be skipped but not a dollar. | | 32 | # There, a colon would be skipped but not a dollar. |
33 | # Parsing therefore continues at the '$' of the ${:U159...}, looking | | 33 | # Parsing therefore continues at the '$' of the ${:U159...}, looking |
34 | # for an ordinary variable modifier. | | 34 | # for an ordinary variable modifier. |
35 | # | | 35 | # |
36 | # At this point, the ${:U} is expanded and interpreted as a variable | | 36 | # At this point, the ${:U} is expanded and interpreted as a variable |
37 | # modifier, which results in the error message "Unknown modifier '1'". | | 37 | # modifier, which results in the error message "Unknown modifier '1'". |
38 | # | | 38 | # |
39 | # If ApplyModifier_Gmtime were to pass its argument through | | 39 | # If ApplyModifier_Gmtime were to pass its argument through |
40 | # ParseModifierPart, this would work. | | 40 | # ParseModifierPart, this would work. |
41 | @echo ${%Y:L:gmtime=${:U1593536400}} | | 41 | @echo ${%Y:L:gmtime=${:U1593536400}} |
42 | | | 42 | |
43 | parse-errors: | | 43 | parse-errors: |
44 | @echo $@: | | 44 | @echo $@: |
45 | | | 45 | |
46 | # As of 2020-10-31, it is possible to pass negative time stamps | | 46 | # As of 2020-10-31, it is possible to pass negative time stamps |
47 | # to the :gmtime modifier, resulting in dates before 1970. | | 47 | # to the :gmtime modifier, resulting in dates before 1970. |
48 | # Going back 50 years in the past is not a practical use case for | | 48 | # Going back 50 years in the past is not a practical use case for |
49 | # make. | | 49 | # make. |
50 | : -1 becomes ${:L:gmtime=-1}. | | 50 | : -1 becomes ${:L:gmtime=-1}. |
51 | | | 51 | |
| | | 52 | # Spaces are allowed, not because it would make sense but just as |
| | | 53 | # a side-effect from using strtoul. |
| | | 54 | : space 1 becomes ${:L:gmtime= 1}. |
| | | 55 | |
52 | # 0 means now; to get consistent test results, the actual value has | | 56 | # 0 means now; to get consistent test results, the actual value has |
53 | # to be normalized. | | 57 | # to be normalized. |
54 | : 0 becomes ${:L:gmtime=0:C,^... ... .. ..:..:.. 20..$,ok,W}. | | 58 | : 0 becomes ${:L:gmtime=0:C,^... ... .. ..:..:.. 20..$,ok,W}. |
55 | | | 59 | |
56 | : 1 becomes ${:L:gmtime=1}. | | 60 | : 1 becomes ${:L:gmtime=1}. |
57 | | | 61 | |
58 | : INT32_MAX becomes ${:L:gmtime=2147483647}. | | 62 | : INT32_MAX becomes ${:L:gmtime=2147483647}. |
59 | | | 63 | |
60 | # This may be different if time_t is still a 32-bit signed integer. | | 64 | # This may be different if time_t is still a 32-bit signed integer. |
61 | : INT32_MAX + 1 becomes ${:L:gmtime=2147483648}. | | 65 | : INT32_MAX + 1 becomes ${:L:gmtime=2147483648}. |
62 | | | 66 | |
63 | # Integer overflow. | | 67 | # Integer overflow. |
64 | # Because this modifier is implemented using strtoul, the parsed | | 68 | # Because this modifier is implemented using strtoul, the parsed |
65 | # time is ULONG_MAX, which gets converted to -1. This results | | 69 | # time is ULONG_MAX, which gets converted to -1. This results |
66 | # in a time stamp of the second before 1970. | | 70 | # in a time stamp of the second before 1970. |
67 | : overflow becomes ${:L:gmtime=10000000000000000000000000000000}. | | 71 | : overflow becomes ${:L:gmtime=10000000000000000000000000000000}. |
68 | | | 72 | |
69 | # As of 2020-10-31, there is no error handling while parsing the | | 73 | # As of 2020-10-31, there is no error handling while parsing the |
70 | # :gmtime modifier, thus no error message is printed. Parsing | | 74 | # :gmtime modifier, thus no error message is printed. Parsing |
71 | # stops after the '=', and the remaining string is parsed for | | 75 | # stops after the '=', and the remaining string is parsed for |
72 | # more variable modifiers. Because of the unknown modifier 'e', | | 76 | # more variable modifiers. Because of the unknown modifier 'e', |
73 | # the whole variable value is discarded and thus not printed. | | 77 | # the whole variable value is discarded and thus not printed. |
74 | : letter becomes ${:L:gmtime=error}. | | 78 | : letter becomes ${:L:gmtime=error}. |
75 | | | 79 | |
76 | all: | | 80 | all: |
77 | @:; | | 81 | @:; |