]> arthur.barton.de Git - bup.git/blob - t/test-ls.sh
Makefile: fix tests with bash and pipefail
[bup.git] / t / test-ls.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh || exit $?
3
4 set -o pipefail
5
6 top="$(WVPASS pwd)" || exit $?
7 tmpdir="$(WVPASS wvmktempdir)" || exit $?
8
9 export BUP_DIR="$tmpdir/bup"
10 export GIT_DIR="$tmpdir/bup"
11
12 bup() { "$top/bup" "$@"; }
13
14 export TZ=UTC
15
16 WVPASS bup init
17 WVPASS cd "$tmpdir"
18
19 WVPASS mkdir src
20 WVPASS touch src/.dotfile src/executable
21 WVPASS mkfifo src/fifo
22 WVPASS "$top"/t/mksock src/socket
23 WVPASS bup random 1k > src/file
24 WVPASS chmod u+x src/executable
25 WVPASS chmod -R u=rwX,g-rwx,o-rwx .
26 WVPASS touch -t 196907202018 src/.dotfile src/*
27 (WVPASS cd src; WVPASS ln -s file symlink) || exit $?
28 WVPASS touch -t 196907202018 src
29 WVPASS touch -t 196907202018 .
30 WVPASS bup index src
31 WVPASS bup save -n src -d 242312160 src
32 WVPASS bup tag some-tag src
33
34
35 WVSTART "ls (short)"
36
37 WVPASSEQ "$(WVPASS bup ls /)" "src"
38
39 WVPASSEQ "$(WVPASS bup ls -A /)" ".commit
40 .tag
41 src"
42
43 WVPASSEQ "$(WVPASS bup ls -AF /)" ".commit/
44 .tag/
45 src/"
46
47 WVPASSEQ "$(WVPASS bup ls -a /)" ".
48 ..
49 .commit
50 .tag
51 src"
52
53 WVPASSEQ "$(WVPASS bup ls -aF /)" "./
54 ../
55 .commit/
56 .tag/
57 src/"
58
59 WVPASSEQ "$(WVPASS bup ls /.tag)" "some-tag"
60
61 WVPASSEQ "$(WVPASS bup ls /src)" \
62 "1977-09-05-125600
63 latest"
64
65 WVPASSEQ "$(WVPASS bup ls src/latest/"$tmpdir"/src)" "executable
66 fifo
67 file
68 socket
69 symlink"
70
71 WVPASSEQ "$(WVPASS bup ls -A src/latest/"$tmpdir"/src)" ".dotfile
72 executable
73 fifo
74 file
75 socket
76 symlink"
77
78 WVPASSEQ "$(WVPASS bup ls -a src/latest/"$tmpdir"/src)" ".
79 ..
80 .dotfile
81 executable
82 fifo
83 file
84 socket
85 symlink"
86
87 WVPASSEQ "$(WVPASS bup ls -F src/latest/"$tmpdir"/src)" "executable*
88 fifo|
89 file
90 socket=
91 symlink@"
92
93 WVPASSEQ "$(WVPASS bup ls --file-type src/latest/"$tmpdir"/src)" "executable
94 fifo|
95 file
96 socket=
97 symlink@"
98
99 WVPASSEQ "$(WVPASS bup ls -d src/latest/"$tmpdir"/src)" "src/latest$tmpdir/src"
100
101
102 WVSTART "ls (long)"
103
104 WVPASSEQ "$(WVPASS bup ls -l / | tr -s ' ' ' ')" \
105 "d--------- ?/? 0 1970-01-01 00:00 src"
106
107 WVPASSEQ "$(WVPASS bup ls -lA / | tr -s ' ' ' ')" \
108 "d--------- ?/? 0 1970-01-01 00:00 .commit
109 d--------- ?/? 0 1970-01-01 00:00 .tag
110 d--------- ?/? 0 1970-01-01 00:00 src"
111
112 WVPASSEQ "$(WVPASS bup ls -lAF / | tr -s ' ' ' ')" \
113 "d--------- ?/? 0 1970-01-01 00:00 .commit/
114 d--------- ?/? 0 1970-01-01 00:00 .tag/
115 d--------- ?/? 0 1970-01-01 00:00 src/"
116
117 WVPASSEQ "$(WVPASS bup ls -la / | tr -s ' ' ' ')" \
118 "d--------- ?/? 0 1970-01-01 00:00 .
119 d--------- ?/? 0 1970-01-01 00:00 ..
120 d--------- ?/? 0 1970-01-01 00:00 .commit
121 d--------- ?/? 0 1970-01-01 00:00 .tag
122 d--------- ?/? 0 1970-01-01 00:00 src"
123
124 WVPASSEQ "$(WVPASS bup ls -laF / | tr -s ' ' ' ')" \
125 "d--------- ?/? 0 1970-01-01 00:00 ./
126 d--------- ?/? 0 1970-01-01 00:00 ../
127 d--------- ?/? 0 1970-01-01 00:00 .commit/
128 d--------- ?/? 0 1970-01-01 00:00 .tag/
129 d--------- ?/? 0 1970-01-01 00:00 src/"
130
131 symlink_mode="$(WVPASS ls -l src/symlink | cut -b -10)" || exit $?
132
133 symlink_bup_info="$(WVPASS bup ls -l src/latest"$tmpdir"/src | grep symlink)" \
134     || exit $?
135 symlink_date="$(WVPASS echo "$symlink_bup_info" \
136   | WVPASS perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')" \
137     || exit $?
138
139 if test "$(uname -s)" != NetBSD; then
140     symlink_size="$(WVPASS python -c "import os
141 print os.lstat('src/symlink').st_size")" || exit $?
142 else
143     # NetBSD appears to return varying sizes, so for now, just ignore it.
144     symlink_size="$(WVPASS echo "$symlink_bup_info" \
145       | WVPASS perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $1')" \
146         || exit $?
147 fi
148
149 uid="$(id -u)" || exit $?
150 gid="$(python -c 'import os; print os.stat("src").st_gid')" || exit $?
151 user="$(id -un)" || exit $?
152 group="$(python -c 'import grp, os;
153 print grp.getgrgid(os.stat("src").st_gid)[0]')" || exit $?
154
155 WVPASSEQ "$(bup ls -l src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
156 "-rwx------ $user/$group 0 1969-07-20 20:18 executable
157 prw------- $user/$group 0 1969-07-20 20:18 fifo
158 -rw------- $user/$group 1024 1969-07-20 20:18 file
159 srwx------ $user/$group 0 1969-07-20 20:18 socket
160 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
161
162 WVPASSEQ "$(bup ls -la src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
163 "drwx------ $user/$group 0 1969-07-20 20:18 .
164 drwx------ $user/$group 0 1969-07-20 20:18 ..
165 -rw------- $user/$group 0 1969-07-20 20:18 .dotfile
166 -rwx------ $user/$group 0 1969-07-20 20:18 executable
167 prw------- $user/$group 0 1969-07-20 20:18 fifo
168 -rw------- $user/$group 1024 1969-07-20 20:18 file
169 srwx------ $user/$group 0 1969-07-20 20:18 socket
170 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
171
172 WVPASSEQ "$(bup ls -lA src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
173 "-rw------- $user/$group 0 1969-07-20 20:18 .dotfile
174 -rwx------ $user/$group 0 1969-07-20 20:18 executable
175 prw------- $user/$group 0 1969-07-20 20:18 fifo
176 -rw------- $user/$group 1024 1969-07-20 20:18 file
177 srwx------ $user/$group 0 1969-07-20 20:18 socket
178 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
179
180 WVPASSEQ "$(bup ls -lF src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
181 "-rwx------ $user/$group 0 1969-07-20 20:18 executable*
182 prw------- $user/$group 0 1969-07-20 20:18 fifo|
183 -rw------- $user/$group 1024 1969-07-20 20:18 file
184 srwx------ $user/$group 0 1969-07-20 20:18 socket=
185 $symlink_mode $user/$group $symlink_size $symlink_date symlink@ -> file"
186
187 WVPASSEQ "$(bup ls -l --file-type src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
188 "-rwx------ $user/$group 0 1969-07-20 20:18 executable
189 prw------- $user/$group 0 1969-07-20 20:18 fifo|
190 -rw------- $user/$group 1024 1969-07-20 20:18 file
191 srwx------ $user/$group 0 1969-07-20 20:18 socket=
192 $symlink_mode $user/$group $symlink_size $symlink_date symlink@ -> file"
193
194 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
195 "-rwx------ $uid/$gid 0 1969-07-20 20:18 executable
196 prw------- $uid/$gid 0 1969-07-20 20:18 fifo
197 -rw------- $uid/$gid 1024 1969-07-20 20:18 file
198 srwx------ $uid/$gid 0 1969-07-20 20:18 socket
199 $symlink_mode $uid/$gid $symlink_size $symlink_date symlink -> file"
200
201 WVPASSEQ "$(bup ls -ld "src/latest$tmpdir/src" | tr -s ' ' ' ')" \
202 "drwx------ $user/$group 0 1969-07-20 20:18 src/latest$tmpdir/src"
203
204
205 WVSTART "ls (backup set - long)"
206 WVPASSEQ "$(bup ls -l src | cut -d' ' -f 1-2)" \
207 "l--------- ?/?
208 l--------- ?/?"
209
210
211 WVSTART "ls (dates TZ != UTC)"
212 export TZ=America/Chicago
213 symlink_date_central="$(bup ls -l src/latest"$tmpdir"/src | grep symlink)"
214 symlink_date_central="$(echo "$symlink_date_central" \
215   | perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')"
216 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
217 "-rwx------ $uid/$gid 0 1969-07-20 15:18 executable
218 prw------- $uid/$gid 0 1969-07-20 15:18 fifo
219 -rw------- $uid/$gid 1024 1969-07-20 15:18 file
220 srwx------ $uid/$gid 0 1969-07-20 15:18 socket
221 $symlink_mode $uid/$gid $symlink_size $symlink_date_central symlink -> file"
222 unset TZ
223
224
225 WVPASS rm -rf "$tmpdir"