summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-03-17 10:35:18 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2016-03-17 10:36:33 -0700
commitdf88fce71651afb2c3456967a142db0ae4bf9906 (patch)
treeaa18160fb6d2ef669fcfc04e914da9d10b649287 /tests
parentc18b3699e1b8c4ad2739761f2b9c306ff2303322 (diff)
downloadcoreutils-df88fce71651afb2c3456967a142db0ae4bf9906.tar.xz
date ls pr: fix time zone abbrs on SysV platforms
The problematic code computed a struct tm in one time zone, and then printed it or converted it to a string in another. To be portable the same time zone needs to be used for both operations. On GNU platforms this is not an issue, but incorrect output can be generated on System V style platforms like AIX where time zone abbreviations are available only in the 'tzname' global variable. Problem reported by Assaf Gordon in: http://bugs.gnu.org/23035 * NEWS: Document the bug. * src/date.c (show_date): * src/ls.c (long_time_expected_width, print_long_format): * src/pr.c (init_header): * src/stat.c (human_time): Use localtime_rz instead of localtime, so that the time zone information is consistent for both localtime and time-formatting functions like fprintftime and nstrftime. For 'stat' this change is mostly just a code cleanup but it also causes stat to also print nanoseconds when printing time stamps that are out of localtime range, as this is more consistent with what other programs do. For programs other than 'stat' this fixes bugs with time zone formats that use %Z. * src/du.c, src/pr.c (localtz): New static var. (main): Initialize it. * src/du.c (show_date): New time zone argument, so that localtime and fprintftime use the same time zone information. All callers changed. * tests/misc/time-style.sh: New file. * tests/local.mk (all_tests): Add it. * tests/misc/date.pl: Test alphabetic time zone abbreviations.
Diffstat (limited to 'tests')
-rw-r--r--tests/local.mk1
-rwxr-xr-xtests/misc/date.pl4
-rwxr-xr-xtests/misc/time-style.sh102
3 files changed, 107 insertions, 0 deletions
diff --git a/tests/local.mk b/tests/local.mk
index 8898897d0..a83c3d080 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -390,6 +390,7 @@ all_tests = \
tests/misc/tail.pl \
tests/misc/tee.sh \
tests/misc/test-diag.pl \
+ tests/misc/time-style.sh \
tests/misc/timeout.sh \
tests/misc/timeout-blocked.pl \
tests/misc/timeout-group.sh \
diff --git a/tests/misc/date.pl b/tests/misc/date.pl
index 2d1925496..3454dcc5b 100755
--- a/tests/misc/date.pl
+++ b/tests/misc/date.pl
@@ -218,6 +218,10 @@ my @Tests =
# Don't recognize %:z with a field width between the ':' and the 'z'.
['tz-5wf', '+%:8z', {OUT=>"%:8z"}, {ENV=>'TZ=XXX0:01'}],
+ # Test alphabetic timezone abbrv
+ ['tz-6', '+%Z', {OUT=>"UTC"}],
+ ['tz-7', '+%Z', {OUT=>"JST"}, {ENV=>'TZ=JST-9'}],
+
['ns-relative',
'--iso=ns',
"-d'1970-01-01 00:00:00.1234567 UTC +961062237.987654321 sec'",
diff --git a/tests/misc/time-style.sh b/tests/misc/time-style.sh
new file mode 100755
index 000000000..444996158
--- /dev/null
+++ b/tests/misc/time-style.sh
@@ -0,0 +1,102 @@
+#!/bin/sh
+# Test --time-style in programs like 'ls'.
+
+# Copyright (C) 2016 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ du
+print_ver_ ls
+print_ver_ pr
+
+echo hello >a || framework_failure_
+
+# The tests assume this is an old time stamp in northern hemisphere summer.
+TZ=UTC0 touch -d '1970-07-08 09:10:11' a || framework_failure_
+
+for tz in UTC0 PST8 PST8PDT,M3.2.0,M11.1.0 XXXYYY-12:30; do
+ for style in full-iso long-iso iso locale '+%Y-%m-%d %H:%M:%S %z (%Z)'; do
+ test "$style" = locale ||
+ TZ=$tz LC_ALL=C du --time --time-style="$style" a >>duout 2>>err || fail=1
+ TZ=$tz LC_ALL=C ls -no --time-style="$style" a >>lsout 2>>err || fail=1
+ case $style in
+ (+*) TZ=$tz LC_ALL=C pr -D"$style" a >>prout 2>>err || fail=1 ;;
+ esac
+ done
+done
+
+sed 's/[^ ]* //' duout >dued || framework_failure_
+sed 's/[^ ]* *[^ ]* *[^ ]* *[^ ]* *//' lsout >lsed || framework_failure_
+sed '/^$/d' prout >pred || framework_failure_
+
+cat <<\EOF > duexp || fail=1
+1970-07-08 09:10:11.000000000 +0000 a
+1970-07-08 09:10 a
+1970-07-08 a
+1970-07-08 09:10:11 +0000 (UTC) a
+1970-07-08 01:10:11.000000000 -0800 a
+1970-07-08 01:10 a
+1970-07-08 a
+1970-07-08 01:10:11 -0800 (PST) a
+1970-07-08 02:10:11.000000000 -0700 a
+1970-07-08 02:10 a
+1970-07-08 a
+1970-07-08 02:10:11 -0700 (PDT) a
+1970-07-08 21:40:11.000000000 +1230 a
+1970-07-08 21:40 a
+1970-07-08 a
+1970-07-08 21:40:11 +1230 (XXXYYY) a
+EOF
+
+cat <<\EOF > lsexp || fail=1
+1970-07-08 09:10:11.000000000 +0000 a
+1970-07-08 09:10 a
+1970-07-08 a
+Jul 8 1970 a
+1970-07-08 09:10:11 +0000 (UTC) a
+1970-07-08 01:10:11.000000000 -0800 a
+1970-07-08 01:10 a
+1970-07-08 a
+Jul 8 1970 a
+1970-07-08 01:10:11 -0800 (PST) a
+1970-07-08 02:10:11.000000000 -0700 a
+1970-07-08 02:10 a
+1970-07-08 a
+Jul 8 1970 a
+1970-07-08 02:10:11 -0700 (PDT) a
+1970-07-08 21:40:11.000000000 +1230 a
+1970-07-08 21:40 a
+1970-07-08 a
+Jul 8 1970 a
+1970-07-08 21:40:11 +1230 (XXXYYY) a
+EOF
+
+cat <<\EOF > prexp || fail=1
++1970-07-08 09:10:11 +0000 (UTC) a Page 1
+hello
++1970-07-08 01:10:11 -0800 (PST) a Page 1
+hello
++1970-07-08 02:10:11 -0700 (PDT) a Page 1
+hello
++1970-07-08 21:40:11 +1230 (XXXYYY) a Page 1
+hello
+EOF
+
+compare duexp dued || fail=1
+compare lsexp lsed || fail=1
+compare prexp pred || fail=1
+compare /dev/null err || fail=1
+
+Exit $fail