Skip to content

Commit 823dde3

Browse files
committed
Add a test case for parsing invalid octal numbers
Add a test case with invalid octal numbers to 'tests/driver.sh' to ensure the lexer/parser can detect invalid octal numbers.
1 parent 4b90420 commit 823dde3

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/driver.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,31 @@ function try_output() {
6262
try "$expected" "$expected_output" "$input"
6363
}
6464

65+
# try_compile_error - test shecc with invalid C program
66+
# Usage:
67+
# - try_compile_error invalid_input_code
68+
# compile "invalid_input_code" with shecc so that shecc generates a
69+
# compilation error message.
70+
#
71+
# This function uses shecc to compile invalid code and obtains the exit
72+
# code returned by shecc. The exit code must be a non-zero value to
73+
# indicate that shecc has the ability to parse the invalid code and
74+
# output an error message.
75+
function try_compile_error() {
76+
local input=$(cat)
77+
78+
local tmp_in="$(mktemp --suffix .c)"
79+
local tmp_exe="$(mktemp)"
80+
echo "$input" > "$tmp_in"
81+
"$SHECC" -o "$tmp_exe" "$tmp_in"
82+
local exit_code=$?
83+
84+
if [ 0 == $exit_code ]; then
85+
echo "Error: compilation is passed."
86+
exit 1
87+
fi
88+
}
89+
6590
function items() {
6691
local expected="$1"
6792
local input="$2"
@@ -238,6 +263,14 @@ int main() {
238263
}
239264
EOF
240265

266+
try_compile_error << EOF
267+
int main() {
268+
int a = 03, b = 01118, c = 091;
269+
printf("%d %d %d\n", a, b, c);
270+
return 0;
271+
}
272+
EOF
273+
241274
try_ 1 << EOF
242275
int is_odd(int x);
243276

0 commit comments

Comments
 (0)