From: Avery Pennarun Date: Sun, 10 Jan 2010 01:35:16 +0000 (-0500) Subject: Start using wvtest.sh for shell-based tests in test-sh. X-Git-Tag: bup-0.04~1^2~4 X-Git-Url: https://arthur.barton.de/gitweb/?p=bup.git;a=commitdiff_plain;h=7f45493d9b35ea16cb7514e2a39ece16354e4449 Start using wvtest.sh for shell-based tests in test-sh. This makes the output a little prettier... at least in the common case where it passes :) --- diff --git a/Makefile b/Makefile index 52679c8..3209e8a 100644 --- a/Makefile +++ b/Makefile @@ -21,16 +21,18 @@ randomgen: randomgen.o chashsplit.so: chashsplitmodule.o $(CC) $(CFLAGS) $(SHARED) -o $@ $< $(PYLIB) -runtests: all +runtests: all runtests-python runtests-cmdline + +runtests-python: ./wvtest.py $(wildcard t/t*.py) runtests-cmdline: all - ./test-sh + t/test.sh stupid: PATH=/bin:/usr/bin $(MAKE) test -test: all runtests-cmdline +test: all ./wvtestrun $(MAKE) runtests %: %.o diff --git a/cmd-join.py b/cmd-join.py index b87319a..5378629 100755 --- a/cmd-join.py +++ b/cmd-join.py @@ -26,5 +26,6 @@ if opt.remote: cli.close() else: for id in extra: + #log('id=%r\n' % id) for blob in git.cat(id): sys.stdout.write(blob) diff --git a/git.py b/git.py index ccafa5c..6775bb2 100644 --- a/git.py +++ b/git.py @@ -398,9 +398,11 @@ class CatPipe: assert(id[0] != '-') self.p.stdin.write('%s\n' % id) hdr = self.p.stdout.readline() + if hdr.endswith(' missing\n'): + raise GitError('blob %r is missing' % id) spl = hdr.split(' ') - assert(len(spl) == 3) - assert(len(spl[0]) == 40) + if len(spl) != 3 or len(spl[0]) != 40: + raise GitError('expected blob, got %r' % spl) (hex, type, size) = spl yield type for blob in chunkyreader(self.p.stdout, int(spl[2])): @@ -437,7 +439,8 @@ class CatPipe: for blob in self.join(treeline[5:]): yield blob else: - raise GitError('unknown object type %r' % type) + raise GitError('invalid object type %r: expected blob/tree/commit' + % type) def join(self, id): for d in self._join(self.get(id)): diff --git a/t/test.sh b/t/test.sh new file mode 100755 index 0000000..e40ada1 --- /dev/null +++ b/t/test.sh @@ -0,0 +1,57 @@ +#!/bin/bash +. wvtest.sh +#set -e + +TOP="$(pwd)" +export BUP_DIR="$TOP/buptest.tmp" + +bup() +{ + "$TOP/bup" "$@" +} + +WVSTART "init" + +#set -x +rm -rf "$BUP_DIR" +WVPASS bup init + +WVSTART "split" + +WVPASS bup split --bench -b tags1.tmp +WVPASS bup split -vvvv -b testfile2 >tags2.tmp +WVPASS bup split -t testfile2 >tags2t.tmp +WVPASS bup split -t testfile2 --fanout 3 >tags2tf.tmp +WVPASS bup split -r "$BUP_DIR" -c testfile2 >tags2c.tmp +WVPASS ls -lR \ + | WVPASS bup split -r "$BUP_DIR" -c --fanout 3 --max-pack-objects 3 -n lslr +WVFAIL diff -u tags1.tmp tags2.tmp + +# fanout must be different from non-fanout +WVFAIL diff -q tags2t.tmp tags2tf.tmp +wc -c testfile1 testfile2 +wc -l tags1.tmp tags2.tmp + +WVSTART "join" +WVPASS bup join $(cat tags1.tmp) >out1.tmp +WVPASS bup join out2.tmp +WVPASS bup join out2t.tmp +WVPASS bup join -r "$BUP_DIR" out2c.tmp +WVPASS diff -u testfile1 out1.tmp +WVPASS diff -u testfile2 out2.tmp +WVPASS diff -u testfile2 out2t.tmp +WVPASS diff -u testfile2 out2c.tmp + +WVSTART "save/fsck" +( + set -e + cd "$BUP_DIR" || exit 1 + #git repack -Ad + #git prune + (cd "$TOP/t/sampledata" && WVPASS bup save -vvn master .) || WVFAIL + n=$(git fsck --full --strict 2>&1 | + egrep -v 'dangling (commit|tree)' | + tee -a /dev/stderr | + wc -l) + WVPASS [ "$n" -eq 0 ] +) || exit 1 diff --git a/test-sh b/test-sh deleted file mode 100755 index f48be99..0000000 --- a/test-sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash -set -e -echo "Testing \"integration\" in $0:" - -TOP="$(pwd)" -export BUP_DIR="$TOP/buptest.tmp" - -bup() -{ - "$TOP/bup" "$@" -} - -set -x -rm -rf "$BUP_DIR" -bup init -bup split --bench -b tags1.tmp -bup split -vvvv -b testfile2 >tags2.tmp -bup split -t testfile2 >tags2t.tmp -bup split -t testfile2 --fanout 3 >tags2tf.tmp -bup split -r "$BUP_DIR" -c testfile2 >tags2c.tmp -ls -lR | bup split -r "$BUP_DIR" -c --fanout 3 --max-pack-objects 3 -n lslr -diff -u tags1.tmp tags2.tmp || true -if diff -q tags2t.tmp tags2tf.tmp; then - echo "fanout tree same as non-fanout tree!?" - false -fi -wc -c testfile1 testfile2 -wc -l tags1.tmp tags2.tmp -bup join $(cat tags1.tmp) >out1.tmp -bup join out2.tmp -bup join out2t.tmp -bup join -r "$BUP_DIR" out2c.tmp -diff -u testfile1 out1.tmp -diff -u testfile2 out2.tmp -diff -u testfile2 out2t.tmp -diff -u testfile2 out2c.tmp - -( - set -e - cd "$BUP_DIR" || exit 1 - #git repack -Ad - #git prune - (cd "$TOP/t/sampledata" && bup save -vvn master .) || exit 1 - n=$(git fsck --full --strict 2>&1 | - egrep -v 'dangling (commit|tree)' | - tee -a /dev/stderr | - wc -l) - if [ "$n" -ne 0 ]; then - echo "git fsck error." - exit 5 - fi -) || exit 1 diff --git a/wvtest.sh b/wvtest.sh new file mode 100644 index 0000000..0ed5fb0 --- /dev/null +++ b/wvtest.sh @@ -0,0 +1,69 @@ +WVIFS=" +" + +# we don't quote $TEXT in case it contains newlines; newlines +# aren't allowed in test output. However, we set -f so that +# at least shell glob characters aren't processed. +_textclean() +{ + ( set -f; echo $* ) +} + +_wvcheck() +{ + CODE="$1" + TEXT=$(_textclean "$2") + OK=ok + if [ "$CODE" -ne 0 ]; then + OK=FAILED + fi + echo "! ${BASH_SOURCE[2]}:${BASH_LINENO[1]} $TEXT $OK" >&2 + if [ "$CODE" -ne 0 ]; then + exit $CODE + else + return 0 + fi +} + + +WVPASS() +{ + #xIFS="$IFS" + #IFS="$WVIFS" + TEXT="$*" + #IFS="$xIFS" + + if "$@"; then + _wvcheck 0 "$TEXT" + return 0 + else + _wvcheck 1 "$TEXT" + # NOTREACHED + return 1 + fi +} + + +WVFAIL() +{ + #xIFS="$IFS" + #IFS="$WVIFS" + TEXT="$*" + #IFS="$xIFS" + + if "$@"; then + _wvcheck 1 "NOT($TEXT)" + # NOTREACHED + return 1 + else + _wvcheck 0 "NOT($TEXT)" + return 0 + fi +} + + +WVSTART() +{ + echo >&2 + echo "Testing \"$*\" in ${BASH_SOURCE[1]}:" >&2 +}