]> pd.if.org Git - zpackage/commitdiff
add extract test file
authorNathan Wagner <nw@hydaspes.if.org>
Sun, 25 Sep 2016 08:38:56 +0000 (03:38 -0500)
committerNathan Wagner <nw@hydaspes.if.org>
Sun, 25 Sep 2016 08:38:56 +0000 (03:38 -0500)
Makefile
t/extract.t [new file with mode: 0755]

index 7ed73d374298dddfeeafdddd2cce7c4efcb726a0..26e1a176f19cfc380b76b45f072b04a7c583de2c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,8 +14,9 @@ lzma.c: mklzma
 
 lzma.o: lzma.c
        gcc -std=c99 -Wall -c -o $@ $<
-test: zpm-addfile
-       prove -e'' t/*.t
+
+test: zpm-addfile zpm-extract
+       prove -e '' t/*.t
 
 programs: elftype soname zpm-addfile zpm-extract
 
diff --git a/t/extract.t b/t/extract.t
new file mode 100755 (executable)
index 0000000..b631006
--- /dev/null
@@ -0,0 +1,88 @@
+#!/bin/sh
+
+# test addfile
+
+tn=0
+planned=0
+
+shownote() {
+       if [ "$note" != "" ]; then
+               printf '# %s\n' "$note"
+       fi
+}
+
+okexit() {
+       exitwith 0 "$*"
+}
+
+failsok() {
+       note=
+       if [ $? -eq 0 ]; then
+               printf 'not ';
+               note=$(printf '# got "%d" expected "%d"' "$1" "0")
+       fi
+       tn=$((tn + 1))
+       printf 'ok %d - %s\n' $tn "$*"
+       shownote
+}
+
+exitwith() {
+       note=
+       if [ $? -ne $1 ]; then
+               printf 'not ';
+               note=$(printf '# got "%d" expected "%d"' "$1" "$2")
+       fi
+       shift
+       tn=$((tn + 1))
+       printf 'ok %d - %s\n' $tn "$*"
+       shownote
+}
+
+okstreq() {
+       note=
+       if [ "$1" != "$2" ]; then
+               printf 'not ';
+               note=$(printf 'got "%s" expected "%s"' "$1" "$2")
+       fi
+
+       shift;shift;
+       tn=$((tn + 1))
+       printf 'ok %d - %s\n' $tn "$*"
+       shownote
+}
+
+plan() {
+       planned=$1
+       printf '1..%d\n' $planned
+}
+
+finish() {
+       if [ $planned -eq 0 ]; then
+               printf '1..%d\n' $tn
+       fi
+}
+
+plan 4
+
+PF=test.db
+
+rm -f $PF test.foo
+echo foo > test.foo
+
+hash=$(./zpm-addfile $PF test.foo 2>> test.out)
+save=$?
+
+okexit add foo file content
+okstreq $hash b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c foo hash contents
+
+rm -f foo
+
+./zpm-extract $PF $hash foo
+okexit  extract foo file content
+
+sha=$(sha256sum foo)
+okstreq $hash $sha extracted hash matches
+
+finish
+
+#rm -f $PF test.empty