From e22abc4eaf4f1446c6ac31e4b709cb5206d4fe3b Mon Sep 17 00:00:00 2001 From: David Phillips Date: Wed, 1 Aug 2018 21:55:36 +1200 Subject: Add simple language test cases, fix empty line bug --- test/Makefile | 6 +-- test/invalid-hence/empty-1.hence | 0 test/invalid-hence/empty-1.hence.expected | 1 + test/invalid-hence/empty-2.hence | 1 + test/invalid-hence/empty-2.hence.expected | 1 + test/invalid-hence/empty-3.hence | 2 + test/invalid-hence/empty-3.hence.expected | 1 + test/invalid-hence/empty-4.hence | 1 + test/invalid-hence/empty-4.hence.expected | 1 + test/invalid-hence/empty-5.hence | 1 + test/invalid-hence/empty-5.hence.expected | 1 + test/invalid-hence/empty-6.hence | 1 + test/invalid-hence/empty-6.hence.expected | 1 + test/invalid-hence/empty-7.hence | 1 + test/invalid-hence/empty-7.hence.expected | 1 + test/invalid-hence/empty-8.hence | 4 ++ test/invalid-hence/empty-8.hence.expected | 1 + test/invalid-hence/empty-9.hence | 2 + test/invalid-hence/empty-9.hence.expected | 1 + test/old/test-duplicate-input.c | 13 ++++++ test/old/test-short-keyword.c | 76 +++++++++++++++++++++++++++++++ test/old/test-whitespace-input.c | 11 +++++ test/run-lang-tests.sh | 28 ++++++++++++ test/test-duplicate-input.c | 13 ------ test/test-short-keyword.c | 76 ------------------------------- test/test-whitespace-input.c | 11 ----- 26 files changed, 152 insertions(+), 104 deletions(-) create mode 100644 test/invalid-hence/empty-1.hence create mode 100644 test/invalid-hence/empty-1.hence.expected create mode 100644 test/invalid-hence/empty-2.hence create mode 100644 test/invalid-hence/empty-2.hence.expected create mode 100644 test/invalid-hence/empty-3.hence create mode 100644 test/invalid-hence/empty-3.hence.expected create mode 100644 test/invalid-hence/empty-4.hence create mode 100644 test/invalid-hence/empty-4.hence.expected create mode 100644 test/invalid-hence/empty-5.hence create mode 100644 test/invalid-hence/empty-5.hence.expected create mode 100644 test/invalid-hence/empty-6.hence create mode 100644 test/invalid-hence/empty-6.hence.expected create mode 100644 test/invalid-hence/empty-7.hence create mode 100644 test/invalid-hence/empty-7.hence.expected create mode 100644 test/invalid-hence/empty-8.hence create mode 100644 test/invalid-hence/empty-8.hence.expected create mode 100644 test/invalid-hence/empty-9.hence create mode 100644 test/invalid-hence/empty-9.hence.expected create mode 100644 test/old/test-duplicate-input.c create mode 100644 test/old/test-short-keyword.c create mode 100644 test/old/test-whitespace-input.c create mode 100755 test/run-lang-tests.sh delete mode 100644 test/test-duplicate-input.c delete mode 100644 test/test-short-keyword.c delete mode 100644 test/test-whitespace-input.c (limited to 'test') diff --git a/test/Makefile b/test/Makefile index 44d4969..1c99ced 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,9 +1,6 @@ CFLAGS += -I../ TESTS = \ - bin/test-whitespace-input \ - bin/test-short-keyword \ - bin/test-duplicate-input \ bin/test-logic-and \ bin/test-logic-or \ bin/test-logic-nand \ @@ -14,7 +11,7 @@ TESTS = \ all: $(TESTS) -bin/test-%: test-%.c ../gate.o ../parser.o ../logic.o +bin/test-%: test-%.c ../gate.o ../logic.o $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ .PHONY: clean @@ -28,3 +25,4 @@ clean: .PHONY: test test: ./test.sh + ./run-lang-tests.sh diff --git a/test/invalid-hence/empty-1.hence b/test/invalid-hence/empty-1.hence new file mode 100644 index 0000000..e69de29 diff --git a/test/invalid-hence/empty-1.hence.expected b/test/invalid-hence/empty-1.hence.expected new file mode 100644 index 0000000..bb92112 --- /dev/null +++ b/test/invalid-hence/empty-1.hence.expected @@ -0,0 +1 @@ +invalid-hence/empty-1.hence: Error: Expected module declaration, got end of file diff --git a/test/invalid-hence/empty-2.hence b/test/invalid-hence/empty-2.hence new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/invalid-hence/empty-2.hence @@ -0,0 +1 @@ + diff --git a/test/invalid-hence/empty-2.hence.expected b/test/invalid-hence/empty-2.hence.expected new file mode 100644 index 0000000..17a6d80 --- /dev/null +++ b/test/invalid-hence/empty-2.hence.expected @@ -0,0 +1 @@ +invalid-hence/empty-2.hence: Error: Expected module declaration, got end of file diff --git a/test/invalid-hence/empty-3.hence b/test/invalid-hence/empty-3.hence new file mode 100644 index 0000000..139597f --- /dev/null +++ b/test/invalid-hence/empty-3.hence @@ -0,0 +1,2 @@ + + diff --git a/test/invalid-hence/empty-3.hence.expected b/test/invalid-hence/empty-3.hence.expected new file mode 100644 index 0000000..576aae5 --- /dev/null +++ b/test/invalid-hence/empty-3.hence.expected @@ -0,0 +1 @@ +invalid-hence/empty-3.hence: Error: Expected module declaration, got end of file diff --git a/test/invalid-hence/empty-4.hence b/test/invalid-hence/empty-4.hence new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/test/invalid-hence/empty-4.hence @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/invalid-hence/empty-4.hence.expected b/test/invalid-hence/empty-4.hence.expected new file mode 100644 index 0000000..2d7a30b --- /dev/null +++ b/test/invalid-hence/empty-4.hence.expected @@ -0,0 +1 @@ +invalid-hence/empty-4.hence: Error: Expected module declaration, got end of file diff --git a/test/invalid-hence/empty-5.hence b/test/invalid-hence/empty-5.hence new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/test/invalid-hence/empty-5.hence @@ -0,0 +1 @@ + diff --git a/test/invalid-hence/empty-5.hence.expected b/test/invalid-hence/empty-5.hence.expected new file mode 100644 index 0000000..afd7eaf --- /dev/null +++ b/test/invalid-hence/empty-5.hence.expected @@ -0,0 +1 @@ +invalid-hence/empty-5.hence: Error: Expected module declaration, got end of file diff --git a/test/invalid-hence/empty-6.hence b/test/invalid-hence/empty-6.hence new file mode 100644 index 0000000..501a6bb --- /dev/null +++ b/test/invalid-hence/empty-6.hence @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/invalid-hence/empty-6.hence.expected b/test/invalid-hence/empty-6.hence.expected new file mode 100644 index 0000000..1869ba1 --- /dev/null +++ b/test/invalid-hence/empty-6.hence.expected @@ -0,0 +1 @@ +invalid-hence/empty-6.hence: Error: Expected module declaration, got end of file diff --git a/test/invalid-hence/empty-7.hence b/test/invalid-hence/empty-7.hence new file mode 100644 index 0000000..09c0ba9 --- /dev/null +++ b/test/invalid-hence/empty-7.hence @@ -0,0 +1 @@ + diff --git a/test/invalid-hence/empty-7.hence.expected b/test/invalid-hence/empty-7.hence.expected new file mode 100644 index 0000000..cf98e0c --- /dev/null +++ b/test/invalid-hence/empty-7.hence.expected @@ -0,0 +1 @@ +invalid-hence/empty-7.hence: Error: Expected module declaration, got end of file diff --git a/test/invalid-hence/empty-8.hence b/test/invalid-hence/empty-8.hence new file mode 100644 index 0000000..0b2d044 --- /dev/null +++ b/test/invalid-hence/empty-8.hence @@ -0,0 +1,4 @@ + + + + diff --git a/test/invalid-hence/empty-8.hence.expected b/test/invalid-hence/empty-8.hence.expected new file mode 100644 index 0000000..834673e --- /dev/null +++ b/test/invalid-hence/empty-8.hence.expected @@ -0,0 +1 @@ +invalid-hence/empty-8.hence: Error: Expected module declaration, got end of file diff --git a/test/invalid-hence/empty-9.hence b/test/invalid-hence/empty-9.hence new file mode 100644 index 0000000..de13416 --- /dev/null +++ b/test/invalid-hence/empty-9.hence @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/test/invalid-hence/empty-9.hence.expected b/test/invalid-hence/empty-9.hence.expected new file mode 100644 index 0000000..1b4af21 --- /dev/null +++ b/test/invalid-hence/empty-9.hence.expected @@ -0,0 +1 @@ +invalid-hence/empty-9.hence: Error: Expected module declaration, got end of file diff --git a/test/old/test-duplicate-input.c b/test/old/test-duplicate-input.c new file mode 100644 index 0000000..8d1b88f --- /dev/null +++ b/test/old/test-duplicate-input.c @@ -0,0 +1,13 @@ +#include + +#include "gate.h" +#include "parser.h" + +int main(void) { + char test_string[] = "input test\n"; + assert(0 == parse_line(test_string)); + assert(gate_get_input_by_name("test") != NULL); + assert(0 != parse_line(test_string)); + assert(gate_get_input_by_name("test") != NULL); + return 0; +} diff --git a/test/old/test-short-keyword.c b/test/old/test-short-keyword.c new file mode 100644 index 0000000..b3baa2c --- /dev/null +++ b/test/old/test-short-keyword.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include + +#include "gate.h" +#include "parser.h" + +char *failures[] = { + "input" + "input\n", + "input \n", + "input aa aa\n", + "module", + " module ", + "\tmodule ", + " moudle \t\n ", + "expr ", + " expr ", + "expr", + "expr asdf xor a b", + "expr asdf: xor b", + "expr asdf: foo b", + "expr asdf: foo a b", +}; + +char *passes[] = { + "input aa", + "input a\n", + "input aaaaaaaa\n", + "module test", + "module test", + "module test ", + "module test ", + " \tmodule \ttest \t", + "expr asdf: xor aa a", + "expr asdf: not aa", + " expr asdf: not aa ", + "\n", + "\n\n", + "\r", + "\r\r", + "\r\n", + "\n\r", + "\n\n\r", + "\r\n\r", + "", + "\t" +}; + +int main(void) { + size_t i = 0; + char *string = NULL; + + for (i = 0; i < sizeof(failures)/sizeof(failures[0]); i++) { + string = strdup(failures[i]); + if (string == NULL) { + perror("strdup"); + return 1; + } + fprintf(stderr, "Testing xfail '%s'\n", string); + assert(0 != parse_line(string)); + free(string); + } + for (i = 0; i < sizeof(passes)/sizeof(passes[0]); i++) { + string = strdup(passes[i]); + if (string == NULL) { + perror("strdup"); + return 1; + } + fprintf(stderr, "Testing xpass '%s'\n", string); + assert(0 == parse_line(string)); + free(string); + } + return 0; +} diff --git a/test/old/test-whitespace-input.c b/test/old/test-whitespace-input.c new file mode 100644 index 0000000..cb4ec22 --- /dev/null +++ b/test/old/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/run-lang-tests.sh b/test/run-lang-tests.sh new file mode 100755 index 0000000..5cc68b3 --- /dev/null +++ b/test/run-lang-tests.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +cd "$(dirname $0)" +EXECUTABLE="$PWD/../simulator" + +echo $PWD + +for src in invalid-hence/*.hence ; do + outfile="$(mktemp)" + "$EXECUTABLE" "$src" 2> "$outfile" + if diff "$src.expected" "$outfile" ; then + echo -ne '[\e[0;32mPASS\e[0m]' + rm "$outfile" + else + echo -ne '[\e[1;31mFAIL\e[0m]' + fi + echo " $src" +done + +#for src in valid-hence/*.hence ; do +# outfile="$(mktemp)" +# "$EXECUTABLE" "$src" > "$outfile" +# if diff "$src.expected" "$outfile" >/dev/null ; then +# echo "$src: PASS" +# else +# echo "$src: FAIL" +# fi +#done diff --git a/test/test-duplicate-input.c b/test/test-duplicate-input.c deleted file mode 100644 index 8d1b88f..0000000 --- a/test/test-duplicate-input.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include "gate.h" -#include "parser.h" - -int main(void) { - char test_string[] = "input test\n"; - assert(0 == parse_line(test_string)); - assert(gate_get_input_by_name("test") != NULL); - assert(0 != parse_line(test_string)); - assert(gate_get_input_by_name("test") != NULL); - return 0; -} diff --git a/test/test-short-keyword.c b/test/test-short-keyword.c deleted file mode 100644 index b3baa2c..0000000 --- a/test/test-short-keyword.c +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include - -#include "gate.h" -#include "parser.h" - -char *failures[] = { - "input" - "input\n", - "input \n", - "input aa aa\n", - "module", - " module ", - "\tmodule ", - " moudle \t\n ", - "expr ", - " expr ", - "expr", - "expr asdf xor a b", - "expr asdf: xor b", - "expr asdf: foo b", - "expr asdf: foo a b", -}; - -char *passes[] = { - "input aa", - "input a\n", - "input aaaaaaaa\n", - "module test", - "module test", - "module test ", - "module test ", - " \tmodule \ttest \t", - "expr asdf: xor aa a", - "expr asdf: not aa", - " expr asdf: not aa ", - "\n", - "\n\n", - "\r", - "\r\r", - "\r\n", - "\n\r", - "\n\n\r", - "\r\n\r", - "", - "\t" -}; - -int main(void) { - size_t i = 0; - char *string = NULL; - - for (i = 0; i < sizeof(failures)/sizeof(failures[0]); i++) { - string = strdup(failures[i]); - if (string == NULL) { - perror("strdup"); - return 1; - } - fprintf(stderr, "Testing xfail '%s'\n", string); - assert(0 != parse_line(string)); - free(string); - } - for (i = 0; i < sizeof(passes)/sizeof(passes[0]); i++) { - string = strdup(passes[i]); - if (string == NULL) { - perror("strdup"); - return 1; - } - fprintf(stderr, "Testing xpass '%s'\n", string); - assert(0 == parse_line(string)); - free(string); - } - return 0; -} diff --git a/test/test-whitespace-input.c b/test/test-whitespace-input.c deleted file mode 100644 index cb4ec22..0000000 --- a/test/test-whitespace-input.c +++ /dev/null @@ -1,11 +0,0 @@ -#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; -} -- cgit v1.1