Home | History | Annotate | Line # | Download | only in unit-tests
      1  1.20  rillig # $NetBSD: varmod-localtime.mk,v 1.20 2025/01/11 20:54:46 rillig Exp $
      2   1.1  rillig #
      3   1.5  rillig # Tests for the :localtime variable modifier, which formats a timestamp
      4   1.5  rillig # using strftime(3) in local time.
      5   1.9  rillig #
      6   1.9  rillig # See also:
      7   1.9  rillig #	varmod-gmtime.mk
      8   1.5  rillig 
      9   1.5  rillig .if ${TZ} != "Europe/Berlin"	# see unit-tests/Makefile
     10   1.5  rillig .  error
     11   1.5  rillig .endif
     12   1.5  rillig 
     13   1.4  rillig # Test for the default time format, %c.  Since the time always varies, it's
     14   1.4  rillig # only possible to check for the general format here.  The names of the
     15   1.4  rillig # month and weekday are always in English, independent from the locale.
     16   1.4  rillig # Example: Thu Oct 29 18:56:41 2020
     17   1.4  rillig .if ${:U:localtime:tW:M??? ??? ?? ??\:??\:?? ????} == ""
     18   1.4  rillig .  error
     19   1.4  rillig .endif
     20   1.4  rillig 
     21   1.5  rillig 
     22   1.6  rillig # modifier name too short, falling back to the SysV modifier.
     23   1.6  rillig .if ${%Y:L:localtim=1593536400} != "%Y"
     24   1.6  rillig .  error
     25   1.6  rillig .endif
     26   1.6  rillig 
     27   1.6  rillig 
     28   1.6  rillig # 2020-07-01T00:00:00Z
     29   1.6  rillig .if ${%Y:L:localtime=1593536400} != "2020"
     30   1.6  rillig .  error
     31   1.6  rillig .endif
     32   1.6  rillig 
     33   1.6  rillig 
     34   1.6  rillig # modifier name too long, falling back to the SysV modifier.
     35   1.6  rillig .if ${%Y:L:localtimer=1593536400} != "%Y"
     36   1.6  rillig .  error
     37   1.6  rillig .endif
     38   1.6  rillig 
     39   1.6  rillig 
     40   1.6  rillig # If the modifier name is not matched exactly, fall back to the
     41   1.6  rillig # :from=to modifier.
     42   1.8  rillig .if ${localtime:L:local%=gm%} != "gmtime"
     43   1.6  rillig .  error
     44   1.6  rillig .endif
     45   1.6  rillig 
     46   1.6  rillig 
     47  1.10  rillig # Before var.c 1.1050 from 2023-05-09, it was not possible to pass the
     48  1.14  rillig # seconds via an expression.
     49  1.10  rillig .if ${%Y:L:localtime=${:U1593536400}} != "2020"
     50   1.6  rillig .  error
     51   1.6  rillig .endif
     52   1.6  rillig 
     53   1.6  rillig 
     54   1.6  rillig # Before var.c 1.631 from 2020-10-31 21:40:20, it was possible to pass
     55   1.6  rillig # negative time stamps to the :localtime modifier, resulting in dates before
     56   1.6  rillig # 1970.  Going back 50 years in the past is not a practical use case for
     57   1.6  rillig # make.  Therefore, since var.c 1.631, negative time stamps produce a
     58   1.6  rillig # parse error.
     59  1.20  rillig # expect+1: Invalid time value "-1"
     60   1.6  rillig .if ${:L:localtime=-1} != ""
     61   1.6  rillig .  error
     62   1.6  rillig .else
     63   1.6  rillig .  error
     64   1.6  rillig .endif
     65   1.6  rillig 
     66   1.6  rillig 
     67   1.8  rillig # Spaces were allowed before var.c 1.631 from 2020-10-31 21:40:20, not
     68   1.8  rillig # because it would make sense but just as a side-effect from using strtoul.
     69  1.20  rillig # expect+1: Invalid time value " 1"
     70   1.6  rillig .if ${:L:localtime= 1} != ""
     71   1.6  rillig .  error
     72   1.9  rillig .else
     73   1.9  rillig .  error
     74   1.6  rillig .endif
     75   1.6  rillig 
     76   1.6  rillig 
     77   1.6  rillig # 0 means now; this differs from GNode.mtime, where a 0 means nonexistent.
     78   1.6  rillig # Since "now" constantly changes, the strongest possible test is to match the
     79   1.6  rillig # resulting pattern.
     80   1.6  rillig .if !${:L:localtime=0:tW:M??? ??? ?? ??\:??\:?? 20??}
     81   1.6  rillig .  error
     82   1.6  rillig .endif
     83   1.6  rillig 
     84   1.6  rillig 
     85   1.6  rillig .if ${:L:localtime=1} != "Thu Jan  1 01:00:01 1970"
     86   1.6  rillig .  error
     87   1.6  rillig .endif
     88   1.6  rillig 
     89   1.6  rillig 
     90   1.6  rillig # INT32_MAX
     91   1.6  rillig .if ${:L:localtime=2147483647} != "Tue Jan 19 04:14:07 2038"
     92   1.6  rillig .  error
     93   1.6  rillig .endif
     94   1.6  rillig 
     95   1.6  rillig 
     96   1.6  rillig .if ${:L:localtime=2147483648} == "Tue Jan 19 04:14:08 2038"
     97   1.6  rillig # All systems that have unsigned time_t or 64-bit time_t.
     98   1.8  rillig .elif ${:L:localtime=2147483648} == "Fri Dec 13 21:45:52 1901"
     99   1.8  rillig # FreeBSD-12.0-i386 still has 32-bit signed time_t, see
    100   1.8  rillig # sys/x86/include/_types.h, __LP64__.
    101   1.8  rillig #
    102   1.8  rillig # Linux on 32-bit systems may still have 32-bit signed time_t, see
    103   1.8  rillig # sysdeps/unix/sysv/linux/generic/bits/typesizes.h, __TIMESIZE.
    104   1.6  rillig .else
    105   1.6  rillig .  error
    106   1.6  rillig .endif
    107   1.6  rillig 
    108   1.6  rillig 
    109   1.6  rillig # Integer overflow, at least before var.c 1.631 from 2020-10-31.
    110   1.6  rillig # Because this modifier is implemented using strtoul, the parsed time was
    111   1.6  rillig # ULONG_MAX, which got converted to -1.  This resulted in a time stamp of
    112   1.6  rillig # the second before 1970.
    113   1.6  rillig #
    114   1.9  rillig # Since var.c 1.631 from 2020-10-31, the overflow is detected and produces a
    115   1.9  rillig # parse error.
    116  1.20  rillig # expect+1: Invalid time value "10000000000000000000000000000000"
    117   1.6  rillig .if ${:L:localtime=10000000000000000000000000000000} != ""
    118   1.6  rillig .  error
    119   1.6  rillig .else
    120   1.6  rillig .  error
    121   1.6  rillig .endif
    122   1.6  rillig 
    123   1.7  rillig # Before var.c 1.631 from 2020-10-31, there was no error handling while
    124   1.8  rillig # parsing the :localtime modifier, thus no error message was printed.  Parsing
    125   1.6  rillig # stopped after the '=', and the remaining string was parsed for more variable
    126   1.6  rillig # modifiers.  Because of the unknown modifier 'e' from the 'error', the whole
    127   1.6  rillig # variable value was discarded and thus not printed.
    128  1.20  rillig # expect+1: Invalid time value "error"
    129   1.6  rillig .if ${:L:localtime=error} != ""
    130   1.6  rillig .  error
    131   1.6  rillig .else
    132   1.6  rillig .  error
    133   1.6  rillig .endif
    134   1.5  rillig 
    135  1.10  rillig # Before var.c 1.1050 from 2023-05-09, the timestamp could be directly
    136  1.12  rillig # followed by the next modifier, without a ':' separator.  This was the same
    137   1.9  rillig # bug as for the ':L' and ':P' modifiers.
    138  1.20  rillig # expect+1: Invalid time value "100000S,1970,bad,"
    139   1.9  rillig .if ${%Y:L:localtime=100000S,1970,bad,} != "bad"
    140   1.9  rillig .  error
    141   1.9  rillig .endif
    142   1.5  rillig 
    143   1.6  rillig all:
    144