]> arthur.barton.de Git - bup.git/commitdiff
Start using wvtest.sh for shell-based tests in test-sh.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 10 Jan 2010 01:35:16 +0000 (20:35 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 10 Jan 2010 01:36:07 +0000 (20:36 -0500)
This makes the output a little prettier... at least in the common case where
it passes :)

Makefile
cmd-join.py
git.py
t/test.sh [new file with mode: 0755]
test-sh [deleted file]
wvtest.sh [new file with mode: 0644]

index 52679c8d0f319339903b71ced713f7340f0dc1a3..3209e8a98a8334ef4d9084f5aea2e6724ca88b6b 100644 (file)
--- 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
index b87319a74027ff1ebc841f288112f14b715cb41f..537862959474febbbb6e395c9f9d259b3a1d8aca 100755 (executable)
@@ -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 ccafa5c8b7e8eedd6e842d51cd70e78385386dfe..6775bb2876a7d8c10d98b65027db432a4438fe77 100644 (file)
--- 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 (executable)
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 <testfile1 >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 <tags2.tmp >out2.tmp
+WVPASS bup join <tags2t.tmp >out2t.tmp
+WVPASS bup join -r "$BUP_DIR" <tags2c.tmp >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 (executable)
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 <testfile1 >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 <tags2.tmp >out2.tmp
-bup join <tags2t.tmp >out2t.tmp
-bup join -r "$BUP_DIR" <tags2c.tmp >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 (file)
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
+}