diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | logic.c | 1 | ||||
-rw-r--r-- | parser.h | 1 | ||||
-rw-r--r-- | test/.gitignore | 2 | ||||
-rw-r--r-- | test/Makefile | 15 | ||||
-rw-r--r-- | test/test-whitespace-input.c | 11 | ||||
-rwxr-xr-x | test/test.sh | 23 |
8 files changed, 56 insertions, 1 deletions
@@ -1,3 +1,4 @@ *.o simulator parser +*.swp @@ -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 @@ -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 |