From 0ff4735622a22b0630669307a78bced7c20d5bdc Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Sat, 29 Jan 2022 12:31:14 -0500 Subject: Add some tests for local variables --- tests/basics.sh | 0 tests/common.sh | 20 ++++++++++++++++++++ tests/variables.sh | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) mode change 100644 => 100755 tests/basics.sh create mode 100755 tests/variables.sh diff --git a/tests/basics.sh b/tests/basics.sh old mode 100644 new mode 100755 diff --git a/tests/common.sh b/tests/common.sh index 4469874..7c8b5ae 100644 --- a/tests/common.sh +++ b/tests/common.sh @@ -24,4 +24,24 @@ function assert_exit_status() { fi set -e echo -n "." +} + +function assert_exit_status_stdin() { + ./cupcc - + assemble + + set +e + ./a.out + res=$? + if [ $res -ne $1 ] + then + echo "" + echo "----------------------------------" + echo "Test failed: expected $2, got $res" + echo "- Input was:" + echo " \`$1\`" + exit 1 + fi + set -e + echo -n "." } \ No newline at end of file diff --git a/tests/variables.sh b/tests/variables.sh new file mode 100755 index 0000000..94010d7 --- /dev/null +++ b/tests/variables.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +. tests/common.sh + +set -e + +echo -n "- One variable: " +assert_exit_status 'fn main() { let x: int = 45; return 1; }' 1 +assert_exit_status 'fn main() { let x: int = 45; return x; }' 45 +assert_exit_status 'fn main() { let x: int = 45; return x+x; }' 90 +echo " OK" + +echo -n "- Multiple variable: " + +assert_exit_status_stdin 2 <