diff options
-rw-r--r-- | Makefile | 4 | ||||
-rwxr-xr-x | test/001-error-no-args.test/run.sh | 8 | ||||
-rw-r--r-- | test/001-error-no-args.test/stderr.expected | 2 | ||||
-rwxr-xr-x | test/002-test-key-name.test/run.sh (renamed from test.sh) | 2 | ||||
-rw-r--r-- | test/003-test-invalid-char.test/run.sh | 9 | ||||
-rw-r--r-- | test/003-test-invalid-char.test/stderr.expected | 2 | ||||
-rwxr-xr-x | test/run-tests.sh | 43 |
7 files changed, 67 insertions, 3 deletions
@@ -9,8 +9,8 @@ sand-leek: sand-leek.o onion_base32.o key_update.o clean: rm -vf sand-leek *.o -test: - ./test.sh +test: all + @./test/run-tests.sh .PHONY: all clean test diff --git a/test/001-error-no-args.test/run.sh b/test/001-error-no-args.test/run.sh new file mode 100755 index 0000000..4e67e1d --- /dev/null +++ b/test/001-error-no-args.test/run.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +${EXECUTABLE} +if [ $? -eq 0 ]; then + exit 1 +else + exit 0 +fi diff --git a/test/001-error-no-args.test/stderr.expected b/test/001-error-no-args.test/stderr.expected new file mode 100644 index 0000000..32481e5 --- /dev/null +++ b/test/001-error-no-args.test/stderr.expected @@ -0,0 +1,2 @@ +usage: ../../sand-leek [-t threads] -s search +searches for keys for onion addresses beginning with `search` diff --git a/test.sh b/test/002-test-key-name.test/run.sh index 2b24176..e4b4acb 100755 --- a/test.sh +++ b/test/002-test-key-name.test/run.sh @@ -6,7 +6,7 @@ key="$(mktemp)" stderr="$(mktemp)" # Four character search should be a < 1 second CPU burst for CI runner -./sand-leek -s site > $key 2>$stderr +${EXECUTABLE} -s site > $key 2>$stderr found="$(tr '\r' '\n' < $stderr | grep Found | cut -d ' ' -f 2)" diff --git a/test/003-test-invalid-char.test/run.sh b/test/003-test-invalid-char.test/run.sh new file mode 100644 index 0000000..a59b826 --- /dev/null +++ b/test/003-test-invalid-char.test/run.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +${EXECUTABLE} -s foovalid1not + +if [ $? -eq 0 ]; then + exit 1 +else + exit 0 +fi diff --git a/test/003-test-invalid-char.test/stderr.expected b/test/003-test-invalid-char.test/stderr.expected new file mode 100644 index 0000000..f1652b2 --- /dev/null +++ b/test/003-test-invalid-char.test/stderr.expected @@ -0,0 +1,2 @@ +Error: search contains non-base-32 character(s): 1 +I cannot search for something that will never occur diff --git a/test/run-tests.sh b/test/run-tests.sh new file mode 100755 index 0000000..07647dd --- /dev/null +++ b/test/run-tests.sh @@ -0,0 +1,43 @@ +#!/bin/sh + + +fail() +{ + echo -e '[\e[1;31mFAIL\e[0m] '$i: $@ + exit 1 +} + +pass() +{ + echo -e '[\e[0;32mPASS\e[0m] '$i +} + +check_expected() +{ + [ -z $1 ] && echo WARN: check_expected called with no argument + if [ -f $1.expected ] ; then + diff $1.expected $1.tmp >/dev/null + if [ $? -ne 0 ] ; then + fail "$1 didn't match expected" + fi + fi +} + +pushd $(dirname $0) >/dev/null +EXECUTABLE="../../sand-leek" +for i in *.test ; do + pushd ${i} >/dev/null + ( . ./run.sh ) 2>stderr.tmp >stdout.tmp + if [ $? -ne 0 ] ; then + fail "script had non-zero return code" + fi + + check_expected stdout + check_expected stderr + + pass $i + + rm std{err,out}.tmp + popd >/dev/null +done +popd >/dev/null |