From 84b0e38048ff606ebd8515c14f250fc80bd6e53b Mon Sep 17 00:00:00 2001 From: Jonathan Worthington Date: Tue, 9 Apr 2019 15:54:06 +0200 Subject: [PATCH] Avoid hack involving early return in Test.pm6 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. --- lib/Test.pm6 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/Test.pm6 b/lib/Test.pm6 index ff6858393cd..f80249ca2ee 100644 --- a/lib/Test.pm6 +++ b/lib/Test.pm6 @@ -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"; @@ -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 *;" @@ -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 @@ -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;