]> arthur.barton.de Git - bup.git/blob - test/ext/test-misc
test-misc: be independent of user's git defaultBranch
[bup.git] / test / ext / test-misc
1 #!/usr/bin/env bash
2 . wvtest.sh
3 . wvtest-bup.sh
4 . dev/lib.sh
5
6 set -o pipefail
7
8 top="$(WVPASS pwd)" || exit $?
9 tmpdir="$(WVPASS wvmktempdir)" || exit $?
10 export BUP_DIR="$tmpdir/bup"
11
12 bup() { "$top/bup" "$@"; }
13 sha1sum() { "$top/dev/checksum" -t sha1 "$@"; }
14
15 WVPASS cd "$tmpdir"
16
17 WVSTART "init"
18 WVPASS bup init
19 # Be independent of git defaults or a configured defaultBranch
20 git --git-dir "$BUP_DIR" symbolic-ref HEAD refs/heads/main
21 D=bupdata.tmp
22 WVPASS force-delete $D
23 WVPASS mkdir $D
24 WVPASS touch $D/a
25 WVPASS bup random 128k >$D/b
26 WVPASS mkdir $D/d $D/d/e
27 WVPASS bup random 512 >$D/f
28 WVPASS touch $D/d/z
29 WVPASS touch $D/d/z
30 WVPASS bup index $D
31 WVPASS bup save -t $D
32
33
34 WVSTART "bloom"
35 WVPASS bup bloom -c $(ls -1 "$BUP_DIR"/objects/pack/*.idx|head -n1)
36 WVPASS rm "$BUP_DIR"/objects/pack/bup.bloom
37 WVPASS bup bloom -k 4
38 WVPASS bup bloom -c $(ls -1 "$BUP_DIR"/objects/pack/*.idx|head -n1)
39 WVPASS bup bloom -d "$BUP_DIR"/objects/pack --ruin --force
40 WVFAIL bup bloom -c $(ls -1 "$BUP_DIR"/objects/pack/*.idx|head -n1)
41 WVPASS bup bloom --force -k 5
42 WVPASS bup bloom -c $(ls -1 "$BUP_DIR"/objects/pack/*.idx|head -n1)
43
44
45 WVSTART "memtest"
46 WVPASS bup memtest -c1 -n100
47 WVPASS bup memtest -c1 -n100 --existing
48
49
50 WVSTART "save/git-fsck"
51 (
52     WVPASS cd "$BUP_DIR"
53     #git repack -Ad
54     #git prune
55     WVPASS bup random 4k | WVPASS bup split -b
56     (WVPASS cd "$top/test/sampledata" && WVPASS bup save -vvn main /) || exit $?
57     result="$(LC_ALL=C git fsck --full --strict 2>&1)" || exit $?
58     n=$(echo "$result" |
59         WVFAIL egrep -v 'dangling (commit|tree|blob)' |
60         WVPASS tee -a /dev/stderr |
61         WVPASS wc -l) || exit $?
62     WVPASS [ "$n" -eq 0 ]
63 ) || exit $?
64
65
66 WVSTART "pack name and idx same as git"
67 (
68     # reuse packs from previous test
69     WVPASS cd "$BUP_DIR"/objects/pack/
70     WVPASS ls *.pack
71     for pack in *.pack ; do
72        bup_idx_sha=$(sha1sum $(basename $pack .pack).idx) || exit $?
73        gitname=$(git index-pack $pack) || exit $?
74        # make sure we named it correctly (like git)
75        WVPASSEQ pack-$gitname.pack $pack
76        # make sure we wrote the index correctly
77        git_idx_sha=$(sha1sum $(basename $pack .pack).idx) || exit $?
78        WVPASSEQ "$bup_idx_sha" "$git_idx_sha"
79     done
80 ) || exit $?
81
82
83 WVSTART "ftp"
84 WVPASS bup ftp "cat /main/latest/$tmpdir/$D/b" >$D/b.new
85 WVPASS bup ftp "cat /main/latest/$tmpdir/$D/f" >$D/f.new
86 WVPASS bup ftp "cat /main/latest/$tmpdir/$D/f"{,} >$D/f2.new
87 WVPASS bup ftp "cat /main/latest/$tmpdir/$D/a" >$D/a.new
88 WVPASSEQ "$(sha1sum <$D/b)" "$(sha1sum <$D/b.new)"
89 WVPASSEQ "$(sha1sum <$D/f)" "$(sha1sum <$D/f.new)"
90 WVPASSEQ "$(cat $D/f.new{,} | sha1sum)" "$(sha1sum <$D/f2.new)"
91 WVPASSEQ "$(sha1sum <$D/a)" "$(sha1sum <$D/a.new)"
92
93
94 WVSTART "tag"
95 WVFAIL bup tag -d v0.n 2>/dev/null
96 WVFAIL bup tag v0.n non-existant 2>/dev/null
97 WVPASSEQ "$(bup tag)" ""
98 WVPASS bup tag v0.1 main
99 WVPASSEQ "$(bup tag)" "v0.1"
100 WVFAIL bup tag v0.1 main
101 WVPASS bup tag -f v0.1 main
102 WVPASS bup tag -d v0.1
103 WVPASS bup tag -f -d v0.1
104 WVFAIL bup tag -d v0.1
105
106
107 WVSTART "indexfile"
108 D=indexfile.tmp
109 INDEXFILE=tmpindexfile.tmp
110 WVPASS rm -f $INDEXFILE
111 WVPASS force-delete $D
112 WVPASS mkdir $D
113 export BUP_DIR="$D/.bup"
114 WVPASS bup init
115 WVPASS touch $D/a
116 WVPASS touch $D/b
117 WVPASS mkdir $D/c
118 WVPASS bup index -ux $D
119 WVPASS bup save --strip -n bupdir $D
120 WVPASSEQ "$(bup ls -F bupdir/latest/)" "a
121 b
122 c/"
123 WVPASS bup index -f $INDEXFILE --exclude=$D/c -ux $D
124 WVPASS bup save --strip -n indexfile -f $INDEXFILE $D
125 WVPASSEQ "$(bup ls indexfile/latest/)" "a
126 b"
127
128
129 WVSTART "import-rsnapshot"
130 D=rsnapshot.tmp
131 export BUP_DIR="$tmpdir/$D/.bup"
132 WVPASS force-delete $D
133 WVPASS mkdir $D
134 WVPASS bup init
135 WVPASS mkdir -p $D/hourly.0/buptest/a
136 WVPASS touch $D/hourly.0/buptest/a/b
137 WVPASS mkdir -p $D/hourly.0/buptest/c/d
138 WVPASS touch $D/hourly.0/buptest/c/d/e
139 WVPASS true
140 WVPASS bup import-rsnapshot $D/
141 WVPASSEQ "$(bup ls -F buptest/latest/)" "a/
142 c/"
143
144
145 WVSTART features
146 expect_py_ver=$(LC_CTYPE=C "$top/dev/python" \
147                         -c 'import platform; print(platform.python_version())') \
148     || exit $?
149 actual_py_ver=$(bup features | grep Python: | sed -Ee 's/ +Python: //') || exit $?
150 WVPASSEQ "$expect_py_ver" "$actual_py_ver"
151
152
153 WVSTART id-other-than
154 result=$("$top/dev/id-other-than" --user 0) ||  exit $?
155 WVPASS echo "$result" | WVPASS grep -qE '.*:[0-9]+$'
156 result=$("$top/dev/id-other-than" --group 0) ||  exit $?
157 WVPASS echo "$result" | WVPASS grep -qE '.*:[0-9]+$'
158
159
160 WVPASS rm -rf "$tmpdir"