From b20d33c5c6fea8e392c26e9ab060efd14034f1f9 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 20 May 2010 22:27:07 -0700 Subject: Implement #if, #else, #elif, and #endif with tests. So far the only expression implemented is a single integer literal, but obviously that's easy to extend. Various things including nesting are tested here. --- tests/040-token-pasting.c | 2 ++ tests/041-if-0.c | 5 +++++ tests/042-if-1.c | 5 +++++ tests/043-if-0-else.c | 7 +++++++ tests/044-if-1-else.c | 7 +++++++ tests/045-if-0-elif.c | 11 +++++++++++ tests/046-if-1-elsif.c | 11 +++++++++++ tests/047-if-elif-else.c | 11 +++++++++++ tests/048-if-nested.c | 11 +++++++++++ tests/glcpp-test | 2 +- 10 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 tests/040-token-pasting.c create mode 100644 tests/041-if-0.c create mode 100644 tests/042-if-1.c create mode 100644 tests/043-if-0-else.c create mode 100644 tests/044-if-1-else.c create mode 100644 tests/045-if-0-elif.c create mode 100644 tests/046-if-1-elsif.c create mode 100644 tests/047-if-elif-else.c create mode 100644 tests/048-if-nested.c (limited to 'tests') diff --git a/tests/040-token-pasting.c b/tests/040-token-pasting.c new file mode 100644 index 0000000000..caab3ba736 --- /dev/null +++ b/tests/040-token-pasting.c @@ -0,0 +1,2 @@ +#define paste(a,b) a ## b +paste(one , token) diff --git a/tests/041-if-0.c b/tests/041-if-0.c new file mode 100644 index 0000000000..2cab677d3e --- /dev/null +++ b/tests/041-if-0.c @@ -0,0 +1,5 @@ +success_1 +#if 0 +failure +#endif +success_2 diff --git a/tests/042-if-1.c b/tests/042-if-1.c new file mode 100644 index 0000000000..874a25cf41 --- /dev/null +++ b/tests/042-if-1.c @@ -0,0 +1,5 @@ +success_1 +#if 1 +success_2 +#endif +success_3 diff --git a/tests/043-if-0-else.c b/tests/043-if-0-else.c new file mode 100644 index 0000000000..323351f9db --- /dev/null +++ b/tests/043-if-0-else.c @@ -0,0 +1,7 @@ +success_1 +#if 0 +failure +#else +success_2 +#endif +success_3 diff --git a/tests/044-if-1-else.c b/tests/044-if-1-else.c new file mode 100644 index 0000000000..28dfc25c6f --- /dev/null +++ b/tests/044-if-1-else.c @@ -0,0 +1,7 @@ +success_1 +#if 1 +success_2 +#else +failure +#endif +success_3 diff --git a/tests/045-if-0-elif.c b/tests/045-if-0-elif.c new file mode 100644 index 0000000000..e50f686d46 --- /dev/null +++ b/tests/045-if-0-elif.c @@ -0,0 +1,11 @@ +success_1 +#if 0 +failure_1 +#elif 0 +failure_2 +#elif 1 +success_3 +#elif 1 +failure_3 +#endif +success_4 diff --git a/tests/046-if-1-elsif.c b/tests/046-if-1-elsif.c new file mode 100644 index 0000000000..130515a01e --- /dev/null +++ b/tests/046-if-1-elsif.c @@ -0,0 +1,11 @@ +success_1 +#if 1 +success_2 +#elif 0 +failure_1 +#elif 1 +failure_2 +#elif 0 +failure_3 +#endif +success_3 diff --git a/tests/047-if-elif-else.c b/tests/047-if-elif-else.c new file mode 100644 index 0000000000..e8f0838a9e --- /dev/null +++ b/tests/047-if-elif-else.c @@ -0,0 +1,11 @@ +success_1 +#if 0 +failure_1 +#elif 0 +failure_2 +#elif 0 +failure_3 +#else +success_2 +#endif +success_3 diff --git a/tests/048-if-nested.c b/tests/048-if-nested.c new file mode 100644 index 0000000000..fc4679c3be --- /dev/null +++ b/tests/048-if-nested.c @@ -0,0 +1,11 @@ +success_1 +#if 0 +failure_1 +#if 1 +failure_2 +#else +failure_3 +#endif +failure_4 +#endif +success_2 diff --git a/tests/glcpp-test b/tests/glcpp-test index 25685eeabe..022a236712 100755 --- a/tests/glcpp-test +++ b/tests/glcpp-test @@ -5,5 +5,5 @@ for test in *.c; do ../glcpp < $test > $test.out gcc -E $test -o $test.gcc grep -v '^#' < $test.gcc > $test.expected - diff -u $test.expected $test.out + diff -B -u $test.expected $test.out done -- cgit v1.2.3