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) { task main_exception(type: RunKonanTest) {
// TODO: cannot currently check the output because the exact stacktrace strings are unpredictable. // TODO: cannot currently check the output because the exact stacktrace strings are unpredictable.
// goldValue = "Uncaught exception from Kotlin's main: Throwable\n" // goldValue = "Uncaught exception from Kotlin's main: Throwable\n"
expectedExitStatus = 1
source = "runtime/basic/main_exception.kt" source = "runtime/basic/main_exception.kt"
} }
+9 -5
View File
@@ -18,19 +18,23 @@ OBJ_GETTER(setupArgs, int argc, char** argv) {
} }
//--- main --------------------------------------------------------------------// //--- main --------------------------------------------------------------------//
extern "C" void Konan_start(const ObjHeader* ); extern "C" KInt Konan_start(const ObjHeader* );
int main(int argc, char** argv) { int main(int argc, char** argv) {
RuntimeState* state = InitRuntime(); RuntimeState* state = InitRuntime();
if (state != nullptr) { if (state == nullptr) {
return 2;
}
KInt exitStatus;
{
ObjHolder args; ObjHolder args;
setupArgs(argc, argv, args.slot()); setupArgs(argc, argv, args.slot());
Konan_start(args.obj()); exitStatus = Konan_start(args.obj());
} }
DeinitRuntime(state); DeinitRuntime(state);
// Yes, we have to follow Java convention and return zero. return exitStatus;
return 0;
} }
+5 -2
View File
@@ -3,16 +3,19 @@ import konan.internal.ExportForCppRuntime
external fun main(args: Array<String>) external fun main(args: Array<String>)
@ExportForCppRuntime @ExportForCppRuntime
private fun Konan_start(args: Array<String>) { private fun Konan_start(args: Array<String>): Int {
try { try {
// This is kotlin program main entry point // This is kotlin program main entry point
main(args) main(args)
// Successfully finished:
return 0
} catch (e: Throwable) { } catch (e: Throwable) {
// TODO: may be add some more info. // TODO: may be add some more info.
print("Uncaught exception from Kotlin's main: ") print("Uncaught exception from Kotlin's main: ")
e.printStackTrace() e.printStackTrace()
// TODO: should exit with non-zero code. return 1
} }
} }