Skip to content

Commit

Permalink
fix main.c so that we check the is_error flag and only show an error …
Browse files Browse the repository at this point in the history
…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
Whiteknight committed Dec 28, 2010
1 parent 8765817 commit b3af8c9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
11 changes: 6 additions & 5 deletions frontend/parrot/main.c
Expand Up @@ -186,13 +186,14 @@ show_last_error_and_exit(Parrot_PMC interp)
Parrot_Int exit_code, is_error; Parrot_Int exit_code, is_error;
Parrot_PMC exception; Parrot_PMC exception;


if (!(Parrot_api_get_result(interp, &is_error, &exception, &exit_code, &errmsg) && if (!Parrot_api_get_result(interp, &is_error, &exception, &exit_code, &errmsg))
Parrot_api_get_exception_backtrace(interp, exception, &backtrace))) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} if (is_error) {

if (!Parrot_api_get_exception_backtrace(interp, exception, &backtrace))
print_parrot_string(interp, stderr, errmsg, 1); exit(EXIT_FAILURE);
print_parrot_string(interp, stderr, errmsg, 1);
print_parrot_string(interp, stderr, backtrace, 0); print_parrot_string(interp, stderr, backtrace, 0);
}


exit(exit_code); exit(exit_code);
} }
Expand Down
4 changes: 3 additions & 1 deletion src/embed/api.c
Expand Up @@ -65,7 +65,9 @@ Parrot_api_get_result(Parrot_PMC interp_pmc, ARGOUT(Parrot_Int *is_error),
*errmsg = STRINGNULL; *errmsg = STRINGNULL;
} }
else { 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); *errmsg = VTABLE_get_string(interp, *exception);
} }
interp->final_exception = PMCNULL; interp->final_exception = PMCNULL;
Expand Down
12 changes: 11 additions & 1 deletion t/op/exit.t
Expand Up @@ -6,7 +6,7 @@ use warnings;
use lib qw( . lib ../lib ../../lib ); use lib qw( . lib ../lib ../../lib );


use Test::More; use Test::More;
use Parrot::Test tests => 7; use Parrot::Test tests => 9;


=head1 NAME =head1 NAME
Expand Down Expand Up @@ -72,6 +72,16 @@ pir_exit_code_is( <<'CODE', 2, "pir exit code isn't exception type" );
.end .end
CODE 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: # Local Variables:
# mode: cperl # mode: cperl
# cperl-indent-level: 4 # cperl-indent-level: 4
Expand Down

0 comments on commit b3af8c9

Please sign in to comment.