Add a very simple test for the pre-processor.
authorCarl Worth <cworth@cworth.org>
Mon, 10 May 2010 23:21:10 +0000 (16:21 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 10 May 2010 23:21:10 +0000 (16:21 -0700)
Validate desired test cases by ensuring the output of glcpp matches
the output of the gcc preprocessor, (ignoring any lines of the gcc
output beginning with '#').

Only one test case so far with a trivial #define.

.gitignore
Makefile
tests/001-define.c [new file with mode: 0644]
tests/glcpp-test [new file with mode: 0755]

index 5bbd660f22b0108edc8899861d52ddcd9f9f0c12..d67bd38c93cc8bb8e7d3f3bb94cfb907444d57b2 100644 (file)
@@ -4,3 +4,6 @@ glcpp-parse.c
 glcpp-parse.h
 *.o
 *~
+tests/*.expected
+tests/*.gcc
+tests/*.out
index d37e9233ec02955978cd722232a4a0497b291cc5..38cc1f314a9330933ab1c24d5f5199dedf86d5ec 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,5 +10,9 @@ glcpp: glcpp.o glcpp-lex.o glcpp-parse.o hash_table.o
 
 glcpp-lex.c: glcpp-parse.h
 
+test:
+       @(cd tests; ./glcpp-test)
+
 clean:
        rm -f glcpp-lex.c glcpp-parse.c *.o *~
+       rm -f tests/*.out tests/*.gcc tests/*.expected
diff --git a/tests/001-define.c b/tests/001-define.c
new file mode 100644 (file)
index 0000000..cbf2fee
--- /dev/null
@@ -0,0 +1,2 @@
+#define foo 1
+foo
diff --git a/tests/glcpp-test b/tests/glcpp-test
new file mode 100755 (executable)
index 0000000..25685ee
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+for test in *.c; do
+    echo "Testing $test"
+    ../glcpp < $test > $test.out
+    gcc -E $test -o $test.gcc
+    grep -v '^#' < $test.gcc > $test.expected
+    diff -u $test.expected $test.out
+done