summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-12-28 19:15:21 +1300
committerDavid Phillips <david@sighup.nz>2017-12-28 19:24:39 +1300
commit22d2cb0a71b22c3142cc073b7ceca976d7a513c1 (patch)
treea113c1b89a71e4a4962e65e22ae9300cc6412f4f
parent95e3d12b61d7ca89c978b22403e66df8656238ae (diff)
downloadhence-22d2cb0a71b22c3142cc073b7ceca976d7a513c1.tar.xz
Add beginnings of test framework
-rw-r--r--.gitignore1
-rw-r--r--Makefile3
-rw-r--r--logic.c1
-rw-r--r--parser.h1
-rw-r--r--test/.gitignore2
-rw-r--r--test/Makefile15
-rw-r--r--test/test-whitespace-input.c11
-rwxr-xr-xtest/test.sh23
8 files changed, 56 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 7bb37c6..6551343 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
*.o
simulator
parser
+*.swp
diff --git a/Makefile b/Makefile
index 4d97506..cc75e79 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,9 @@ simulator: simulator.o gate.o logic.o
parser: parser.o gate.o logic.o
+.PHONY: test
+test:
+ $(MAKE) -C test all test
clean:
rm -f parser simulator
diff --git a/logic.c b/logic.c
index 83c4148..a4f834e 100644
--- a/logic.c
+++ b/logic.c
@@ -1,4 +1,3 @@
-#define NDEBUG
#include <assert.h>
#include <stdlib.h>
diff --git a/parser.h b/parser.h
new file mode 100644
index 0000000..5c78b92
--- /dev/null
+++ b/parser.h
@@ -0,0 +1 @@
+int parse_line(char *line);
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 0000000..2674822
--- /dev/null
+++ b/test/.gitignore
@@ -0,0 +1,2 @@
+test-whitespace-input
+*.log
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..25c1690
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,15 @@
+CFLAGS += -I../
+
+TESTS = \
+ test-whitespace-input
+
+all: clean $(TESTS)
+
+test-whitespace-input: ../gate.o ../parser.o ../logic.o
+
+clean:
+ rm -f $(TESTS)
+
+.PHONY: test
+test:
+ ./test.sh
diff --git a/test/test-whitespace-input.c b/test/test-whitespace-input.c
new file mode 100644
index 0000000..cb4ec22
--- /dev/null
+++ b/test/test-whitespace-input.c
@@ -0,0 +1,11 @@
+#include <assert.h>
+
+#include "gate.h"
+#include "parser.h"
+
+int main(void) {
+ char test_string[] = "input b \n";
+ parse_line(test_string);
+ assert(gate_get_input_by_name("b") != NULL);
+ return 0;
+}
diff --git a/test/test.sh b/test/test.sh
new file mode 100755
index 0000000..91dddbd
--- /dev/null
+++ b/test/test.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+fail="none"
+
+for i in test-* ; do
+ if [[ "$i" != *.* ]] ; then
+ echo -n "$i: "
+ if ./"$i" >"$i.stdout.log" 2>"$i.stderr.log" ; then
+ echo -e '[\e[0;32mPASS\e[0m]'
+ else
+ echo -e '[\e[1;31mFAIL\e[0m]'
+ fail="indeed"
+ fi
+ fi
+done
+
+if [ "$fail" != "none" ] ; then
+ echo 'Test failure(s)'
+ exit 1
+else
+ echo Success
+ exit 0
+fi