]> arthur.barton.de Git - bup.git/blob - t/test-ls.sh
test-ls.sh: get the symlink mode from the host ls; test for subcmd failure.
[bup.git] / t / test-ls.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh
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 -t 196907202018 src/.dotfile
21 WVPASS bup random 1k > src/file
22 WVPASS touch -t 196907202018 src/file
23 (WVPASS cd src; WVPASS ln -s file symlink) || exit $?
24 WVPASS mkfifo src/fifo
25 WVPASS touch -t 196907202018 src/fifo
26 WVPASS "$top"/t/mksock src/socket
27 WVPASS touch -t 196907202018 src/socket
28 WVPASS touch -t 196907202018 src/executable
29 WVPASS chmod u+x src/executable
30 WVPASS touch -t 196907202018 src/executable
31 WVPASS touch -t 196907202018 src
32 WVPASS touch -t 196907202018 .
33 WVPASS chmod -R u=rwX,g-rwx,o-rwx .
34 WVPASS bup index src
35 WVPASS bup save -n src src
36
37 WVSTART "ls (short)"
38
39 WVPASSEQ "$(WVPASS bup ls /)" "src"
40
41 WVPASSEQ "$(WVPASS bup ls -A /)" ".commit
42 .tag
43 src"
44
45 WVPASSEQ "$(WVPASS bup ls -AF /)" ".commit/
46 .tag/
47 src/"
48
49 WVPASSEQ "$(WVPASS bup ls -a /)" ".
50 ..
51 .commit
52 .tag
53 src"
54
55 WVPASSEQ "$(WVPASS bup ls -aF /)" "./
56 ../
57 .commit/
58 .tag/
59 src/"
60
61 WVPASSEQ "$(WVPASS bup ls src/latest/"$tmpdir"/src)" "executable
62 fifo
63 file
64 socket
65 symlink"
66
67 WVPASSEQ "$(WVPASS bup ls -A src/latest/"$tmpdir"/src)" ".dotfile
68 executable
69 fifo
70 file
71 socket
72 symlink"
73
74 WVPASSEQ "$(WVPASS bup ls -a src/latest/"$tmpdir"/src)" ".
75 ..
76 .dotfile
77 executable
78 fifo
79 file
80 socket
81 symlink"
82
83 WVPASSEQ "$(WVPASS bup ls -F src/latest/"$tmpdir"/src)" "executable*
84 fifo|
85 file
86 socket=
87 symlink@"
88
89 WVPASSEQ "$(WVPASS bup ls --file-type src/latest/"$tmpdir"/src)" "executable
90 fifo|
91 file
92 socket=
93 symlink@"
94
95 WVSTART "ls (long)"
96
97 WVPASSEQ "$(WVPASS bup ls -l / | tr -s ' ' ' ')" \
98 "d--------- ?/? 0 1970-01-01 00:00 src"
99
100 WVPASSEQ "$(WVPASS bup ls -lA / | tr -s ' ' ' ')" \
101 "d--------- ?/? 0 1970-01-01 00:00 .commit
102 d--------- ?/? 0 1970-01-01 00:00 .tag
103 d--------- ?/? 0 1970-01-01 00:00 src"
104
105 WVPASSEQ "$(WVPASS bup ls -lAF / | tr -s ' ' ' ')" \
106 "d--------- ?/? 0 1970-01-01 00:00 .commit/
107 d--------- ?/? 0 1970-01-01 00:00 .tag/
108 d--------- ?/? 0 1970-01-01 00:00 src/"
109
110 WVPASSEQ "$(WVPASS bup ls -la / | tr -s ' ' ' ')" \
111 "d--------- ?/? 0 1970-01-01 00:00 .
112 d--------- ?/? 0 1970-01-01 00:00 ..
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 -laF / | 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 symlink_mode="$(WVPASS ls -l src/symlink | cut -d' ' -f 1)" || exit $?
125
126 symlink_size="$(WVPASS python -c "import os
127 print os.lstat('src/symlink').st_size")" || exit $?
128
129 symlink_date="$(WVPASS bup ls -l src/latest"$tmpdir"/src | grep symlink)" || exit $?
130 symlink_date="$(WVPASS echo "$symlink_date" \
131   | WVPASS perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')" \
132     || exit $?
133
134 uid="$(id -u)" || exit $?
135 gid="$(id -g)" || exit $?
136 user="$(id -un)" || exit $?
137 group="$(id -gn)" || exit $?
138
139 WVPASSEQ "$(bup ls -l src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
140 "-rwx------ $user/$group 0 1969-07-20 20:18 executable
141 prw------- $user/$group 0 1969-07-20 20:18 fifo
142 -rw------- $user/$group 1024 1969-07-20 20:18 file
143 srwx------ $user/$group 0 1969-07-20 20:18 socket
144 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
145
146 WVPASSEQ "$(bup ls -la src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
147 "drwx------ $user/$group 0 1969-07-20 20:18 .
148 drwx------ $user/$group 0 1969-07-20 20:18 ..
149 -rw------- $user/$group 0 1969-07-20 20:18 .dotfile
150 -rwx------ $user/$group 0 1969-07-20 20:18 executable
151 prw------- $user/$group 0 1969-07-20 20:18 fifo
152 -rw------- $user/$group 1024 1969-07-20 20:18 file
153 srwx------ $user/$group 0 1969-07-20 20:18 socket
154 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
155
156 WVPASSEQ "$(bup ls -lA src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
157 "-rw------- $user/$group 0 1969-07-20 20:18 .dotfile
158 -rwx------ $user/$group 0 1969-07-20 20:18 executable
159 prw------- $user/$group 0 1969-07-20 20:18 fifo
160 -rw------- $user/$group 1024 1969-07-20 20:18 file
161 srwx------ $user/$group 0 1969-07-20 20:18 socket
162 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
163
164 WVPASSEQ "$(bup ls -lF src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
165 "-rwx------ $user/$group 0 1969-07-20 20:18 executable*
166 prw------- $user/$group 0 1969-07-20 20:18 fifo|
167 -rw------- $user/$group 1024 1969-07-20 20:18 file
168 srwx------ $user/$group 0 1969-07-20 20:18 socket=
169 $symlink_mode $user/$group $symlink_size $symlink_date symlink@ -> file"
170
171 WVPASSEQ "$(bup ls -l --file-type src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
172 "-rwx------ $user/$group 0 1969-07-20 20:18 executable
173 prw------- $user/$group 0 1969-07-20 20:18 fifo|
174 -rw------- $user/$group 1024 1969-07-20 20:18 file
175 srwx------ $user/$group 0 1969-07-20 20:18 socket=
176 $symlink_mode $user/$group $symlink_size $symlink_date symlink@ -> file"
177
178 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
179 "-rwx------ $uid/$gid 0 1969-07-20 20:18 executable
180 prw------- $uid/$gid 0 1969-07-20 20:18 fifo
181 -rw------- $uid/$gid 1024 1969-07-20 20:18 file
182 srwx------ $uid/$gid 0 1969-07-20 20:18 socket
183 $symlink_mode $uid/$gid $symlink_size $symlink_date symlink -> file"
184
185 WVSTART "ls (backup set - long)"
186 WVPASSEQ "$(bup ls -l src | cut -d' ' -f 1-2)" \
187 "l--------- ?/?
188 l--------- ?/?"
189
190 WVSTART "ls (dates TZ != UTC)"
191 export TZ=US/Central
192 symlink_date_central="$(bup ls -l src/latest"$tmpdir"/src | grep symlink)"
193 symlink_date_central="$(echo "$symlink_date_central" \
194   | perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')"
195 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
196 "-rwx------ $uid/$gid 0 1969-07-20 15:18 executable
197 prw------- $uid/$gid 0 1969-07-20 15:18 fifo
198 -rw------- $uid/$gid 1024 1969-07-20 15:18 file
199 srwx------ $uid/$gid 0 1969-07-20 15:18 socket
200 $symlink_mode $uid/$gid $symlink_size $symlink_date_central symlink -> file"
201 unset TZ
202
203 WVPASS rm -rf "$tmpdir"