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: ctest:
rm -f test* v* stresstest/* 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'" @echo "To run a single test only, type: 'make test CHECK=testname'"
pytest: pytest:
./unittests.pl pyunittests.cfg $(CHECK) ./unittests.sh pyunittests.cfg $(CHECK)
docpptest: docpptest:
./unittests.pl cppunittests.cfg $(CHECK) ./unittests.sh cppunittests.cfg $(CHECK)
jsontest: jsontest:
./unittests.pl jsonunittests.cfg $(CHECK) ./unittests.sh jsonunittests.cfg $(CHECK)
stresstest: check stresstest: check
./unittests.pl stresstests.cfg ./unittests.pl stresstests.cfg

View File

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

View File

@@ -1,4 +1,4 @@
# -*-html-*- # -*-sh-*-
# #
# This file is part of Pretty Curved Privacy (pcp1). # This file is part of Pretty Curved Privacy (pcp1).
# #
@@ -23,63 +23,78 @@
pcp=../src/pcp1 pcp=../src/pcp1
passwd=xxx passwd=xxx
verbose=1 verbose=1
include keys.cfg
<test vja> . keys.cfg
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>
<test vjb> check-json-support () {
prepare = rm -f vjb; $pcp -V vjb -K -I key-bobby-sec -x b cmd="$pcp -V vja -t -j"
<test check-json-import-public> expect="\"keyvaultfile\""
cmd = $pcp -V vjb -K -I testkeyvjapub.json -j check "$cmd" "$expect"
expect /added/ }
</test>
<test check-json-import-public-open>
cmd = $pcp -V vjb -l
expect = /Alicia/
</test>
</test>
<test vjc> check-json-export-public () {
prepare = rm -f vjc cmd="$pcp -V vja -p -j -x a -O testkeyvjapub.json"
<test check-json-import-secret> expectfile="testkeyvjapub.json"
cmd = $pcp -V vjc -K -I testkeyvjasec.json -x a -j expect="/\"Alicia\"/"
expect = /added/ check "$cmd" "$expect" "$input" "$expectfile"
</test> }
<test check-json-import-secret-open>
cmd = $pcp -V vjc -l
expect = /Alicia/
</test>
</test>
<test vjtxt> check-json-export-secret () {
<test check-json-text-vault> cmd="$pcp -V vja -s -j -x a -O testkeyvjasec.json"
cmd = $pcp -V vjb -t -j expectfile="testkeyvjasec.json"
expect = /"Alicia"/ check "$cmd" "$expect" "$input" "$expectfile"
</test> }
<test check-json-text-public> check-json-export-secret-isjson () {
cmd = $pcp -V vjb -t -j -i ${idalicia} cmd="cat testkeyvjasec.json"
expect = /"Alicia"/ expect="/\"Alicia\"/"
</test> check "$cmd" "$expect" "$input" "$expectfile"
<test check-json-text-secret> }
cmd = $pcp -V vjb -t -j -i ${idbobby}
expect = /"Bobby"/ check-json-import-public () {
</test> cmd="$pcp -V vjb -K -I testkeyvjapub.json -j"
</test> 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). # This file is part of Pretty Curved Privacy (pcp1).
# #
@@ -21,38 +22,47 @@
py=./pytest.py py=./pytest.py
<test py-import-keys> py-import-keys () {
cmd = $py impkeys cmd="$py impkeys"
expect=/ok/ expect=/ok/
</test> }
py-encrypt-asym-armor () {
<test py-encrypt-asym-armor> cmd="$py asymarmor"
cmd = $py asymarmor
expect=/ok/ expect=/ok/
</test> check "$cmd" "$expect" "$input"
}
<test py-encrypt-asym-raw> py-encrypt-asym-raw () {
cmd = $py asymraw cmd="$py asymraw"
expect=/ok/ expect=/ok/
</test> check "$cmd" "$expect" "$input"
}
<test py-encrypt-asym-sign> py-encrypt-asym-sign () {
cmd = $py asymsign cmd="$py asymsign"
expect=/ok/ expect=/ok/
</test> check "$cmd" "$expect" "$input"
}
<test py-encrypt-asym-anon> py-encrypt-asym-anon () {
cmd = $py asymanon cmd="$py asymanon"
expect=/ok/ expect=/ok/
</test> check "$cmd" "$expect" "$input"
}
<test py-encrypt-sym-armor> py-encrypt-sym-armor () {
cmd = $py symarmor cmd="$py symarmor"
expect=/ok/ expect=/ok/
</test> check "$cmd" "$expect" "$input"
}
<test py-encrypt-sym-raw> py-encrypt-sym-raw () {
cmd = $py symraw cmd="$py symraw"
expect=/ok/ expect=/ok/
</test> check "$cmd" "$expect" "$input"
}
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