aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--tests/arithmetic_operators.c9
-rw-r--r--tests/arithmetic_operators.sh11
-rw-r--r--tests/assignment_operators.c (renamed from tests/assignment_operators.sh)10
-rw-r--r--tests/bitwise_operators.c (renamed from tests/bitwise_operators.sh)4
-rw-r--r--tests/bool_type.c (renamed from tests/bool_type.sh)4
-rw-r--r--tests/char_literals.c (renamed from tests/char_literals.sh)4
-rw-r--r--tests/comparison_operators.c (renamed from tests/comparison_operators.sh)4
-rw-r--r--tests/function_basics.c (renamed from tests/function_basics.sh)11
-rw-r--r--tests/global_variables.sh2
-rw-r--r--tests/helpers.sh10
-rw-r--r--tests/if_else.c (renamed from tests/if_else.sh)4
-rw-r--r--tests/local_variables.c (renamed from tests/local_variables.sh)22
-rw-r--r--tests/number_literals.c (renamed from tests/number_literals.sh)4
-rw-r--r--tests/recursive_functions.c (renamed from tests/recursive_functions.sh)4
-rw-r--r--tests/run.sh29
-rw-r--r--tests/switch.sh16
-rw-r--r--tests/ternary_operator.c (renamed from tests/ternary_operator.sh)4
17 files changed, 58 insertions, 94 deletions
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 <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);
+}
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.sh b/tests/assignment_operators.c
index 9b3a33e..1edc574 100644
--- a/tests/assignment_operators.sh
+++ b/tests/assignment_operators.c
@@ -1,12 +1,13 @@
-test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
int i = 0;
- for (; i < 5; i += 1) {}
+ for (; i < 5; i += 1) {
+ }
ASSERT_EQ(5, i);
- for (i = 5; i >= 0; i -= 1);
+ for (i = 5; i >= 0; i -= 1)
+ ;
ASSERT_EQ(-1, i);
int x = 123;
@@ -61,4 +62,3 @@ int main() {
k >>= 3;
ASSERT_EQ(8, k);
}
-EOF
diff --git a/tests/bitwise_operators.sh b/tests/bitwise_operators.c
index f683099..e8a5619 100644
--- a/tests/bitwise_operators.sh
+++ b/tests/bitwise_operators.c
@@ -1,5 +1,4 @@
-test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
ASSERT_EQ(123, 0 | 123);
@@ -37,4 +36,3 @@ int main() {
ASSERT_EQ(-1, ~(x & 0));
ASSERT_EQ(-16, ~(x | 5));
}
-EOF
diff --git a/tests/bool_type.sh b/tests/bool_type.c
index d18fd30..7313410 100644
--- a/tests/bool_type.sh
+++ b/tests/bool_type.c
@@ -1,5 +1,4 @@
-test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
bool b1 = true, b0 = false;
@@ -9,4 +8,3 @@ int main() {
ASSERT_EQ(1, sizeof(b0));
ASSERT_EQ(1, sizeof(bool));
}
-EOF
diff --git a/tests/char_literals.sh b/tests/char_literals.c
index 64b130b..cc592ff 100644
--- a/tests/char_literals.sh
+++ b/tests/char_literals.c
@@ -1,5 +1,4 @@
-test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
ASSERT_EQ(97, 'a');
@@ -24,4 +23,3 @@ int main() {
ASSERT_EQ(27, '\e');
}
-EOF
diff --git a/tests/comparison_operators.sh b/tests/comparison_operators.c
index 7bcb689..7e0600d 100644
--- a/tests/comparison_operators.sh
+++ b/tests/comparison_operators.c
@@ -1,5 +1,4 @@
-test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
ASSERT_EQ(1, 0 == 0);
@@ -11,4 +10,3 @@ int main() {
ASSERT_EQ(1, 123 <= 123);
ASSERT_EQ(0, 123 < 123);
}
-EOF
diff --git a/tests/function_basics.sh b/tests/function_basics.c
index f064622..f02384c 100644
--- a/tests/function_basics.sh
+++ b/tests/function_basics.c
@@ -1,5 +1,4 @@
-test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int foo() {
int i;
@@ -48,11 +47,3 @@ int main() {
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 <helpers.h>
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.sh b/tests/if_else.c
index f1da0d1..a444f2e 100644
--- a/tests/if_else.sh
+++ b/tests/if_else.c
@@ -1,5 +1,4 @@
-test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
int result1;
@@ -18,4 +17,3 @@ int main() {
}
ASSERT_EQ(34, result2);
}
-EOF
diff --git a/tests/local_variables.sh b/tests/local_variables.c
index 674899d..ac63f04 100644
--- a/tests/local_variables.sh
+++ b/tests/local_variables.c
@@ -1,5 +1,4 @@
-test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
int foo;
@@ -30,27 +29,10 @@ int main() {
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"
+ ASSERT_EQ(45, a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + 0);
-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.sh b/tests/number_literals.c
index e96308a..c28e4e3 100644
--- a/tests/number_literals.sh
+++ b/tests/number_literals.c
@@ -1,5 +1,4 @@
-test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
ASSERT_EQ(0, 0);
@@ -7,4 +6,3 @@ int main() {
ASSERT_EQ(3405691582, 0xcafebabe);
ASSERT_EQ(436, 0664);
}
-EOF
diff --git a/tests/recursive_functions.sh b/tests/recursive_functions.c
index 709cfbe..b81824a 100644
--- a/tests/recursive_functions.sh
+++ b/tests/recursive_functions.c
@@ -1,5 +1,4 @@
-test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int fib(int n) {
if (n <= 1) {
@@ -12,4 +11,3 @@ int fib(int n) {
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 <helpers.h>
int main() {
int x = 2;
@@ -24,7 +24,7 @@ int main() {
EOF
test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
int x = 5;
@@ -47,7 +47,7 @@ int main() {
EOF
test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
int x = 2;
@@ -68,7 +68,7 @@ int main() {
EOF
test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
int x = 1;
@@ -96,7 +96,7 @@ int main() {
EOF
test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
int a = 3;
@@ -120,7 +120,7 @@ int main() {
EOF
test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
int x = 2;
@@ -148,7 +148,7 @@ int main() {
EOF
test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
int x = 1;
@@ -172,7 +172,7 @@ int main() {
EOF
test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
int x = 10;
diff --git a/tests/ternary_operator.sh b/tests/ternary_operator.c
index c63f581..1f46dbe 100644
--- a/tests/ternary_operator.sh
+++ b/tests/ternary_operator.c
@@ -1,8 +1,6 @@
-test_exit_code 0 <<'EOF'
-#include "../../helpers.h"
+#include <helpers.h>
int main() {
ASSERT_EQ(2, 1 ? 2 : 3);
ASSERT_EQ(5, 0 ? 4 : 5);
}
-EOF