feat: add support for booleans and comparision operators
This commit is contained in:
@@ -44,6 +44,48 @@ run_test() {
|
||||
echo
|
||||
}
|
||||
|
||||
# --- Helper Function ---
|
||||
run_harness_test() {
|
||||
local src_file="$1"
|
||||
local harness_file="$2"
|
||||
local expected_code="$3"
|
||||
local base_name
|
||||
base_name=$(basename "$src_file" .src)
|
||||
local obj_file="tests/$base_name.o"
|
||||
local exec_file="tests/$base_name"
|
||||
|
||||
echo "--- Running test: $src_file ---"
|
||||
|
||||
# 1. Compile the source file using our compiler
|
||||
echo " [1/4] Compiling..."
|
||||
cargo run --release -- "$src_file" -o "$obj_file" > /dev/null 2>&1
|
||||
|
||||
# 2. Link the object file with the system linker (gcc)
|
||||
echo " [2/4] Linking with gcc..."
|
||||
gcc "$obj_file" "$harness_file" -o "$exec_file"
|
||||
|
||||
# 3. Run the executable
|
||||
echo " [3/4] Running..."
|
||||
set +e
|
||||
./"$exec_file"
|
||||
local actual_code=$?
|
||||
set -e
|
||||
|
||||
# 4. Check the exit code
|
||||
echo " [4/4] Verifying exit code..."
|
||||
if [ "$actual_code" -eq "$expected_code" ]; then
|
||||
echo "SUCCESS: Exit code is $actual_code as expected."
|
||||
else
|
||||
echo "FAILURE: Expected exit code $expected_code, but got $actual_code."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Clean up generated files
|
||||
rm "$obj_file" "$exec_file"
|
||||
echo "------------------------------------"
|
||||
echo
|
||||
}
|
||||
|
||||
# --- Test Cases ---
|
||||
|
||||
# Test a simple positive return value.
|
||||
@@ -53,4 +95,7 @@ run_test "tests/return_42.src" 42
|
||||
# so -69 (i8) wraps around to 187.
|
||||
run_test "tests/return_neg_69.src" 187
|
||||
|
||||
# Test boolean operations.
|
||||
run_harness_test "tests/booleans.src" "tests/booleans.c" 0
|
||||
|
||||
echo "All end-to-end tests passed!"
|
||||
Reference in New Issue
Block a user