tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / misc / ls-time
1 #!/bin/sh
2 # Test some of ls's sorting options.
3
4 # Copyright (C) 1998-2001, 2004, 2007-2009 Free Software Foundation, Inc.
5
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.
10
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.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 if test "$VERBOSE" = yes; then
20   set -x
21   ls --version
22 fi
23
24 . $srcdir/test-lib.sh
25
26 # Avoid any possible glitches due to daylight-saving changes near the
27 # time stamps used during the test.
28 TZ=UTC0
29 export TZ
30
31 t1='1998-01-15 21:00'
32 t2='1998-01-15 22:00'
33 t3='1998-01-15 23:00'
34
35 u1='1998-01-14 11:00'
36 u2='1998-01-14 12:00'
37 u3='1998-01-14 13:00'
38
39 touch -m -d "$t3" a || framework_failure
40 touch -m -d "$t2" b || framework_failure
41 touch -m -d "$t1" c || framework_failure
42
43 touch -a -d "$u3" c || framework_failure
44 touch -a -d "$u2" b || framework_failure
45 # Make sure A has ctime at least 1 second more recent than C's.
46 sleep 2
47 touch -a -d "$u1" a || framework_failure
48
49
50 # A has ctime more recent than C.
51 set `ls -c a c`
52 test "$*" = 'a c' || fail=1
53
54 # Sleep so long in an attempt to avoid spurious failures
55 # due to NFS caching and/or clock skew.
56 sleep 2
57
58 # Create a link, updating c's ctime.
59 ln c d || framework_failure
60
61 # Before we go any further, verify that touch's -m option works.
62 set -- `ls --full -l a`
63 case "$*" in
64   *" $t3:00.000000000 +0000 a") ;;
65   *)
66   # This might be what's making HPUX 11 systems fail this test.
67   cat >&2 << EOF
68 A basic test of touch -m has just failed, so the subsequent
69 tests in this file will not be run.
70
71 In the output below, the date of last modification for \`a' should
72 have been $t3.
73 EOF
74   #`
75   ls --full -l a
76   framework_failure
77   ;;
78 esac
79
80 # Now test touch's -a option.
81 set -- `ls --full -lu a`
82 case "$*" in
83   *" $u1:00.000000000 +0000 a") ;;
84   *)
85   # This might be what's making HPUX 11 systems fail this test.
86   cat >&2 << EOF
87 A basic test of touch -a has just failed, so the subsequent
88 tests in this file will not be run.
89
90 In the output below, the date of last access for \`a' should
91 have been $u1.
92 EOF
93   ls --full -lu a
94   Exit 77
95   ;;
96 esac
97
98 set `ls -ut a b c`
99 test "$*" = 'c b a' && : || fail=1
100 test $fail = 1 && ls -l --full-time --time=access a b c
101
102 set `ls -t a b c`
103 test "$*" = 'a b c' && : || fail=1
104 test $fail = 1 && ls -l --full-time a b c
105
106 # Now, C should have ctime more recent than A.
107 set `ls -ct a c`
108 if test "$*" = 'c a'; then
109   : ok
110 else
111   # In spite of documentation, (e.g., stat(2)), neither link nor chmod
112   # update a file's st_ctime on SunOS4.1.4.
113   cat >&2 << \EOF
114 failed ls ctime test -- this failure is expected at least for SunOS4.1.4
115 and for tmpfs file systems on Solaris 5.5.1.
116
117 In the output below, `c' should have had a ctime more recent than
118 that of `a', but does not.
119 EOF
120   #'
121   ls -ctl --full-time a c
122   fail=1
123 fi
124
125 Exit $fail