Skip to content

Commit

Permalink
Restructure test-c-codegen/
Browse files Browse the repository at this point in the history
  • Loading branch information
hirrolot committed Jan 5, 2025
1 parent e2890a1 commit 5dd8f04
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 24 deletions.
4 changes: 0 additions & 4 deletions test-c-codegen/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
main.mz
mazeppa.h
sds*
main
panic
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "mazeppa.h"
#include "../mazeppa.h"

int main(void) {
(void)MZ_OP2(MZ_INT(I, 32, 1), div, MZ_INT(I, 32, 0));
Expand Down
9 changes: 9 additions & 0 deletions test-c-codegen/execution-panic/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

$CC main.c ../sds.c -lgc -o main $COMMON_OPTIONS
if ! ./main 2>&1 >/dev/null \
| grep -q 'Execution panic: "out of range"'; then
echo "Expected a panic."
fi
1 change: 1 addition & 0 deletions test-c-codegen/mazeppa.h
1 change: 1 addition & 0 deletions test-c-codegen/sds.c
1 change: 1 addition & 0 deletions test-c-codegen/sds.h
1 change: 1 addition & 0 deletions test-c-codegen/sdsalloc.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "mazeppa.h"
#include "../mazeppa.h"

mz_Value run(void);

Expand Down
1 change: 1 addition & 0 deletions test-c-codegen/self-interpreter/program.mz
12 changes: 12 additions & 0 deletions test-c-codegen/self-interpreter/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# The fact that the self-interpreter uses almost all the language features makes
# it a good example for testing.

set -e

cat program.mz \
| ../../scripts/mazeppa.sh translate --language C --entry run \
| $CC -c -o program.o $COMMON_OPTIONS -xc -I.. -
$CC main.c program.o ../sds.c -lgc -o main $COMMON_OPTIONS
./main
24 changes: 6 additions & 18 deletions test-c-codegen/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,16 @@ fi
common_options="-Wall -Werror -Wno-unused-variable -Wno-infinite-recursion"
common_options="$common_options -std=gnu11"

cp -r ../c/deps/sds* .

# All the examples must at least compile with no errors.
for example in ../examples/*/; do
cat "${example}main.mz" \
| ../scripts/mazeppa.sh translate --language C --entry run \
--dump-header-to . \
| $CC -c -o /dev/null $common_options -xc -
done

# Compile and execute the self-interpreter example (convenient for testing).
cp ../examples/self-interpreter/main.mz main.mz
cat main.mz \
| ../scripts/mazeppa.sh translate --language C --entry run \
--dump-header-to . \
| $CC -c -o program.o $common_options -xc -
$CC main.c program.o sds.c -lgc -o main $common_options
./main

# Make sure that run-time panics work as expected.
$CC panic.c sds.c -lgc -o panic $common_options
if ! ./panic 2>&1 >/dev/null \
| grep -q 'Execution panic: "out of range"'; then
echo "Expected a panic."
fi
for test_dir in */; do
echo "Testing '$test_dir'..."
cd $test_dir
COMMON_OPTIONS=$common_options ./test.sh
cd ..
done

0 comments on commit 5dd8f04

Please sign in to comment.