summaryrefslogtreecommitdiffstats
path: root/tests/misc/time-style.sh
blob: 3433836353e79b69055989a0e8741dea0d52846e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
# Test --time-style in programs like 'ls'.

# Copyright (C) 2016-2023 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 <https://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 timestamp 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)' \
               +%%b%b%%b%b; 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 || framework_failure_
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
%bJul%bJul	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
%bJul%bJul	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
%bJul%bJul	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
%bJul%bJul	a
EOF

cat <<\EOF > lsexp || framework_failure_
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
%bJul%bJul 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
%bJul%bJul 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
%bJul%bJul 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
%bJul%bJul a
EOF

cat <<\EOF > prexp || framework_failure_
+1970-07-08 09:10:11 +0000 (UTC)                a                 Page 1
hello
+%bJul%bJul                           a                           Page 1
hello
+1970-07-08 01:10:11 -0800 (PST)                a                 Page 1
hello
+%bJul%bJul                           a                           Page 1
hello
+1970-07-08 02:10:11 -0700 (PDT)                a                 Page 1
hello
+%bJul%bJul                           a                           Page 1
hello
+1970-07-08 21:40:11 +1230 (XXXYYY)               a               Page 1
hello
+%bJul%bJul                           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