]> pd.if.org Git - zpackage/commitdiff
add bad file type tests to addfile test
authorNathan Wagner <nw@hydaspes.if.org>
Thu, 29 Sep 2016 00:23:44 +0000 (00:23 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Thu, 29 Sep 2016 00:23:44 +0000 (00:23 +0000)
t/addfile.t
t/extract.t
t/tap.sh

index fbfa70eb90bd70d39223d699d0659277c76b5e65..a2fe02f63388b0d8fc555624ecff4c5602ae2ef8 100755 (executable)
@@ -2,74 +2,16 @@
 
 # test addfile
 
-tn=0
-planned=0
+. tap.sh
 
-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
+plan 6
 
 PF=test.db
 
 rm -f $PF test.empty
 touch test.empty
 
-hash=$(./zpm-addfile $PF test.empty 2>> test.out)
+hash=$(zpm-addfile $PF test.empty 2>> test.out)
 okexit add empty file content
 okstreq $hash e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 hash contents
 
@@ -79,6 +21,14 @@ okstreq $appid 1515209794 application id set
 userv=$(sqlite3 test.db 'pragma user_version')
 okstreq $userv 1 db version set
 
+mkdir test.dir
+zpm-addfile $PF test.dir 2>>test.out
+failsok fail to add directory
+rmdir test.dir
+
+zpm-addfile $PF /dev/null 2>>test.out
+failsok fail to device file
+
 finish
 
-#rm -f $PF test.empty
+rm -f test.*
index b631006cc61702b3c6bbd93a6255cc100ffce1e2..17b2faa2da8a8f8797386a51621d48c9e7ed18be 100755 (executable)
@@ -2,65 +2,7 @@
 
 # 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
-}
+. tap.sh
 
 plan 4
 
@@ -69,7 +11,7 @@ PF=test.db
 rm -f $PF test.foo
 echo foo > test.foo
 
-hash=$(./zpm-addfile $PF test.foo 2>> test.out)
+hash=$(zpm-addfile $PF test.foo 2>> test.out)
 save=$?
 
 okexit add foo file content
@@ -77,12 +19,12 @@ okstreq $hash b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c f
 
 rm -f foo
 
-./zpm-extract $PF $hash foo
-okexit  extract foo file content
+zpm-extract $PF $hash test.foo2
+okexit extract foo file content
 
-sha=$(sha256sum foo)
+sha=$(zpm-hash test.foo2)
 okstreq $hash $sha extracted hash matches
 
 finish
 
-#rm -f $PF test.empty
+rm -f test.*
index 23c52997190d8f127cab8a8384f828d92bcf50f2..553128ffe01e9a55e5e58570acc07699f1dab1ea 100755 (executable)
--- a/t/tap.sh
+++ b/t/tap.sh
@@ -26,10 +26,11 @@ okexit() {
 }
 
 failsok() {
+       rv=$?
        note=
-       if [ $? -eq 0 ]; then
+       if [ $rv -eq 0 ]; then
                printf 'not ';
-               note=$(printf '# got "%d" expected "%d"' "$1" "0")
+               note=$(printf 'got "%d" expected "%d"' "$rv" "0")
        fi
        tn=$((tn + 1))
        printf 'ok %d - %s\n' $tn "$*"
@@ -37,8 +38,9 @@ failsok() {
 }
 
 exitwith() {
+       rv=$?
        note=
-       if [ $? -ne $1 ]; then
+       if [ $rv -ne $1 ]; then
                printf 'not ';
                note=$(printf '# got "%d" expected "%d"' "$1" "$2")
        fi