aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-07-27 14:16:17 +1200
committerDavid Phillips <david@sighup.nz>2017-07-27 14:16:17 +1200
commit8df5d237856d365a7a49835274e58e8c8bb281b1 (patch)
tree2973898cdff4fd9d4e4e5acf69b97221c879bfb9
parent92d9e59d6b3dc5375c100c72ba8907502aea8331 (diff)
downloadsand-leek-8df5d237856d365a7a49835274e58e8c8bb281b1.tar.xz
Add more tests, pull simple test runner from other project
-rw-r--r--Makefile4
-rwxr-xr-xtest/001-error-no-args.test/run.sh8
-rw-r--r--test/001-error-no-args.test/stderr.expected2
-rwxr-xr-xtest/002-test-key-name.test/run.sh (renamed from test.sh)2
-rw-r--r--test/003-test-invalid-char.test/run.sh9
-rw-r--r--test/003-test-invalid-char.test/stderr.expected2
-rwxr-xr-xtest/run-tests.sh43
7 files changed, 67 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 4f5566f..c06ac86 100644
--- a/Makefile
+++ b/Makefile
@@ -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