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 --- test/.gitignore | 2 ++ test/Makefile | 15 +++++++++++++++ test/test-whitespace-input.c | 11 +++++++++++ test/test.sh | 23 +++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 test/.gitignore create mode 100644 test/Makefile create mode 100644 test/test-whitespace-input.c create mode 100755 test/test.sh (limited to 'test') 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