summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/sizeof.toc17
-rw-r--r--tests/sizeof_expected2
-rwxr-xr-xtests/test.sh8
3 files changed, 26 insertions, 1 deletions
diff --git a/tests/sizeof.toc b/tests/sizeof.toc
new file mode 100644
index 0000000..0bc806b
--- /dev/null
+++ b/tests/sizeof.toc
@@ -0,0 +1,17 @@
+#include "io.toc", io;
+
+Point3D ::= struct {
+ x, y, z: f32;
+}
+
+calculation ::= fn() int {
+ p: Point3D;
+ (#sizeof Point3D) * (#sizeof typeof p) * (sizeof Point3D) * (sizeof typeof p)
+ * (#alignof Point3D) * (#alignof typeof p) * (alignof Point3D) * (alignof typeof p)
+}
+
+main ::= fn() {
+ x ::= calculation();
+ io.puti(x);
+ io.puti(calculation());
+} \ No newline at end of file
diff --git a/tests/sizeof_expected b/tests/sizeof_expected
new file mode 100644
index 0000000..d93e228
--- /dev/null
+++ b/tests/sizeof_expected
@@ -0,0 +1,2 @@
+5308416
+5308416
diff --git a/tests/test.sh b/tests/test.sh
index 4016151..5e4535a 100755
--- a/tests/test.sh
+++ b/tests/test.sh
@@ -2,6 +2,7 @@
tests='bf
control_flow
+sizeof
arr
arr2
arr3
@@ -30,6 +31,8 @@ compile_c() {
$CC $CFLAGS $EXTRA_FLAGS -Werror -o a.out out.c || exit 1
}
+failed=false
+
do_tests() {
valgrind -q --exit-on-first-error=yes --error-exitcode=1 $TOC "$1.toc" -o out.c || exit 1
for CC in "gcc -O0 -g" "tcc" "clang -O3 -s"; do
@@ -40,7 +43,7 @@ do_tests() {
printf '\x1b[92mpassed!\x1b[0m\n'
else
printf '\x1b[91mfailed!\x1b[0m\n'
- exit 1
+ failed=true
fi
done
}
@@ -49,3 +52,6 @@ for x in $tests; do
done
rm got a.out out.c
+if $failed; then
+ exit 1
+fi