From 22d2cb0a71b22c3142cc073b7ceca976d7a513c1 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Thu, 28 Dec 2017 19:15:21 +1300 Subject: Add beginnings of test framework --- .gitignore | 1 + Makefile | 3 +++ logic.c | 1 - parser.h | 1 + test/.gitignore | 2 ++ test/Makefile | 15 +++++++++++++++ test/test-whitespace-input.c | 11 +++++++++++ test/test.sh | 23 +++++++++++++++++++++++ 8 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 parser.h create mode 100644 test/.gitignore create mode 100644 test/Makefile create mode 100644 test/test-whitespace-input.c create mode 100755 test/test.sh 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 #include 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 + +#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 -- cgit v1.1