Skip to content

Commit 0d54532

Browse files
committed
tests/ansi: add test case for TZ environment variable behaviour
1 parent 7348c18 commit 0d54532

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

tests/ansi/tz.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <stdio.h>
2+
#include <time.h>
3+
4+
extern int daylight;
5+
extern long timezone;
6+
extern char *tzname[2];
7+
8+
int main() {
9+
tzset();
10+
printf("%s %ld %d\n", tzname[0], timezone, daylight);
11+
return 0;
12+
}

tests/ansi/tz.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import subprocess
2+
import sys
3+
import os
4+
from pyexpect import expect
5+
6+
wrapper = os.getenv("MESON_EXE_WRAPPER")
7+
wrapper = [x for x in (wrapper,) if x]
8+
9+
def check_tz(tz, expected):
10+
output = subprocess.check_output(
11+
wrapper + [sys.argv[1]],
12+
stderr=subprocess.STDOUT,
13+
env={"TZ": tz},
14+
)
15+
16+
expect(expected).to_equal(output)
17+
18+
check_tz("UTC0", b"UTC 0 0\n")
19+
check_tz("GMT0", b"GMT 0 0\n")
20+
check_tz(":UTC0", b"UTC 0 0\n")
21+
check_tz("EST+5", b"EST 18000 0\n")
22+
check_tz("EET-2", b"EET -7200 0\n")
23+
check_tz("<+03>-03", b"+03 -10800 0\n")
24+
check_tz("NZST-12", b"NZST -43200 0\n")
25+
check_tz("NST+03:40", b"NST 13200 0\n")
26+
check_tz("NPT-05:45", b"NPT -20700 0\n")
27+
28+
# These depend on tzdata, which may or may not exist.
29+
# Useful to check every now and then, but these also present subtle differences
30+
# between the host libc and mlibc, so we can't expect these to always hold up.
31+
# E.g. glibc will set `tzname` from the TZ environment variable even if it
32+
# cannot find the tzinfo file, however mlibc will use the name of the timezone
33+
# as read from the tzinfo file or the timezone that it defaults to (UTC).
34+
35+
# Would be b"Universal 0 0\n" on glibc.
36+
# check_tz("", b"UTC 0 0\n")
37+
38+
# check_tz("UTC", b"UTC 0 0\n")
39+
# check_tz(":UTC", b"UTC 0 0\n")
40+
41+
# Would be b"Universal 0 0\n" on glibc.
42+
# check_tz("Universal", b"UTC 0 0\n")
43+
# check_tz(":Universal", b"UTC 0 0\n")
44+
45+
# Would be b"ATimeZoneThatShouldHopefullyNeverBeInTzdata 0 0\n" on glibc.
46+
# check_tz("ATimeZoneThatShouldHopefullyNeverBeInTzdata", b"UTC 0 0\n")
47+
# check_tz(":ATimeZoneThatShouldHopefullyNeverBeInTzdata", b"UTC 0 0\n")

tests/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ all_test_cases = [
1818
'ansi/wcsrtombs',
1919
'ansi/wmemcmp',
2020
'ansi/timegm',
21+
'ansi/tz',
2122
'ansi/ungetc',
2223
'ansi/wcsdup',
2324
'ansi/wcsncasecmp',
@@ -130,6 +131,7 @@ fail_test_cases = [
130131
]
131132

132133
wrapped_test_cases = [
134+
'ansi/tz',
133135
'glibc/error',
134136
'glibc/error_at_line',
135137
]

0 commit comments

Comments
 (0)