Skip to content

Commit

Permalink
Avoid hack involving early return in Test.pm6
Browse files Browse the repository at this point in the history
Instead, implement it with an exception. This means that we could lift
the restriction on needing a `Callable` that can be returned from in
this place too; unfortunately, we have spectests that make sure it
fails, so simply lifting the restriction will cause failures in the
spectest for released language versions. For now, just preserve the
existing behavior, but in a way that won't break our more accurate
tracking of which things need return handlers.
  • Loading branch information
jnthn committed Apr 9, 2019
1 parent 165f918 commit 84b0e38
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/Test.pm6
Expand Up @@ -64,6 +64,8 @@ our sub todo_output is rw {

proto sub plan ($?, Cool :$skip-all) {*}

my class X::SubtestsSkipped is Exception {}

multi sub plan (Cool:D :skip-all($reason)!) {
_init_io() unless $output;
$output.say: $indents ~ "1..0 # Skipped: $reason";
Expand All @@ -81,7 +83,7 @@ multi sub plan (Cool:D :skip-all($reason)!) {

$done_testing_has_been_run = 1;
$num_of_tests_failed = $num_of_tests_planned = $num_of_tests_run = 0;
nqp::throwpayloadlexcaller(nqp::const::CONTROL_RETURN, True);
X::SubtestsSkipped.new.throw
}

# "plan 'no_plan';" is now "plan *;"
Expand Down Expand Up @@ -414,7 +416,14 @@ multi sub subtest(&subtests, $desc = '') is export {
$subtest_callable_type = &subtests.WHAT;
$indents ~= " ";
$subtest_level++;
subtests();
{
subtests();
CATCH {
when X::SubtestsSkipped {
# Subtests all skipped
}
}
}
$subtest_level--;
done-testing() if nqp::iseq_i($done_testing_has_been_run,0);
my $status = $num_of_tests_failed == 0
Expand Down Expand Up @@ -601,7 +610,7 @@ sub throws-like($code, $ex_type, $reason?, *%matcher) is export {
$code()
} else {
$msg = "'$code' died";
EVAL $code, context => CALLER::CALLER::CALLER::CALLER::;
EVAL $code, context => CALLER::CALLER::CALLER::CALLER::CALLER::;
}
flunk $msg;
skip 'Code did not die, can not check exception', 1 + %matcher.elems;
Expand Down

0 comments on commit 84b0e38

Please sign in to comment.