tests: add test for locale decimal processing
[coreutils.git] / tests / misc / ls-time.sh
blobdcb183ce3cd218004e563c68491b6e52e2cb35d5
1 #!/bin/sh
2 # Test some of ls's sorting options.
4 # Copyright (C) 1998-2019 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ ls
22 # Avoid any possible glitches due to daylight-saving changes near the
23 # timestamps used during the test.
24 TZ=UTC0
25 export TZ
27 t1='1998-01-15 21:00'
28 t2='1998-01-15 22:00'
29 t3='1998-01-15 23:00'
31 u1='1998-01-14 11:00'
32 u2='1998-01-14 12:00'
33 u3='1998-01-14 13:00'
35 touch -m -d "$t3" a || framework_failure_
36 touch -m -d "$t2" b || framework_failure_
37 touch -m -d "$t1" c || framework_failure_
39 touch -a -d "$u3" c || framework_failure_
40 touch -a -d "$u2" b || framework_failure_
41 # Make sure A has ctime at least 1 second more recent than C's.
42 sleep 2
43 touch -a -d "$u1" a || framework_failure_
44 # Updating the atime is usually enough to update the ctime, but on
45 # Solaris 10's tmpfs, ctime is not updated, so force an update here:
46 { ln a a-ctime && rm a-ctime; } || framework_failure_
49 # A has ctime more recent than C.
50 set $(ls -c a c)
51 test "$*" = 'a c' || fail=1
53 # Sleep so long in an attempt to avoid spurious failures
54 # due to NFS caching and/or clock skew.
55 sleep 2
57 # Create a link, updating c's ctime.
58 ln c d || framework_failure_
60 # Before we go any further, verify that touch's -m option works.
61 set -- $(ls --full -l a)
62 case "$*" in
63 *" $t3:00.000000000 +0000 a") ;;
65 # This might be what's making HPUX 11 systems fail this test.
66 cat >&2 << EOF
67 A basic test of touch -m has just failed, so the subsequent
68 tests in this file will not be run.
70 In the output below, the date of last modification for 'a' should
71 have been $t3.
72 EOF
73 ls --full -l a
74 skip_ "touch -m -d '$t3' didn't work"
76 esac
78 # Ensure that touch's -a option works.
79 set -- $(ls --full -lu a)
80 case "$*" in
81 *" $u1:00.000000000 +0000 a") ;;
83 # This might be what's making HPUX 11 systems fail this test.
84 cat >&2 << EOF
85 A fundamental touch -a test has just failed, so the subsequent
86 tests in this file will not be run.
88 In the output below, the date of last access for 'a' should
89 have been $u1.
90 EOF
91 ls --full -lu a
92 Exit 77
94 esac
96 set $(ls -ut a b c)
97 test "$*" = 'c b a' && : || fail=1
98 test $fail = 1 && ls -l --full-time --time=access a b c
100 set $(ls -t a b c)
101 test "$*" = 'a b c' && : || fail=1
102 test $fail = 1 && ls -l --full-time a b c
104 # Now, C should have ctime more recent than A.
105 set $(ls -ct a c)
106 if test "$*" = 'c a'; then
107 : ok
108 else
109 # In spite of documentation, (e.g., stat(2)), neither link nor chmod
110 # update a file's st_ctime on SunOS4.1.4.
111 cat >&2 << \EOF
112 failed ls ctime test -- this failure is expected at least for SunOS4.1.4
113 and for tmpfs file systems on Solaris 5.5.1.
114 It is also expected to fail on a btrfs file system until
115 https://bugzilla.redhat.com/591068 is addressed.
117 In the output below, 'c' should have had a ctime more recent than
118 that of 'a', but does not.
121 ls -ctl --full-time a c
122 fail=1
125 # This check is ineffective if:
126 # en_US locale is not on the system.
127 # The system en_US message catalog has a specific TIME_FMT translation,
128 # which was inadvertently the case between coreutils 8.1 and 8.5 inclusive.
130 if gettext --version >/dev/null 2>&1; then
132 default_tf1='%b %e %Y'
133 en_tf1=$(LC_ALL=en_US gettext coreutils "$default_tf1")
135 if test "$default_tf1" = "$en_tf1"; then
136 LC_ALL=en_US ls -l c >en_output
137 ls -l --time-style=long-iso c >liso_output
138 if compare en_output liso_output; then
139 fail=1
140 echo "Long ISO TIME_FMT being used for en_US locale." >&2
145 Exit $fail