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