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