]> pd.if.org Git - zpackage/commitdiff
fixup tests
authorNathan Wagner <nw@hydaspes.if.org>
Mon, 19 Sep 2016 02:58:29 +0000 (02:58 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Mon, 19 Sep 2016 02:58:29 +0000 (02:58 +0000)
Makefile
t/addfile.t [new file with mode: 0755]

index 18991523314f7e752ab8dec0dc4b197669b19825..ff9f4c94eccdc6473a7a65e15e58e542a813c13a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-CFLAGS=-Wall -std=c99 -I. -Ilzma/api -Ilzma/tuklib -Ilzma/lzma -Ilzma/common -Ilzma/check -Ilzma/lz -Ilzma/rangecoder -Ilzma/simple -Ilzma/delta -DHAVE_CHECK_CRC64 -DHAVE_CHECK_CRC32 -DHAVE_ENCODER_LZMA2 -DHAVE_DECODER_LZMA2 -DHAVE_MF_BT4
+CFLAGS=-Wall -std=c99 -I. -Ilzma/api -Ilzma/tuklib -Ilzma/lzma -Ilzma/common -Ilzma/check -Ilzma/lz -Ilzma/rangecoder -Ilzma/simple -Ilzma/delta -DHAVE_CHECK_CRC64 -DHAVE_CHECK_CRC32 -DHAVE_ENCODER_LZMA2 -DHAVE_DECODER_LZMA2 -DHAVE_MF_BT4 -D_POSIX_C_SOURCE=1
 LDFLAGS=-L.
 
 LZMACHECKSRC=lzma/check/check.c lzma/check/crc32_fast.c lzma/check/crc64_fast.c lzma/check/crc32_table.c lzma/check/crc64_table.c
@@ -9,6 +9,8 @@ def: libzpm.a
 d:
        printf '%s\n' $(LZMAOBJ)
 
+test: zpm-addfile
+       prove -e'' t/*.t
 
 programs: elftype soname zpm-addfile zpm-extract
 
@@ -53,4 +55,4 @@ install: elftype
        #SPOOL=$(DESTDIR)/var/lib/admin/notes ./zpm-sequence -c notes
 
 clean:
-       rm -f *.o lib/*.o $(LZMAOBJ) liblzma.a
+       rm -f *.o lib/*.o $(LZMAOBJ) liblzma.a zpm-addfile
diff --git a/t/addfile.t b/t/addfile.t
new file mode 100755 (executable)
index 0000000..fbfa70e
--- /dev/null
@@ -0,0 +1,84 @@
+#!/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.empty
+touch test.empty
+
+hash=$(./zpm-addfile $PF test.empty 2>> test.out)
+okexit add empty file content
+okstreq $hash e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 hash contents
+
+appid=$(sqlite3 test.db 'pragma application_id')
+okstreq $appid 1515209794 application id set
+
+userv=$(sqlite3 test.db 'pragma user_version')
+okstreq $userv 1 db version set
+
+finish
+
+#rm -f $PF test.empty