runtime: use exitStatus == 1 if main finished with exception

Also update the corresponding test.
This commit is contained in:
Svyatoslav Scherbina
2017-03-10 13:02:53 +07:00
committed by SvyatoslavScherbina
parent 051f42667c
commit 13bbd7af81
3 changed files with 15 additions and 7 deletions
+1
View File
@@ -1141,6 +1141,7 @@ task spread_operator_0(type: RunKonanTest) {
task main_exception(type: RunKonanTest) {
// TODO: cannot currently check the output because the exact stacktrace strings are unpredictable.
// goldValue = "Uncaught exception from Kotlin's main: Throwable\n"
expectedExitStatus = 1
source = "runtime/basic/main_exception.kt"
}
+9 -5
View File
@@ -18,19 +18,23 @@ OBJ_GETTER(setupArgs, int argc, char** argv) {
}
//--- main --------------------------------------------------------------------//
extern "C" void Konan_start(const ObjHeader* );
extern "C" KInt Konan_start(const ObjHeader* );
int main(int argc, char** argv) {
RuntimeState* state = InitRuntime();
if (state != nullptr) {
if (state == nullptr) {
return 2;
}
KInt exitStatus;
{
ObjHolder args;
setupArgs(argc, argv, args.slot());
Konan_start(args.obj());
exitStatus = Konan_start(args.obj());
}
DeinitRuntime(state);
// Yes, we have to follow Java convention and return zero.
return 0;
return exitStatus;
}
+5 -2
View File
@@ -3,16 +3,19 @@ import konan.internal.ExportForCppRuntime
external fun main(args: Array<String>)
@ExportForCppRuntime
private fun Konan_start(args: Array<String>) {
private fun Konan_start(args: Array<String>): Int {
try {
// This is kotlin program main entry point
main(args)
// Successfully finished:
return 0
} catch (e: Throwable) {
// TODO: may be add some more info.
print("Uncaught exception from Kotlin's main: ")
e.printStackTrace()
// TODO: should exit with non-zero code.
return 1
}
}