]> arthur.barton.de Git - bup.git/blob - t/test.sh
b48b1b681c41f312b0440324fafcd1d88fb9bba1
[bup.git] / t / test.sh
1 #!/usr/bin/env bash
2 . wvtest.sh
3 . wvtest-bup.sh
4 . t/lib.sh
5
6 set -o pipefail
7
8 top="$(WVPASS /bin/pwd)" || exit $?
9 tmpdir="$(WVPASS wvmktempdir)" || exit $?
10 export BUP_DIR="$tmpdir/bup"
11
12 bup() { "$top/bup" "$@"; }
13
14 WVPASS cd "$tmpdir"
15
16 WVSTART "init"
17
18 WVPASS bup init
19
20 WVSTART "index"
21 D=bupdata.tmp
22 WVPASS force-delete $D
23 WVPASS mkdir $D
24 WVFAIL bup index --exclude-from $D/cannot-exist $D
25 WVPASSEQ "$(bup index --check -p)" ""
26 WVPASSEQ "$(bup index --check -p $D)" ""
27 WVFAIL [ -e $D.fake ]
28 WVFAIL bup index --check -u $D.fake
29 WVPASS bup index --check -u $D
30 WVPASSEQ "$(bup index --check -p $D)" "$D/"
31 WVPASS touch $D/a
32 WVPASS bup random 128k >$D/b
33 WVPASS mkdir $D/d $D/d/e
34 WVPASS bup random 512 >$D/f
35 WVPASS ln -s non-existent-file $D/g
36 WVPASSEQ "$(bup index -s $D/)" "A $D/"
37 WVPASSEQ "$(bup index -s $D/b)" ""
38 WVPASSEQ "$(bup index --check -us $D/b)" "A $D/b"
39 WVPASSEQ "$(bup index --check -us $D/b $D/d)" \
40 "A $D/d/e/
41 A $D/d/
42 A $D/b"
43 WVPASS touch $D/d/z
44 WVPASS bup tick
45 WVPASSEQ "$(bup index --check -usx $D)" \
46 "A $D/g
47 A $D/f
48 A $D/d/z
49 A $D/d/e/
50 A $D/d/
51 A $D/b
52 A $D/a
53 A $D/"
54 WVPASSEQ "$(bup index --check -us $D/a $D/b --fake-valid)" \
55 "  $D/b
56   $D/a"
57 WVPASSEQ "$(bup index --check -us $D/a)" "  $D/a"  # stays unmodified
58 WVPASSEQ "$(bup index --check -us $D/d --fake-valid)" \
59 "  $D/d/z
60   $D/d/e/
61   $D/d/"
62 WVPASS touch $D/d/z
63 WVPASS bup index -u $D/d/z  # becomes modified
64 WVPASSEQ "$(bup index -s $D/a $D $D/b)" \
65 "A $D/g
66 A $D/f
67 M $D/d/z
68   $D/d/e/
69 M $D/d/
70   $D/b
71   $D/a
72 A $D/"
73
74 WVPASS bup index -u $D/d/e $D/a --fake-invalid
75 WVPASSEQ "$(cd $D && bup index -m .)" \
76 "./g
77 ./f
78 ./d/z
79 ./d/e/
80 ./d/
81 ./a
82 ./"
83 WVPASSEQ "$(cd $D && bup index -m)" \
84 "g
85 f
86 d/z
87 d/e/
88 d/
89 a
90 ./"
91 WVPASSEQ "$(cd $D && bup index -s .)" "$(cd $D && bup index -s .)"
92
93 WVFAIL bup save -t $D/doesnt-exist-filename
94
95 WVPASS mv "$BUP_DIR/bupindex" "$BUP_DIR/bi.old"
96 WVFAIL bup save -t $D/d/e/fifotest
97 WVPASS mkfifo $D/d/e/fifotest
98 WVPASS bup index -u $D/d/e/fifotest
99 WVPASS bup save -t $D/d/e/fifotest
100 WVPASS bup save -t $D/d/e
101 WVPASS rm -f $D/d/e/fifotest
102 WVPASS bup index -u $D/d/e
103 WVFAIL bup save -t $D/d/e/fifotest
104 WVPASS mv "$BUP_DIR/bi.old" "$BUP_DIR/bupindex"
105
106 WVPASS bup index -u $D/d/e
107 WVPASS bup save -t $D/d/e
108 WVPASSEQ "$(cd $D && bup index -m)" \
109 "g
110 f
111 d/z
112 d/
113 a
114 ./"
115 WVPASS bup save -t $D/d
116 WVPASS bup index --fake-invalid $D/d/z
117 WVPASS bup save -t $D/d/z
118 WVPASS bup save -t $D/d/z  # test regenerating trees when no files are changed
119 WVPASS bup save -t $D/d
120 WVPASSEQ "$(cd $D && bup index -m)" \
121 "g
122 f
123 a
124 ./"
125 WVPASS bup save -r ":$BUP_DIR" -n r-test $D
126 WVFAIL bup save -r ":$BUP_DIR/fake/path" -n r-test $D
127 WVFAIL bup save -r ":$BUP_DIR" -n r-test $D/fake/path
128
129 WVSTART "split"
130 WVPASS echo a >a.tmp
131 WVPASS echo b >b.tmp
132 WVPASS bup split -b a.tmp >taga.tmp
133 WVPASS bup split -b b.tmp >tagb.tmp
134 WVPASS cat a.tmp b.tmp | WVPASS bup split -b >tagab.tmp
135 WVPASSEQ $(cat taga.tmp | wc -l) 1
136 WVPASSEQ $(cat tagb.tmp | wc -l) 1
137 WVPASSEQ $(cat tagab.tmp | wc -l) 1
138 WVPASSEQ $(cat tag[ab].tmp | wc -l) 2
139 WVPASSEQ "$(bup split -b a.tmp b.tmp)" "$(cat tagab.tmp)"
140 WVPASSEQ "$(bup split -b --keep-boundaries a.tmp b.tmp)" "$(cat tag[ab].tmp)"
141 WVPASSEQ "$(cat tag[ab].tmp | bup split -b --keep-boundaries --git-ids)" \
142          "$(cat tag[ab].tmp)"
143 WVPASSEQ "$(cat tag[ab].tmp | bup split -b --git-ids)" \
144          "$(cat tagab.tmp)"
145 WVPASS bup split --bench -b <"$top/t/testfile1" >tags1.tmp
146 WVPASS bup split -vvvv -b "$top/t/testfile2" >tags2.tmp
147 WVPASS echo -n "" | bup split -n split_empty_string.tmp
148 WVPASS bup margin
149 WVPASS bup midx -f
150 WVPASS bup midx --check -a
151 WVPASS bup midx -o "$BUP_DIR/objects/pack/test1.midx" \
152         "$BUP_DIR"/objects/pack/*.idx
153 WVPASS bup midx --check -a
154 WVPASS bup midx -o "$BUP_DIR"/objects/pack/test1.midx \
155         "$BUP_DIR"/objects/pack/*.idx \
156         "$BUP_DIR"/objects/pack/*.idx
157 WVPASS bup midx --check -a
158 all=$(echo "$BUP_DIR"/objects/pack/*.idx "$BUP_DIR"/objects/pack/*.midx)
159 WVPASS bup midx -o "$BUP_DIR"/objects/pack/zzz.midx $all
160 WVPASS bup tick
161 WVPASS bup midx -o "$BUP_DIR"/objects/pack/yyy.midx $all
162 WVPASS bup midx -a
163 WVPASSEQ "$(echo "$BUP_DIR"/objects/pack/*.midx)" \
164         ""$BUP_DIR"/objects/pack/yyy.midx"
165 WVPASS bup margin
166 WVPASS bup split -t "$top/t/testfile2" >tags2t.tmp
167 WVPASS bup split -t "$top/t/testfile2" --fanout 3 >tags2tf.tmp
168 WVPASS bup split -r "$BUP_DIR" -c "$top/t/testfile2" >tags2c.tmp
169 WVPASS bup split -r ":$BUP_DIR" -c "$top/t/testfile2" >tags2c.tmp
170 WVPASS ls -lR \
171     | WVPASS bup split -r ":$BUP_DIR" -c --fanout 3 --max-pack-objects 3 -n lslr \
172     || exit $?
173 WVPASS bup ls
174 WVFAIL bup ls /does-not-exist
175 WVPASS bup ls /lslr
176 WVPASS bup ls /lslr/latest
177 WVPASS bup ls /lslr/latest/
178 #WVPASS bup ls /lslr/1971-01-01   # all dates always exist
179 WVFAIL diff -u tags1.tmp tags2.tmp
180
181 # fanout must be different from non-fanout
182 WVFAIL diff tags2t.tmp tags2tf.tmp
183 WVPASS wc -c "$top/t/testfile1" "$top/t/testfile2"
184 WVPASS wc -l tags1.tmp tags2.tmp
185
186 WVSTART "bloom"
187 WVPASS bup bloom -c $(ls -1 "$BUP_DIR"/objects/pack/*.idx|head -n1)
188 WVPASS rm "$BUP_DIR"/objects/pack/bup.bloom
189 WVPASS bup bloom -k 4
190 WVPASS bup bloom -c $(ls -1 "$BUP_DIR"/objects/pack/*.idx|head -n1)
191 WVPASS bup bloom -d "$BUP_DIR"/objects/pack --ruin --force
192 WVFAIL bup bloom -c $(ls -1 "$BUP_DIR"/objects/pack/*.idx|head -n1)
193 WVPASS bup bloom --force -k 5
194 WVPASS bup bloom -c $(ls -1 "$BUP_DIR"/objects/pack/*.idx|head -n1)
195
196 WVSTART "memtest"
197 WVPASS bup memtest -c1 -n100
198 WVPASS bup memtest -c1 -n100 --existing
199
200 WVSTART "join"
201 WVPASS bup join $(cat tags1.tmp) >out1.tmp
202 WVPASS bup join <tags2.tmp >out2.tmp
203 WVPASS bup join <tags2t.tmp -o out2t.tmp
204 WVPASS bup join -r "$BUP_DIR" <tags2c.tmp >out2c.tmp
205 WVPASS bup join -r ":$BUP_DIR" <tags2c.tmp >out2c.tmp
206 WVPASS diff -u "$top/t/testfile1" out1.tmp
207 WVPASS diff -u "$top/t/testfile2" out2.tmp
208 WVPASS diff -u "$top/t/testfile2" out2t.tmp
209 WVPASS diff -u "$top/t/testfile2" out2c.tmp
210 WVPASSEQ "$(bup join split_empty_string.tmp)" ""
211
212 WVSTART "save/git-fsck"
213 (
214     WVPASS cd "$BUP_DIR"
215     #git repack -Ad
216     #git prune
217     (WVPASS cd "$top/t/sampledata" && WVPASS bup save -vvn master /) || exit $?
218     result="$(git fsck --full --strict 2>&1)" || exit $?
219     n=$(echo "$result" |
220         WVFAIL egrep -v 'dangling (commit|tree|blob)' |
221         WVPASS tee -a /dev/stderr |
222         WVPASS wc -l) || exit $?
223     WVPASS [ "$n" -eq 0 ]
224 ) || exit $?
225
226 WVSTART "restore"
227 WVPASS force-delete buprestore.tmp
228 WVFAIL bup restore boink
229 WVPASS touch "$tmpdir/$D/$D"
230 WVPASS bup index -u "$tmpdir/$D"
231 WVPASS bup save -n master /
232 WVPASS bup restore -C buprestore.tmp "/master/latest/$tmpdir/$D"
233 WVPASSEQ "$(ls buprestore.tmp)" "bupdata.tmp"
234 WVPASS force-delete buprestore.tmp
235 WVPASS bup restore -C buprestore.tmp "/master/latest/$tmpdir/$D/"
236 WVPASS touch $D/non-existent-file buprestore.tmp/non-existent-file # else diff fails
237 WVPASS diff -ur $D/ buprestore.tmp/
238 WVPASS force-delete buprestore.tmp
239 WVPASS bup restore -C buprestore.tmp split_empty_string.tmp/latest/
240 WVPASSEQ "$(cat buprestore.tmp/data)" ""
241
242 (
243     tmp=testrestore.tmp
244     WVPASS force-delete $tmp
245     WVPASS mkdir $tmp
246     export BUP_DIR="$(pwd)/$tmp/bup"
247     WVPASS WVPASS bup init
248     WVPASS mkdir -p $tmp/src/x/y/z
249     WVPASS bup random 8k > $tmp/src/x/y/random-1
250     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
251     WVPASS bup index -u $tmp/src
252     WVPASS bup save --strip -n foo $tmp/src
253
254     WVSTART "restore /foo/latest"
255     WVPASS bup restore -C $tmp/restore /foo/latest
256     WVPASS "$top/t/compare-trees" $tmp/src/ $tmp/restore/latest/
257
258     WVSTART "restore /foo/latest/"
259     WVPASS force-delete "$tmp/restore"
260     WVPASS bup restore -C $tmp/restore /foo/latest/
261     for x in $tmp/src/*; do
262         WVPASS "$top/t/compare-trees" $x/ $tmp/restore/$(basename $x);
263     done
264
265     WVSTART "restore /foo/latest/."
266     WVPASS force-delete "$tmp/restore"
267     WVPASS bup restore -C $tmp/restore /foo/latest/.
268     WVPASS "$top/t/compare-trees" $tmp/src/ $tmp/restore/
269
270     WVSTART "restore /foo/latest/x"
271     WVPASS force-delete "$tmp/restore"
272     WVPASS bup restore -C $tmp/restore /foo/latest/x
273     WVPASS "$top/t/compare-trees" $tmp/src/x/ $tmp/restore/x/
274
275     WVSTART "restore /foo/latest/x/"
276     WVPASS force-delete "$tmp/restore"
277     WVPASS bup restore -C $tmp/restore /foo/latest/x/
278     for x in $tmp/src/x/*; do
279         WVPASS "$top/t/compare-trees" $x/ $tmp/restore/$(basename $x);
280     done
281
282     WVSTART "restore /foo/latest/x/."
283     WVPASS force-delete "$tmp/restore"
284     WVPASS bup restore -C $tmp/restore /foo/latest/x/.
285     WVPASS "$top/t/compare-trees" $tmp/src/x/ $tmp/restore/
286 ) || exit $?
287
288
289 WVSTART "ftp"
290 WVPASS bup ftp "cat /master/latest/$tmpdir/$D/b" >$D/b.new
291 WVPASS bup ftp "cat /master/latest/$tmpdir/$D/f" >$D/f.new
292 WVPASS bup ftp "cat /master/latest/$tmpdir/$D/f"{,} >$D/f2.new
293 WVPASS bup ftp "cat /master/latest/$tmpdir/$D/a" >$D/a.new
294 WVPASSEQ "$(sha1sum <$D/b)" "$(sha1sum <$D/b.new)"
295 WVPASSEQ "$(sha1sum <$D/f)" "$(sha1sum <$D/f.new)"
296 WVPASSEQ "$(cat $D/f.new{,} | sha1sum)" "$(sha1sum <$D/f2.new)"
297 WVPASSEQ "$(sha1sum <$D/a)" "$(sha1sum <$D/a.new)"
298
299 WVSTART "tag"
300 WVFAIL bup tag -d v0.n 2>/dev/null
301 WVFAIL bup tag v0.n non-existant 2>/dev/null
302 WVPASSEQ "$(bup tag)" ""
303 WVPASS bup tag v0.1 master
304 WVPASSEQ "$(bup tag)" "v0.1"
305 WVFAIL bup tag v0.1 master
306 WVPASS bup tag -f v0.1 master
307 WVPASS bup tag -d v0.1
308 WVPASS bup tag -f -d v0.1
309 WVFAIL bup tag -d v0.1
310
311
312 WVSTART "save (no index)"
313 (
314     tmp=save-no-index.tmp
315     WVPASS force-delete $tmp
316     WVPASS mkdir $tmp
317     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
318     WVPASS bup init
319     WVFAIL bup save -n nothing /
320     WVPASS rm -r "$tmp"
321 ) || exit $?
322
323 WVSTART "indexfile"
324 D=indexfile.tmp
325 INDEXFILE=tmpindexfile.tmp
326 WVPASS rm -f $INDEXFILE
327 WVPASS force-delete $D
328 WVPASS mkdir $D
329 export BUP_DIR="$D/.bup"
330 WVPASS bup init
331 WVPASS touch $D/a
332 WVPASS touch $D/b
333 WVPASS mkdir $D/c
334 WVPASS bup index -ux $D
335 WVPASS bup save --strip -n bupdir $D
336 WVPASSEQ "$(bup ls -F bupdir/latest/)" "a
337 b
338 c/"
339 WVPASS bup index -f $INDEXFILE --exclude=$D/c -ux $D
340 WVPASS bup save --strip -n indexfile -f $INDEXFILE $D
341 WVPASSEQ "$(bup ls indexfile/latest/)" "a
342 b"
343
344
345 WVSTART "import-rsnapshot"
346 D=rsnapshot.tmp
347 export BUP_DIR="$tmpdir/$D/.bup"
348 WVPASS force-delete $D
349 WVPASS mkdir $D
350 WVPASS bup init
351 WVPASS mkdir -p $D/hourly.0/buptest/a
352 WVPASS touch $D/hourly.0/buptest/a/b
353 WVPASS mkdir -p $D/hourly.0/buptest/c/d
354 WVPASS touch $D/hourly.0/buptest/c/d/e
355 WVPASS true
356 WVPASS bup import-rsnapshot $D/
357 WVPASSEQ "$(bup ls -F buptest/latest/)" "a/
358 c/"
359
360
361 WVSTART "save disjoint top-level directories"
362 (
363     # Resolve any symlinks involving the top top-level dirs.
364     real_pwd="$(WVPASS realpath .)" || exit $?
365     real_tmp="$(WVPASS realpath /tmp/.)" || exit $?
366     pwd_top="$(echo $real_pwd | WVPASS awk -F "/" '{print $2}')" || exit $?
367     tmp_top="$(echo $real_tmp | WVPASS awk -F "/" '{print $2}')" || exit $?
368
369     if [ "$pwd_top" = "$tmp_top" ]; then
370         echo "(running from within /$tmp_top; skipping test)" 1>&2
371         exit 0
372     fi
373     D=bupdata.tmp
374     WVPASS force-delete $D
375     WVPASS mkdir -p $D/x
376     WVPASS date > $D/x/1
377     tmpdir2="$(WVPASS mktemp -d $real_tmp/bup-test-XXXXXXX)" || exit $?
378     cleanup() { WVPASS rm -r "$tmpdir2"; }
379     WVPASS trap cleanup EXIT
380     WVPASS date > "$tmpdir2/2"
381
382     export BUP_DIR="$tmpdir/bup"
383     WVPASS test -d "$BUP_DIR" && WVPASS rm -r "$BUP_DIR"
384
385     WVPASS bup init
386     WVPASS bup index -vu $(pwd)/$D/x "$tmpdir2"
387     WVPASS bup save -t -n src $(pwd)/$D/x "$tmpdir2"
388
389     # For now, assume that "ls -a" and "sort" use the same order.
390     actual="$(WVPASS bup ls -AF src/latest)" || exit $?
391     expected="$(echo -e "$pwd_top/\n$tmp_top/" | WVPASS sort)" || exit $?
392     WVPASSEQ "$actual" "$expected"
393 ) || exit $?
394
395 WVPASS rm -rf "$tmpdir"