Skip to content
Browse files

fix main.c so that we check the is_error flag and only show an error …

…message and backtrace if we have an error. This fixes TT #1907. Add two tests for the test cause provided by Coke++ to show that it does indeed have an exit code of 3, but that it produces no error output
  • Loading branch information...
1 parent 8765817 commit b3af8c93d7ecf8a6723f97bd51bec1a162bafeaf @Whiteknight Whiteknight committed Dec 28, 2010
Showing with 20 additions and 7 deletions.
  1. +6 −5 frontend/parrot/main.c
  2. +3 −1 src/embed/api.c
  3. +11 −1 t/op/exit.t
View
11 frontend/parrot/main.c
@@ -186,13 +186,14 @@ show_last_error_and_exit(Parrot_PMC interp)
Parrot_Int exit_code, is_error;
Parrot_PMC exception;
- if (!(Parrot_api_get_result(interp, &is_error, &exception, &exit_code, &errmsg) &&
- Parrot_api_get_exception_backtrace(interp, exception, &backtrace))) {
+ if (!Parrot_api_get_result(interp, &is_error, &exception, &exit_code, &errmsg))
exit(EXIT_FAILURE);
- }
-
- print_parrot_string(interp, stderr, errmsg, 1);
+ if (is_error) {
+ if (!Parrot_api_get_exception_backtrace(interp, exception, &backtrace))
+ exit(EXIT_FAILURE);
+ print_parrot_string(interp, stderr, errmsg, 1);
print_parrot_string(interp, stderr, backtrace, 0);
+ }
exit(exit_code);
}
View
4 src/embed/api.c
@@ -65,7 +65,9 @@ Parrot_api_get_result(Parrot_PMC interp_pmc, ARGOUT(Parrot_Int *is_error),
*errmsg = STRINGNULL;
}
else {
- *is_error = !interp->exit_code;
+ STRING * const severity_str = Parrot_str_new(interp, "severity", 0);
+ INTVAL severity = VTABLE_get_integer_keyed_str(interp, *exception, severity_str);
+ *is_error = (severity != EXCEPT_exit);
*errmsg = VTABLE_get_string(interp, *exception);
}
interp->final_exception = PMCNULL;
View
12 t/op/exit.t
@@ -6,7 +6,7 @@ use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 7;
+use Parrot::Test tests => 9;
=head1 NAME
@@ -72,6 +72,16 @@ pir_exit_code_is( <<'CODE', 2, "pir exit code isn't exception type" );
.end
CODE
+my $exit_3_snippet = <<'CODE';
+.sub main :main
+ exit 3
+.end
+CODE
+
+pir_exit_code_is($exit_3_snippet, 3, "exit 3 causes exit code 3");
+pir_error_output_like($exit_3_snippet, '/^\s*$/', "exit opcode causes no error message to print");
+
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4

0 comments on commit b3af8c9

Please sign in to comment.
Something went wrong with that request. Please try again.