#!/usr/bin/expect
|
|
|
|
set SUGAR_EXECUTABLE $::env(SUGAR_EXECUTABLE)
|
|
set BUILD_NAME 005.
|
|
|
|
proc abort {reason} {
|
|
puts "test failed $reason"
|
|
exit 1
|
|
}
|
|
|
|
spawn -noecho $SUGAR_EXECUTABLE tests/005/exit-with-3.mol tests/005/library.mol lex-all merge-all
|
|
expect {
|
|
error { abort "failed to parse" }
|
|
eof { abort "cannot find the symbol main in lexed output" }
|
|
main
|
|
}
|
|
expect eof
|
|
lassign [wait] pid spawnid os_error_flag value
|
|
if {$value != 0} {
|
|
abort "compiler crashed"
|
|
}
|
|
|
|
spawn -noecho $SUGAR_EXECUTABLE tests/005/exit-with-3.mol tests/005/library.mol lex-all merge-all parse
|
|
expect {
|
|
error { abort "failed to parse" }
|
|
eof { abort "cannot find the main procedure" }
|
|
main
|
|
}
|
|
expect eof
|
|
lassign [wait] pid spawnid os_error_flag value
|
|
if {$value != 0} {
|
|
abort "compiler crashed"
|
|
}
|
|
|
|
spawn -noecho $SUGAR_EXECUTABLE tests/005/exit-with-3.mol tests/005/library.mol lex-all merge-all parse
|
|
expect {
|
|
error { abort "failed to parse" }
|
|
eof { abort "cannot find the exit-syscall-number procedure" }
|
|
exit-syscall-number
|
|
}
|
|
expect eof
|
|
lassign [wait] pid spawnid os_error_flag value
|
|
if {$value != 0} {
|
|
abort "compiler crashed"
|
|
}
|
|
|
|
|
|
spawn -noecho $SUGAR_EXECUTABLE tests/005/exit-with-3.mol lex tests/005/library.mol lex merge parse /tmp/sugar.generated.$BUILD_NAME generate assemble
|
|
expect {
|
|
error { abort "failed to compile" }
|
|
eof { abort "didn't run clang" }
|
|
clang
|
|
}
|
|
expect {
|
|
error { abort "failed to link" }
|
|
eof { abort "didn't run ld" }
|
|
ld
|
|
}
|
|
expect eof
|
|
lassign [wait] pid spawnid os_error_flag value
|
|
if {$value != 0} {
|
|
abort "compiler crashed"
|
|
}
|
|
|
|
spawn -noecho /tmp/sugar.generated.$BUILD_NAME
|
|
expect {
|
|
error { abort "failed to compile" }
|
|
eof { abort "didn't output" }
|
|
Hello
|
|
}
|
|
expect eof
|
|
lassign [wait] pid spawnid os_error_flag value
|
|
if {$value != 3} {
|
|
abort "executable didn't return exit code 3 but $value instead"
|
|
}
|