move from unittest perl tp shell script, more portable and easier to understand

This commit is contained in:
Thomas von Dein
2016-10-25 16:33:12 +02:00
parent 0b1e843ee8
commit 2cb91c93e0
7 changed files with 779 additions and 570 deletions

View File

@@ -94,17 +94,17 @@ test: check ctest $(MAYPY) $(MAYCPP) $(MAYJSON)
ctest:
rm -f test* v* stresstest/*
./unittests.pl unittests.cfg $(CHECK)
./unittests.sh unittests.cfg $(CHECK)
@echo "To run a single test only, type: 'make test CHECK=testname'"
pytest:
./unittests.pl pyunittests.cfg $(CHECK)
./unittests.sh pyunittests.cfg $(CHECK)
docpptest:
./unittests.pl cppunittests.cfg $(CHECK)
./unittests.sh cppunittests.cfg $(CHECK)
jsontest:
./unittests.pl jsonunittests.cfg $(CHECK)
./unittests.sh jsonunittests.cfg $(CHECK)
stresstest: check
./unittests.pl stresstests.cfg

View File

@@ -1,26 +1,37 @@
# -*-sh-*-
#
# test the c++ api
<test check-cpp-crypto>
cmd = ./cpptest 0
expect = /ok/
</test>
<test check-cpp-vault>
cmd = ./cpptest 1
expect = /ok/
</test>
check-cpp-crypto () {
cmd="./cpptest 0"
expect=/ok/
check "$cmd" "$expect" "$input"
}
<test check-cpp-import-pub>
cmd = ./cpptest 2
expect = /ok/
</test>
check-cpp-vault () {
cmd="./cpptest 1"
expect=/ok/
check "$cmd" "$expect" "$input"
}
<test check-cpp-signature>
cmd = ./cpptest 3
expect = /ok/
</test>
check-cpp-import-pub () {
cmd="./cpptest 2"
expect=/ok/
check "$cmd" "$expect" "$input"
}
<test check-buffer>
cmd = ./cpptest 4
expect = /ok/
</test>
check-cpp-signature () {
cmd="./cpptest 3"
expect=/ok/
check "$cmd" "$expect" "$input"
}
check-buffer () {
cmd="./cpptest 4"
expect=/ok/
check "$cmd" "$expect" "$input"
}
prepare () {
:
}

View File

@@ -43,12 +43,12 @@ $pcp1 -V unknown3 -l
echo hallo | $pcp -e -x a -z | egrep -v "^ " | egrep -v -- "----" | grep . > unknown4
echo blah | $pcp -V vxxxBart -g -x a | egrep -v "^ " | egrep -v -- "----" | grep . > unknown5
echo "bartid = $ids
bartserial = $ser
idbobby = $idb
idalicia = $ida
mailbobby = bobby@local
mailalicia = alicia@local" > keys.cfg
echo "bartid=$ids
bartserial=$ser
idbobby=$idb
idalicia=$ida
mailbobby=bobby@local
mailalicia=alicia@local" > keys.cfg
./gencheader > static.h

View File

@@ -1,4 +1,4 @@
# -*-html-*-
# -*-sh-*-
#
# This file is part of Pretty Curved Privacy (pcp1).
#
@@ -20,66 +20,81 @@
# You can contact me by mail: <tlinden AT cpan DOT org>.
#
pcp = ../src/pcp1
passwd = xxx
verbose = 1
include keys.cfg
pcp=../src/pcp1
passwd=xxx
verbose=1
<test vja>
prepare = rm -f vja; $pcp -V vja -K -I key-alicia-sec -x a
<test check-json-export-public>
cmd = $pcp -V vja -p -j -x a -O testkeyvjapub.json
expect-file testkeyvjapub.json
</test>
<test check-json-export-public-isjson>
cmd = cat testkeyvjapub.json
expect = /"Alicia"/
</test>
<test check-json-export-secret>
cmd = $pcp -V vja -s -j -x a -O testkeyvjasec.json
expect-file testkeyvjasec.json
</test>
<test check-json-export-secret-isjson>
cmd = cat testkeyvjasec.json
expect = /"Alicia"/
</test>
</test>
. keys.cfg
<test vjb>
prepare = rm -f vjb; $pcp -V vjb -K -I key-bobby-sec -x b
<test check-json-import-public>
cmd = $pcp -V vjb -K -I testkeyvjapub.json -j
expect /added/
</test>
<test check-json-import-public-open>
cmd = $pcp -V vjb -l
expect = /Alicia/
</test>
</test>
check-json-support () {
cmd="$pcp -V vja -t -j"
expect="\"keyvaultfile\""
check "$cmd" "$expect"
}
<test vjc>
prepare = rm -f vjc
<test check-json-import-secret>
cmd = $pcp -V vjc -K -I testkeyvjasec.json -x a -j
expect = /added/
</test>
<test check-json-import-secret-open>
cmd = $pcp -V vjc -l
expect = /Alicia/
</test>
</test>
check-json-export-public () {
cmd="$pcp -V vja -p -j -x a -O testkeyvjapub.json"
expectfile="testkeyvjapub.json"
expect="/\"Alicia\"/"
check "$cmd" "$expect" "$input" "$expectfile"
}
<test vjtxt>
<test check-json-text-vault>
cmd = $pcp -V vjb -t -j
expect = /"Alicia"/
</test>
<test check-json-text-public>
cmd = $pcp -V vjb -t -j -i ${idalicia}
expect = /"Alicia"/
</test>
<test check-json-text-secret>
cmd = $pcp -V vjb -t -j -i ${idbobby}
expect = /"Bobby"/
</test>
</test>
check-json-export-secret () {
cmd="$pcp -V vja -s -j -x a -O testkeyvjasec.json"
expectfile="testkeyvjasec.json"
check "$cmd" "$expect" "$input" "$expectfile"
}
check-json-export-secret-isjson () {
cmd="cat testkeyvjasec.json"
expect="/\"Alicia\"/"
check "$cmd" "$expect" "$input" "$expectfile"
}
check-json-import-public () {
cmd="$pcp -V vjb -K -I testkeyvjapub.json -j"
expect="/added/"
check "$cmd" "$expect" "$input" "$expectfile"
}
check-json-import-public-open () {
cmd="$pcp -V vjb -l"
expect="/Alicia/"
check "$cmd" "$expect" "$input" "$expectfile"
}
check-json-import-secret () {
cmd="$pcp -V vjc -K -I testkeyvjasec.json -x a -j"
expect="/added/"
check "$cmd" "$expect" "$input" "$expectfile"
}
check-json-import-secret-open () {
cmd="$pcp -V vjc -l"
expect="/Alicia/"
check "$cmd" "$expect" "$input" "$expectfile"
}
check-json-text-vault () {
cmd="$pcp -V vjb -t -j"
expect="/\"Alicia\"/"
check "$cmd" "$expect" "$input" "$expectfile"
}
check-json-text-public () {
cmd="$pcp -V vjb -t -j -i ${idalicia}"
expect="/\"Alicia\"/"
check "$cmd" "$expect" "$input" "$expectfile"
}
check-json-text-secret () {
cmd="$pcp -V vjb -t -j -i ${idbobby}"
expect="/\"Bobby\"/"
check "$cmd" "$expect" "$input" "$expectfile"
}
prepare () {
rm -f vja; $pcp -V vja -K -I key-alicia-sec -x a
rm -f vjb; $pcp -V vjb -K -I key-bobby-sec -x b
rm -f vjc
}

View File

@@ -1,3 +1,4 @@
# -*-sh-*-
#
# This file is part of Pretty Curved Privacy (pcp1).
#
@@ -19,40 +20,49 @@
# You can contact me by mail: <tlinden AT cpan DOT org>.
#
py = ./pytest.py
py=./pytest.py
<test py-import-keys>
cmd = $py impkeys
expect = /ok/
</test>
py-import-keys () {
cmd="$py impkeys"
expect=/ok/
}
py-encrypt-asym-armor () {
cmd="$py asymarmor"
expect=/ok/
check "$cmd" "$expect" "$input"
}
<test py-encrypt-asym-armor>
cmd = $py asymarmor
expect = /ok/
</test>
py-encrypt-asym-raw () {
cmd="$py asymraw"
expect=/ok/
check "$cmd" "$expect" "$input"
}
<test py-encrypt-asym-raw>
cmd = $py asymraw
expect = /ok/
</test>
py-encrypt-asym-sign () {
cmd="$py asymsign"
expect=/ok/
check "$cmd" "$expect" "$input"
}
<test py-encrypt-asym-sign>
cmd = $py asymsign
expect = /ok/
</test>
py-encrypt-asym-anon () {
cmd="$py asymanon"
expect=/ok/
check "$cmd" "$expect" "$input"
}
<test py-encrypt-asym-anon>
cmd = $py asymanon
expect = /ok/
</test>
py-encrypt-sym-armor () {
cmd="$py symarmor"
expect=/ok/
check "$cmd" "$expect" "$input"
}
<test py-encrypt-sym-armor>
cmd = $py symarmor
expect = /ok/
</test>
py-encrypt-sym-raw () {
cmd="$py symraw"
expect=/ok/
check "$cmd" "$expect" "$input"
}
<test py-encrypt-sym-raw>
cmd = $py symraw
expect = /ok/
</test>
prepare () {
:
}

File diff suppressed because it is too large Load Diff

133
tests/unittests.sh Executable file
View File

@@ -0,0 +1,133 @@
#!/bin/sh
errout () {
log="$1"
expect="$2"
echo " EXPECTED: $expect"
echo -n " GOT: "
cat $log | head -1
cat $log | tail +2 | sed 's/^/ /'
}
lookup () {
log="$1"
expect="$2"
if echo "$expect" | grep '!' > /dev/null 2>&2; then
# negate
expect=`echo "$expect" | sed -e 's/^\!//' -e 's#^/##' -e 's#/$##'`
if cat $log | grep "$expect" > /dev/null 2>&1; then
errout "$log" "NOT $expect"
return 1
else
echo " OK"
return 0
fi
else
expect=`echo "$expect" | sed -e 's#^/##' -e 's#/$##'`
if cat $log | grep "$expect" > /dev/null 2>&1; then
echo " OK"
return 0
else
errout "$log" "$expect"
return 1
fi
fi
}
check() {
cmd="$1"
expect="$2"
input="$3"
file="$4"
log=".log-$$"
fail=''
echo " executing $cmd"
echo "$input" | eval "$cmd" > $log 2>&1
if test -n "$file"; then
# ignore result, check output file
if test -n "$expect"; then
# look for string in output
if ! lookup "$log" "$expect"; then
fail=y
fi
else
# just check for existence
if test -e "$file"; then
echo " OK"
else
echo " Failed: $file doesnt exist"
fail=y
fi
fi
else
# check output
if ! lookup "$log" "$expect"; then
fail=y
fi
fi
rm -f $log
if test -n "$fail"; then
return 1
else
return 0
fi
}
checkdump () {
F="$1"
if test -e "pcp1.core"; then
echo "Test $F dumped core!"
gdb -x .gdb -batch $pcp pcp1.core
exit 1
fi
}
callcheck () {
F="$1"
rm -f pcp1.core
echo "--- test $F result:"
if ! $F; then
echo
echo "Test $F failed!"
checkdump $F
exit 1
else
checkdump $F
fi
}
cfg="$1"
check="$2"
if test -z "$cfg"; then
echo "Usage: $0 <config> [check]"
exit 1
fi
if ! test -e "$cfg"; then
echo "$cfg doesn't exist!"
exit 1
fi
. $cfg
count=`grep -E -- "^check-" "$cfg" | wc -l`
callcheck prepare
if test -n "$check"; then
callcheck $check
else
for F in `grep -E -- "^check-" "$cfg" | cut -d' ' -f1`; do
callcheck $F
done
echo "All Tests OK"
fi