]> arthur.barton.de Git - bup.git/blob - t/test.sh
1dca9f10a36ef7008c4a021b360a6cb0125a49ee
[bup.git] / t / test.sh
1 #!/usr/bin/env bash
2 . wvtest.sh
3 #set -e
4
5 TOP="$(pwd)"
6 export BUP_DIR="$TOP/buptest.tmp"
7
8 bup()
9 {
10     "$TOP/bup" "$@"
11 }
12
13 WVSTART "init"
14
15 #set -x
16 rm -rf "$BUP_DIR"
17 WVPASS bup init
18
19 WVSTART "index"
20 D=bupdata.tmp
21 rm -rf $D
22 mkdir $D
23 WVPASSEQ "$(bup index --check -p)" ""
24 WVPASSEQ "$(bup index --check -p $D)" ""
25 WVFAIL [ -e $D.fake ]
26 WVFAIL bup index --check -u $D.fake
27 WVPASS bup index --check -u $D
28 WVPASSEQ "$(bup index --check -p $D)" "$D/"
29 touch $D/a
30 bup random 128k >$D/b
31 mkdir $D/d $D/d/e
32 bup random 512 >$D/f
33 WVPASSEQ "$(bup index -s $D/)" "A $D/"
34 WVPASSEQ "$(bup index -s $D/b)" ""
35 WVPASSEQ "$(bup index --check -us $D/b)" "A $D/b"
36 WVPASSEQ "$(bup index --check -us $D/b $D/d)" \
37 "A $D/d/e/
38 A $D/d/
39 A $D/b"
40 touch $D/d/z
41 bup tick
42 WVPASSEQ "$(bup index --check -usx $D)" \
43 "A $D/f
44 A $D/d/z
45 A $D/d/e/
46 A $D/d/
47 A $D/b
48 A $D/a
49 A $D/"
50 WVPASSEQ "$(bup index --check -us $D/a $D/b --fake-valid)" \
51 "  $D/b
52   $D/a"
53 WVPASSEQ "$(bup index --check -us $D/a)" "  $D/a"  # stays unmodified
54 WVPASSEQ "$(bup index --check -us $D/d --fake-valid)" \
55 "  $D/d/z
56   $D/d/e/
57   $D/d/"
58 touch $D/d/z
59 WVPASS bup index -u $D/d/z  # becomes modified
60 WVPASSEQ "$(bup index -s $D/a $D $D/b)" \
61 "A $D/f
62 M $D/d/z
63   $D/d/e/
64 M $D/d/
65   $D/b
66   $D/a
67 A $D/"
68
69 WVPASS bup index -u $D/d/e $D/a --fake-invalid
70 WVPASSEQ "$(cd $D && bup index -m .)" \
71 "./f
72 ./d/z
73 ./d/e/
74 ./d/
75 ./a
76 ./"
77 WVPASSEQ "$(cd $D && bup index -m)" \
78 "f
79 d/z
80 d/e/
81 d/
82 a
83 ./"
84 WVPASSEQ "$(cd $D && bup index -s .)" "$(cd $D && bup index -s .)"
85
86 WVFAIL bup save -t $D/doesnt-exist-filename
87
88 mv $BUP_DIR/bupindex $BUP_DIR/bi.old
89 WVFAIL bup save -t $D/d/e/fifotest
90 mkfifo $D/d/e/fifotest
91 WVPASS bup index -u $D/d/e/fifotest
92 WVFAIL bup save -t $D/d/e/fifotest
93 WVFAIL bup save -t $D/d/e
94 rm -f $D/d/e/fifotest
95 WVPASS bup index -u $D/d/e
96 WVFAIL bup save -t $D/d/e/fifotest
97 mv $BUP_DIR/bi.old $BUP_DIR/bupindex
98
99 WVPASS bup index -u $D/d/e
100 WVPASS bup save -t $D/d/e
101 WVPASSEQ "$(cd $D && bup index -m)" \
102 "f
103 d/z
104 d/
105 a
106 ./"
107 WVPASS bup save -t $D/d
108 WVPASSEQ "$(cd $D && bup index -m)" \
109 "f
110 a
111 ./"
112 tree1=$(bup save -t $D)
113 WVPASSEQ "$(cd $D && bup index -m)" ""
114 tree2=$(bup save -t $D)
115 WVPASSEQ "$tree1" "$tree2"
116 WVPASSEQ "$(bup index -s / | grep ^D)" ""
117 tree3=$(bup save -t /)
118 WVPASSEQ "$tree1" "$tree3"
119
120 WVSTART "split"
121 WVPASS bup split --bench -b <t/testfile1 >tags1.tmp
122 WVPASS bup split -vvvv -b t/testfile2 >tags2.tmp
123 WVPASS bup margin
124 WVPASS bup midx -f
125 WVPASS bup margin
126 WVPASS bup split -t t/testfile2 >tags2t.tmp
127 WVPASS bup split -t t/testfile2 --fanout 3 >tags2tf.tmp
128 WVPASS bup split -r "$BUP_DIR" -c t/testfile2 >tags2c.tmp
129 WVPASS ls -lR \
130    | WVPASS bup split -r "$BUP_DIR" -c --fanout 3 --max-pack-objects 3 -n lslr
131 WVPASS bup ls
132 WVFAIL bup ls /does-not-exist
133 WVPASS bup ls /lslr
134 #WVPASS bup ls /lslr/1971-01-01   # all dates always exist
135 WVFAIL diff -u tags1.tmp tags2.tmp
136
137 # fanout must be different from non-fanout
138 WVFAIL diff -q tags2t.tmp tags2tf.tmp
139 wc -c t/testfile1 t/testfile2
140 wc -l tags1.tmp tags2.tmp
141
142 WVSTART "join"
143 WVPASS bup join $(cat tags1.tmp) >out1.tmp
144 WVPASS bup join <tags2.tmp >out2.tmp
145 WVPASS bup join <tags2t.tmp >out2t.tmp
146 WVPASS bup join -r "$BUP_DIR" <tags2c.tmp >out2c.tmp
147 WVPASS diff -u t/testfile1 out1.tmp
148 WVPASS diff -u t/testfile2 out2.tmp
149 WVPASS diff -u t/testfile2 out2t.tmp
150 WVPASS diff -u t/testfile2 out2c.tmp
151
152 WVSTART "save/git-fsck"
153 (
154     set -e
155     cd "$BUP_DIR" || exit 1
156     #git repack -Ad
157     #git prune
158     (cd "$TOP/t/sampledata" && WVPASS bup save -vvn master /) || WVFAIL
159     n=$(git fsck --full --strict 2>&1 | 
160           egrep -v 'dangling (commit|tree)' |
161           tee -a /dev/stderr | 
162           wc -l)
163     WVPASS [ "$n" -eq 0 ]
164 ) || exit 1
165
166 WVSTART "ftp"
167 WVPASS bup ftp "cat /master/latest/$TOP/$D/b" >$D/b.new
168 WVPASS bup ftp "cat /master/latest/$TOP/$D/f" >$D/f.new
169 WVPASS bup ftp "cat /master/latest/$TOP/$D/f"{,} >$D/f2.new
170 WVPASS bup ftp "cat /master/latest/$TOP/$D/a" >$D/a.new
171 WVPASSEQ "$(sha1sum <$D/b)" "$(sha1sum <$D/b.new)"
172 WVPASSEQ "$(sha1sum <$D/f)" "$(sha1sum <$D/f.new)"
173 WVPASSEQ "$(cat $D/f.new{,} | sha1sum)" "$(sha1sum <$D/f2.new)"
174 WVPASSEQ "$(sha1sum <$D/a)" "$(sha1sum <$D/a.new)"
175
176 WVSTART "fsck"
177 WVPASS bup fsck
178 WVPASS bup fsck --quick
179 if bup fsck --par2-ok; then
180     WVSTART "fsck (par2)"
181 else
182     WVSTART "fsck (PAR2 IS MISSING)"
183 fi
184 WVPASS bup fsck -g
185 WVPASS bup fsck -r
186 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1 -S0
187 WVFAIL bup fsck --quick
188 WVFAIL bup fsck --quick --disable-par2
189 chmod u+w $BUP_DIR/objects/pack/*.idx
190 WVPASS bup damage $BUP_DIR/objects/pack/*.idx -n10 -s1 -S0
191 WVFAIL bup fsck --quick -j4
192 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1024 --percent 0.4 -S0
193 WVFAIL bup fsck --quick
194 WVFAIL bup fsck --quick -rvv -j99   # fails because repairs were needed
195 if bup fsck --par2-ok; then
196     WVPASS bup fsck -r # ok because of repairs from last time
197     WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n202 -s1 --equal -S0
198     WVFAIL bup fsck
199     WVFAIL bup fsck -rvv   # too many errors to be repairable
200     WVFAIL bup fsck -r   # too many errors to be repairable
201 else
202     WVFAIL bup fsck --quick -r # still fails because par2 was missing
203 fi