From 41d24c967eb5fce3f811fc567f60204c77dada15 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 8 Jan 2026 00:18:34 +0900 Subject: refactor: rewrite some tests in C --- tests/arithmetic_operators.c | 9 ++++++ tests/arithmetic_operators.sh | 11 -------- tests/assignment_operators.c | 64 +++++++++++++++++++++++++++++++++++++++++++ tests/assignment_operators.sh | 64 ------------------------------------------- tests/bitwise_operators.c | 38 +++++++++++++++++++++++++ tests/bitwise_operators.sh | 40 --------------------------- tests/bool_type.c | 10 +++++++ tests/bool_type.sh | 12 -------- tests/char_literals.c | 25 +++++++++++++++++ tests/char_literals.sh | 27 ------------------ tests/comparison_operators.c | 12 ++++++++ tests/comparison_operators.sh | 14 ---------- tests/function_basics.c | 49 +++++++++++++++++++++++++++++++++ tests/function_basics.sh | 58 --------------------------------------- tests/global_variables.sh | 2 +- tests/helpers.sh | 10 +++---- tests/if_else.c | 19 +++++++++++++ tests/if_else.sh | 21 -------------- tests/local_variables.c | 38 +++++++++++++++++++++++++ tests/local_variables.sh | 56 ------------------------------------- tests/number_literals.c | 8 ++++++ tests/number_literals.sh | 10 ------- tests/recursive_functions.c | 13 +++++++++ tests/recursive_functions.sh | 15 ---------- tests/run.sh | 29 +++++++++++++------- tests/switch.sh | 16 +++++------ tests/ternary_operator.c | 6 ++++ tests/ternary_operator.sh | 8 ------ 28 files changed, 324 insertions(+), 360 deletions(-) create mode 100644 tests/arithmetic_operators.c delete mode 100644 tests/arithmetic_operators.sh create mode 100644 tests/assignment_operators.c delete mode 100644 tests/assignment_operators.sh create mode 100644 tests/bitwise_operators.c delete mode 100644 tests/bitwise_operators.sh create mode 100644 tests/bool_type.c delete mode 100644 tests/bool_type.sh create mode 100644 tests/char_literals.c delete mode 100644 tests/char_literals.sh create mode 100644 tests/comparison_operators.c delete mode 100644 tests/comparison_operators.sh create mode 100644 tests/function_basics.c delete mode 100644 tests/function_basics.sh create mode 100644 tests/if_else.c delete mode 100644 tests/if_else.sh create mode 100644 tests/local_variables.c delete mode 100644 tests/local_variables.sh create mode 100644 tests/number_literals.c delete mode 100644 tests/number_literals.sh create mode 100644 tests/recursive_functions.c delete mode 100644 tests/recursive_functions.sh create mode 100644 tests/ternary_operator.c delete mode 100644 tests/ternary_operator.sh diff --git a/tests/arithmetic_operators.c b/tests/arithmetic_operators.c new file mode 100644 index 0000000..e7cfe95 --- /dev/null +++ b/tests/arithmetic_operators.c @@ -0,0 +1,9 @@ +#include + +int main() { + ASSERT_EQ(42, 42); + ASSERT_EQ(21, 5 + 20 - 4); + ASSERT_EQ(26, 2 * 3 + 4 * 5); + ASSERT_EQ(197, (((3 + 5) / 2) + (5 * (9 - 6)) * (5 + 6 * 7)) % 256); + ASSERT_EQ(30, (-10 + 20 * -3) + 100); +} diff --git a/tests/arithmetic_operators.sh b/tests/arithmetic_operators.sh deleted file mode 100644 index a98ca15..0000000 --- a/tests/arithmetic_operators.sh +++ /dev/null @@ -1,11 +0,0 @@ -test_exit_code 0 <<'EOF' -#include "../../helpers.h" - -int main() { - ASSERT_EQ(42, 42); - ASSERT_EQ(21, 5+20-4); - ASSERT_EQ(26, 2*3+4*5); - ASSERT_EQ(197, (((3+5)/2) + (5*(9-6)) * (5+6*7)) % 256); - ASSERT_EQ(30, (-10 + 20 * -3) + 100); -} -EOF diff --git a/tests/assignment_operators.c b/tests/assignment_operators.c new file mode 100644 index 0000000..1edc574 --- /dev/null +++ b/tests/assignment_operators.c @@ -0,0 +1,64 @@ +#include + +int main() { + int i = 0; + for (; i < 5; i += 1) { + } + ASSERT_EQ(5, i); + + for (i = 5; i >= 0; i -= 1) + ; + ASSERT_EQ(-1, i); + + int x = 123; + x *= 456; + ASSERT_EQ(56088, x); + + int y = 120; + y /= 5; + ASSERT_EQ(24, y); + + int z = 17; + z %= 7; + ASSERT_EQ(3, z); + + int a = 0x05; + a |= 0x0A; + ASSERT_EQ(0x0F, a); + + int b = 0x0F; + b &= 0x0A; + ASSERT_EQ(0x0A, b); + + int c = 7; + c |= 8; + ASSERT_EQ(15, c); + + int d = 15; + d &= 6; + ASSERT_EQ(6, d); + + int e = 0x0F; + e ^= 0x05; + ASSERT_EQ(0x0A, e); + + int f = 3; + f <<= 2; + ASSERT_EQ(12, f); + + int g = 16; + g >>= 2; + ASSERT_EQ(4, g); + + int h = -16; + h >>= 2; + ASSERT_EQ(-4, h); + + int j = 1; + j <<= 4; + ASSERT_EQ(16, j); + + int k = 64; + k >>= 3; + ASSERT_EQ(8, k); +} diff --git a/tests/assignment_operators.sh b/tests/assignment_operators.sh deleted file mode 100644 index 9b3a33e..0000000 --- a/tests/assignment_operators.sh +++ /dev/null @@ -1,64 +0,0 @@ -test_exit_code 0 <<'EOF' -#include "../../helpers.h" - -int main() { - int i = 0; - for (; i < 5; i += 1) {} - ASSERT_EQ(5, i); - - for (i = 5; i >= 0; i -= 1); - ASSERT_EQ(-1, i); - - int x = 123; - x *= 456; - ASSERT_EQ(56088, x); - - int y = 120; - y /= 5; - ASSERT_EQ(24, y); - - int z = 17; - z %= 7; - ASSERT_EQ(3, z); - - int a = 0x05; - a |= 0x0A; - ASSERT_EQ(0x0F, a); - - int b = 0x0F; - b &= 0x0A; - ASSERT_EQ(0x0A, b); - - int c = 7; - c |= 8; - ASSERT_EQ(15, c); - - int d = 15; - d &= 6; - ASSERT_EQ(6, d); - - int e = 0x0F; - e ^= 0x05; - ASSERT_EQ(0x0A, e); - - int f = 3; - f <<= 2; - ASSERT_EQ(12, f); - - int g = 16; - g >>= 2; - ASSERT_EQ(4, g); - - int h = -16; - h >>= 2; - ASSERT_EQ(-4, h); - - int j = 1; - j <<= 4; - ASSERT_EQ(16, j); - - int k = 64; - k >>= 3; - ASSERT_EQ(8, k); -} -EOF diff --git a/tests/bitwise_operators.c b/tests/bitwise_operators.c new file mode 100644 index 0000000..e8a5619 --- /dev/null +++ b/tests/bitwise_operators.c @@ -0,0 +1,38 @@ +#include + +int main() { + ASSERT_EQ(123, 0 | 123); + ASSERT_EQ(460, 12 | 456); + + ASSERT_EQ(8, 1 << 3); + ASSERT_EQ(336, 21 << 4); + ASSERT_EQ(13, 111 >> 3); + ASSERT_EQ(0, 15 >> 14); + + int a = 5; + int b = 3; + ASSERT_EQ(1, a & b); + ASSERT_EQ(7, a | b); + ASSERT_EQ(6, a ^ b); + ASSERT_EQ(4, 2 + 3 & 4); + + int c = 1 + 2 & 3; + int d = 4 & 5 ^ 6; + int e = 1 ^ 2 | 3; + int f = 0 | 1 & 2; + ASSERT_EQ(3, c); + ASSERT_EQ(2, d); + ASSERT_EQ(3, e); + ASSERT_EQ(0, f); + + ASSERT_EQ(-1, ~0); + ASSERT_EQ(-2, ~1); + ASSERT_EQ(-6, ~5); + ASSERT_EQ(0, ~(-1)); + ASSERT_EQ(5, ~(-6)); + + int x = 10; + ASSERT_EQ(-11, ~x); + ASSERT_EQ(-1, ~(x & 0)); + ASSERT_EQ(-16, ~(x | 5)); +} diff --git a/tests/bitwise_operators.sh b/tests/bitwise_operators.sh deleted file mode 100644 index f683099..0000000 --- a/tests/bitwise_operators.sh +++ /dev/null @@ -1,40 +0,0 @@ -test_exit_code 0 <<'EOF' -#include "../../helpers.h" - -int main() { - ASSERT_EQ(123, 0 | 123); - ASSERT_EQ(460, 12 | 456); - - ASSERT_EQ(8, 1 << 3); - ASSERT_EQ(336, 21 << 4); - ASSERT_EQ(13, 111 >> 3); - ASSERT_EQ(0, 15 >> 14); - - int a = 5; - int b = 3; - ASSERT_EQ(1, a & b); - ASSERT_EQ(7, a | b); - ASSERT_EQ(6, a ^ b); - ASSERT_EQ(4, 2 + 3 & 4); - - int c = 1 + 2 & 3; - int d = 4 & 5 ^ 6; - int e = 1 ^ 2 | 3; - int f = 0 | 1 & 2; - ASSERT_EQ(3, c); - ASSERT_EQ(2, d); - ASSERT_EQ(3, e); - ASSERT_EQ(0, f); - - ASSERT_EQ(-1, ~0); - ASSERT_EQ(-2, ~1); - ASSERT_EQ(-6, ~5); - ASSERT_EQ(0, ~(-1)); - ASSERT_EQ(5, ~(-6)); - - int x = 10; - ASSERT_EQ(-11, ~x); - ASSERT_EQ(-1, ~(x & 0)); - ASSERT_EQ(-16, ~(x | 5)); -} -EOF diff --git a/tests/bool_type.c b/tests/bool_type.c new file mode 100644 index 0000000..7313410 --- /dev/null +++ b/tests/bool_type.c @@ -0,0 +1,10 @@ +#include + +int main() { + bool b1 = true, b0 = false; + ASSERT_EQ(1, b1); + ASSERT_EQ(0, b0); + ASSERT_EQ(1, sizeof(b1)); + ASSERT_EQ(1, sizeof(b0)); + ASSERT_EQ(1, sizeof(bool)); +} diff --git a/tests/bool_type.sh b/tests/bool_type.sh deleted file mode 100644 index d18fd30..0000000 --- a/tests/bool_type.sh +++ /dev/null @@ -1,12 +0,0 @@ -test_exit_code 0 <<'EOF' -#include "../../helpers.h" - -int main() { - bool b1 = true, b0 = false; - ASSERT_EQ(1, b1); - ASSERT_EQ(0, b0); - ASSERT_EQ(1, sizeof(b1)); - ASSERT_EQ(1, sizeof(b0)); - ASSERT_EQ(1, sizeof(bool)); -} -EOF diff --git a/tests/char_literals.c b/tests/char_literals.c new file mode 100644 index 0000000..cc592ff --- /dev/null +++ b/tests/char_literals.c @@ -0,0 +1,25 @@ +#include + +int main() { + ASSERT_EQ(97, 'a'); + ASSERT_EQ(48, '0'); + ASSERT_EQ(92, '\\'); + ASSERT_EQ(39, '\''); + ASSERT_EQ(10, '\n'); + + ASSERT_EQ(39, '\''); + ASSERT_EQ(34, '\"'); + ASSERT_EQ(63, '\?'); + ASSERT_EQ(92, '\\'); + ASSERT_EQ(7, '\a'); + ASSERT_EQ(8, '\b'); + ASSERT_EQ(12, '\f'); + ASSERT_EQ(10, '\n'); + ASSERT_EQ(13, '\r'); + ASSERT_EQ(9, '\t'); + ASSERT_EQ(11, '\v'); + + ASSERT_EQ(0, '\0'); + + ASSERT_EQ(27, '\e'); +} diff --git a/tests/char_literals.sh b/tests/char_literals.sh deleted file mode 100644 index 64b130b..0000000 --- a/tests/char_literals.sh +++ /dev/null @@ -1,27 +0,0 @@ -test_exit_code 0 <<'EOF' -#include "../../helpers.h" - -int main() { - ASSERT_EQ(97, 'a'); - ASSERT_EQ(48, '0'); - ASSERT_EQ(92, '\\'); - ASSERT_EQ(39, '\''); - ASSERT_EQ(10, '\n'); - - ASSERT_EQ(39, '\''); - ASSERT_EQ(34, '\"'); - ASSERT_EQ(63, '\?'); - ASSERT_EQ(92, '\\'); - ASSERT_EQ(7, '\a'); - ASSERT_EQ(8, '\b'); - ASSERT_EQ(12, '\f'); - ASSERT_EQ(10, '\n'); - ASSERT_EQ(13, '\r'); - ASSERT_EQ(9, '\t'); - ASSERT_EQ(11, '\v'); - - ASSERT_EQ(0, '\0'); - - ASSERT_EQ(27, '\e'); -} -EOF diff --git a/tests/comparison_operators.c b/tests/comparison_operators.c new file mode 100644 index 0000000..7e0600d --- /dev/null +++ b/tests/comparison_operators.c @@ -0,0 +1,12 @@ +#include + +int main() { + ASSERT_EQ(1, 0 == 0); + ASSERT_EQ(0, 123 != 123); + ASSERT_EQ(1, 123 != 456); + ASSERT_EQ(0, 123 == 124); + ASSERT_EQ(1, 123 < 567); + ASSERT_EQ(1, 123 <= 567); + ASSERT_EQ(1, 123 <= 123); + ASSERT_EQ(0, 123 < 123); +} diff --git a/tests/comparison_operators.sh b/tests/comparison_operators.sh deleted file mode 100644 index 7bcb689..0000000 --- a/tests/comparison_operators.sh +++ /dev/null @@ -1,14 +0,0 @@ -test_exit_code 0 <<'EOF' -#include "../../helpers.h" - -int main() { - ASSERT_EQ(1, 0 == 0); - ASSERT_EQ(0, 123 != 123); - ASSERT_EQ(1, 123 != 456); - ASSERT_EQ(0, 123 == 124); - ASSERT_EQ(1, 123 < 567); - ASSERT_EQ(1, 123 <= 567); - ASSERT_EQ(1, 123 <= 123); - ASSERT_EQ(0, 123 < 123); -} -EOF diff --git a/tests/function_basics.c b/tests/function_basics.c new file mode 100644 index 0000000..f02384c --- /dev/null +++ b/tests/function_basics.c @@ -0,0 +1,49 @@ +#include + +int foo() { + int i; + int ret; + i = 0; + ret = 0; + for (i = 0; i < 100; i = i + 1) { + if (i == 12) { + break; + } + ret = ret + i; + } + return ret; +} + +int f(int a, int b, int c, int d, int e, int f) { + return a; +} + +int f2(int a, int b, int c, int d, int e, int f) { + return b; +} + +int f3(int a, int b, int c, int d, int e, int f) { + return c; +} + +int f4(int a, int b, int c, int d, int e, int f) { + return d; +} + +int f5(int a, int b, int c, int d, int e, int f) { + return e; +} + +int f6(int a, int b, int c, int d, int e, int f) { + return f; +} + +int main() { + ASSERT_EQ(66, foo()); + ASSERT_EQ(10, 10 * f(1, 2, 3, 4, 5, 6)); + ASSERT_EQ(20, 10 * f2(1, 2, 3, 4, 5, 6)); + ASSERT_EQ(30, 10 * f3(1, 2, 3, 4, 5, 6)); + ASSERT_EQ(40, 10 * f4(1, 2, 3, 4, 5, 6)); + ASSERT_EQ(50, 10 * f5(1, 2, 3, 4, 5, 6)); + ASSERT_EQ(60, 10 * f6(1, 2, 3, 4, 5, 6)); +} diff --git a/tests/function_basics.sh b/tests/function_basics.sh deleted file mode 100644 index f064622..0000000 --- a/tests/function_basics.sh +++ /dev/null @@ -1,58 +0,0 @@ -test_exit_code 0 <<'EOF' -#include "../../helpers.h" - -int foo() { - int i; - int ret; - i = 0; - ret = 0; - for (i = 0; i < 100; i = i + 1) { - if (i == 12) { - break; - } - ret = ret + i; - } - return ret; -} - -int f(int a, int b, int c, int d, int e, int f) { - return a; -} - -int f2(int a, int b, int c, int d, int e, int f) { - return b; -} - -int f3(int a, int b, int c, int d, int e, int f) { - return c; -} - -int f4(int a, int b, int c, int d, int e, int f) { - return d; -} - -int f5(int a, int b, int c, int d, int e, int f) { - return e; -} - -int f6(int a, int b, int c, int d, int e, int f) { - return f; -} - -int main() { - ASSERT_EQ(66, foo()); - ASSERT_EQ(10, 10 * f(1, 2, 3, 4, 5, 6)); - ASSERT_EQ(20, 10 * f2(1, 2, 3, 4, 5, 6)); - ASSERT_EQ(30, 10 * f3(1, 2, 3, 4, 5, 6)); - ASSERT_EQ(40, 10 * f4(1, 2, 3, 4, 5, 6)); - ASSERT_EQ(50, 10 * f5(1, 2, 3, 4, 5, 6)); - ASSERT_EQ(60, 10 * f6(1, 2, 3, 4, 5, 6)); -} -EOF - -touch expected -test_diff <<'EOF' -int main() { - return 0; -} -EOF diff --git a/tests/global_variables.sh b/tests/global_variables.sh index 8de1483..fac386d 100644 --- a/tests/global_variables.sh +++ b/tests/global_variables.sh @@ -15,7 +15,7 @@ int main() { EOF test_exit_code 0 <<'EOF' -#include "../../helpers.h" +#include int a; int* b = &a; diff --git a/tests/helpers.sh b/tests/helpers.sh index 6e0c51c..b8de8a9 100644 --- a/tests/helpers.sh +++ b/tests/helpers.sh @@ -1,7 +1,7 @@ function test_exit_code() { cat > main.c - "$ducc" "${CFLAGS:-}" -o a.out main.c + "$ducc" "${CFLAGS:-}" -I ../../../tests -o a.out main.c set +e ./a.out exit_code=$? @@ -18,7 +18,7 @@ function test_exit_code() { function test_diff() { cat > main.c - "$ducc" "${CFLAGS:-}" -o a.out main.c + "$ducc" "${CFLAGS:-}" -I ../../../tests -o a.out main.c if [[ ! -f input ]]; then touch input fi @@ -37,7 +37,7 @@ function test_compile_error() { cat > main.c set +e - "$ducc" "${CFLAGS:-}" main.c > /dev/null 2> output + "$ducc" "${CFLAGS:-}" -I ../../../tests main.c > /dev/null 2> output exit_code=$? set -e @@ -53,14 +53,14 @@ function test_compile_error() { function test_cpp() { cat > main.c - "$ducc" "${CFLAGS:-}" -E main.c > output + "$ducc" "${CFLAGS:-}" -I ../../../tests -E main.c > output diff -u -Z expected output } function test_example() { filename="../../../examples/$1.c" - "$ducc" "${CFLAGS:-}" -o a.out "$filename" + "$ducc" "${CFLAGS:-}" -I ../../../tests -o a.out "$filename" if [[ ! -f input ]]; then touch input fi diff --git a/tests/if_else.c b/tests/if_else.c new file mode 100644 index 0000000..a444f2e --- /dev/null +++ b/tests/if_else.c @@ -0,0 +1,19 @@ +#include + +int main() { + int result1; + if (1) { + result1 = 12; + } else { + result1 = 34; + } + ASSERT_EQ(12, result1); + + int result2; + if (1 + 1 != 2) { + result2 = 12; + } else { + result2 = 34; + } + ASSERT_EQ(34, result2); +} diff --git a/tests/if_else.sh b/tests/if_else.sh deleted file mode 100644 index f1da0d1..0000000 --- a/tests/if_else.sh +++ /dev/null @@ -1,21 +0,0 @@ -test_exit_code 0 <<'EOF' -#include "../../helpers.h" - -int main() { - int result1; - if (1) { - result1 = 12; - } else { - result1 = 34; - } - ASSERT_EQ(12, result1); - - int result2; - if (1 + 1 != 2) { - result2 = 12; - } else { - result2 = 34; - } - ASSERT_EQ(34, result2); -} -EOF diff --git a/tests/local_variables.c b/tests/local_variables.c new file mode 100644 index 0000000..ac63f04 --- /dev/null +++ b/tests/local_variables.c @@ -0,0 +1,38 @@ +#include + +int main() { + int foo; + foo = 42; + ASSERT_EQ(42, foo); + + int bar; + bar = 28; + ASSERT_EQ(70, foo + bar); + + int a1; + int a2; + int a3; + int a4; + int a5; + int a6; + int a7; + int a8; + int a9; + + a1 = 1; + a2 = 2; + a3 = 3; + a4 = 4; + a5 = 5; + a6 = 6; + a7 = 7; + a8 = 8; + a9 = 9; + + ASSERT_EQ(45, a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + 0); + + int d = 2, e = d, f = d + e; + ASSERT_EQ(2, d); + ASSERT_EQ(2, e); + ASSERT_EQ(4, f); +} diff --git a/tests/local_variables.sh b/tests/local_variables.sh deleted file mode 100644 index 674899d..0000000 --- a/tests/local_variables.sh +++ /dev/null @@ -1,56 +0,0 @@ -test_exit_code 0 <<'EOF' -#include "../../helpers.h" - -int main() { - int foo; - foo = 42; - ASSERT_EQ(42, foo); - - int bar; - bar = 28; - ASSERT_EQ(70, foo + bar); - - int a1; - int a2; - int a3; - int a4; - int a5; - int a6; - int a7; - int a8; - int a9; - - a1 = 1; - a2 = 2; - a3 = 3; - a4 = 4; - a5 = 5; - a6 = 6; - a7 = 7; - a8 = 8; - a9 = 9; - - ASSERT_EQ(45, - a1 + - a2 + - a3 + - a4 + - a5 + - a6 + - a7 + - a8 + - a9 + - 0); -} -EOF - -test_exit_code 0 <<'EOF' -#include "../../helpers.h" - -int main() { - int d = 2, e = d, f = d + e; - ASSERT_EQ(2, d); - ASSERT_EQ(2, e); - ASSERT_EQ(4, f); -} -EOF diff --git a/tests/number_literals.c b/tests/number_literals.c new file mode 100644 index 0000000..c28e4e3 --- /dev/null +++ b/tests/number_literals.c @@ -0,0 +1,8 @@ +#include + +int main() { + ASSERT_EQ(0, 0); + ASSERT_EQ(291, 0x123); + ASSERT_EQ(3405691582, 0xcafebabe); + ASSERT_EQ(436, 0664); +} diff --git a/tests/number_literals.sh b/tests/number_literals.sh deleted file mode 100644 index e96308a..0000000 --- a/tests/number_literals.sh +++ /dev/null @@ -1,10 +0,0 @@ -test_exit_code 0 <<'EOF' -#include "../../helpers.h" - -int main() { - ASSERT_EQ(0, 0); - ASSERT_EQ(291, 0x123); - ASSERT_EQ(3405691582, 0xcafebabe); - ASSERT_EQ(436, 0664); -} -EOF diff --git a/tests/recursive_functions.c b/tests/recursive_functions.c new file mode 100644 index 0000000..b81824a --- /dev/null +++ b/tests/recursive_functions.c @@ -0,0 +1,13 @@ +#include + +int fib(int n) { + if (n <= 1) { + return 1; + } else { + return fib(n - 1) + fib(n - 2); + } +} + +int main() { + ASSERT_EQ(89, fib(10)); +} diff --git a/tests/recursive_functions.sh b/tests/recursive_functions.sh deleted file mode 100644 index 709cfbe..0000000 --- a/tests/recursive_functions.sh +++ /dev/null @@ -1,15 +0,0 @@ -test_exit_code 0 <<'EOF' -#include "../../helpers.h" - -int fib(int n) { - if (n <= 1) { - return 1; - } else { - return fib(n - 1) + fib(n - 2); - } -} - -int main() { - ASSERT_EQ(89, fib(10)); -} -EOF diff --git a/tests/run.sh b/tests/run.sh index 1003e87..0835d9a 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -5,17 +5,26 @@ export ducc="../../../build/$BIN" export testcase=$1 export tmp_dir="tests/tmp/$testcase" -test_file="tests/$testcase.sh" +c_test_file="tests/$testcase.c" +sh_test_file="tests/$testcase.sh" -if [[ ! -f "$test_file" ]]; then +if [[ -f "$c_test_file" ]]; then + source tests/helpers.sh + + echo "$c_test_file" + mkdir -p "$tmp_dir" + cd "$tmp_dir" + test_exit_code < "../../../$c_test_file" + cd "../../.." +elif [[ -f "$sh_test_file" ]]; then + source tests/helpers.sh + + echo "$sh_test_file" + mkdir -p "$tmp_dir" + cd "$tmp_dir" + source "../../../$sh_test_file" + cd "../../.." +else echo "no test $testcase" >&2 exit 1 fi - -source tests/helpers.sh - -echo "$test_file" -mkdir -p "$tmp_dir" -cd "$tmp_dir" -source "../../../$test_file" -cd "../../.." diff --git a/tests/switch.sh b/tests/switch.sh index d5d3dae..e77e250 100644 --- a/tests/switch.sh +++ b/tests/switch.sh @@ -1,7 +1,7 @@ #!/bin/bash test_exit_code 0 <<'EOF' -#include "../../helpers.h" +#include int main() { int x = 2; @@ -24,7 +24,7 @@ int main() { EOF test_exit_code 0 <<'EOF' -#include "../../helpers.h" +#include int main() { int x = 5; @@ -47,7 +47,7 @@ int main() { EOF test_exit_code 0 <<'EOF' -#include "../../helpers.h" +#include int main() { int x = 2; @@ -68,7 +68,7 @@ int main() { EOF test_exit_code 0 <<'EOF' -#include "../../helpers.h" +#include int main() { int x = 1; @@ -96,7 +96,7 @@ int main() { EOF test_exit_code 0 <<'EOF' -#include "../../helpers.h" +#include int main() { int a = 3; @@ -120,7 +120,7 @@ int main() { EOF test_exit_code 0 <<'EOF' -#include "../../helpers.h" +#include int main() { int x = 2; @@ -148,7 +148,7 @@ int main() { EOF test_exit_code 0 <<'EOF' -#include "../../helpers.h" +#include int main() { int x = 1; @@ -172,7 +172,7 @@ int main() { EOF test_exit_code 0 <<'EOF' -#include "../../helpers.h" +#include int main() { int x = 10; diff --git a/tests/ternary_operator.c b/tests/ternary_operator.c new file mode 100644 index 0000000..1f46dbe --- /dev/null +++ b/tests/ternary_operator.c @@ -0,0 +1,6 @@ +#include + +int main() { + ASSERT_EQ(2, 1 ? 2 : 3); + ASSERT_EQ(5, 0 ? 4 : 5); +} diff --git a/tests/ternary_operator.sh b/tests/ternary_operator.sh deleted file mode 100644 index c63f581..0000000 --- a/tests/ternary_operator.sh +++ /dev/null @@ -1,8 +0,0 @@ -test_exit_code 0 <<'EOF' -#include "../../helpers.h" - -int main() { - ASSERT_EQ(2, 1 ? 2 : 3); - ASSERT_EQ(5, 0 ? 4 : 5); -} -EOF -- cgit v1.2.3-70-g09d2