Updated patch (replaces previous) which does the right thing when you don't call done_testing in planless mode. Thanks pmurias++ for spotting that.
On Thu, Jul 23, 2009 at 12:38 PM, perl6 via RT<perl6-bugs-follo...@perl.org> wrote: > Greetings, > > This message has been automatically generated in response to the > creation of a trouble ticket regarding: > "[PATCH] Test.pm planless testing support update", > a summary of which appears below. > > There is no need to reply to this message right now. Your ticket has been > assigned an ID of [perl #67810]. > > Please include the string: > > [perl #67810] > > in the subject line of all future correspondence about this issue. To do so, > you may reply to this message. > > Thank you, > perl6-bugs-follo...@perl.org > > ------------------------------------------------------------------------- > Following IRC discussion on 23rd of July 2009, this patch removes the > need to call 'plan', and adds done_testing. > > Should work (and seems to work) seamlessly with numbered test files > using the usual format (with or without an explicit call to > done_testing). > > May not handle all possible failure cases entirely elegantly. > >
From d1b4a9b5dbe57e775bf1fd6c5f3689169eefd989 Mon Sep 17 00:00:00 2001 From: Matthew Walton <matt...@matthew-walton.co.uk> Date: Thu, 23 Jul 2009 12:32:59 +0100 Subject: [PATCH] Updated Test.pm planless testing support. Omit your call to plan, and call done_testing when all tests have run. --- Test.pm | 40 ++++++++++++++++++++++++---------------- 1 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Test.pm b/Test.pm index 72517d0..237c4ff 100644 --- a/Test.pm +++ b/Test.pm @@ -11,13 +11,15 @@ our $num_of_tests_failed = 0; our $todo_upto_test_num = 0; our $todo_reason = ''; our $num_of_tests_planned; -our $no_plan; +our $no_plan = 1; our $die_on_fail; our $*WARNINGS = 0; -# for running the test suite multiple times in the same process -our $testing_started; +## If done_testing hasn't been run when we hit our END block, we need to know +## so that it can be run. This allows compatibility with old tests that use +## plans and don't call done_testing. +our $done_testing_has_been_run = 0; ## test functions @@ -28,14 +30,14 @@ sub die_on_fail($fail=1) { } # "plan 'no_plan';" is now "plan *;" +# It is also the default if nobody calls plan at all multi sub plan(Whatever $plan) is export(:DEFAULT) { $no_plan = 1; } multi sub plan($number_of_tests) is export(:DEFAULT) { - $testing_started = 1; - $num_of_tests_planned = $number_of_tests; + $no_plan = 0; say '1..' ~ $number_of_tests; } @@ -212,7 +214,6 @@ sub eval_exception($code) { } sub proclaim($cond, $desc) { - $testing_started = 1; $num_of_tests_run = $num_of_tests_run + 1; unless $cond { @@ -234,26 +235,33 @@ sub proclaim($cond, $desc) { return $cond; } -END { - # until END blocks can access compile-time symbol tables of outer scopes, - # we need these declarations - our $testing_started; - our $num_of_tests_planned; - our $num_of_tests_run; - our $num_of_tests_failed; - our $no_plan; +sub done_testing() is export(:DEFAULT) { + our $done_testing_has_been_run; + + $done_testing_has_been_run = 1; if $no_plan { $num_of_tests_planned = $num_of_tests_run; say "1..$num_of_tests_planned"; } - if ($testing_started and $num_of_tests_planned != $num_of_tests_run) { ##Wrong quantity of tests + if ($num_of_tests_planned != $num_of_tests_run) { ##Wrong quantity of tests diag("Looks like you planned $num_of_tests_planned tests, but ran $num_of_tests_run"); } - if ($testing_started and $num_of_tests_failed) { + if ($num_of_tests_failed) { diag("Looks like you failed $num_of_tests_failed tests of $num_of_tests_run"); } } +END { + our $done_testing_has_been_run; + our $no_plan; + + ## In planned mode, people don't necessarily expect to have to call done_testing + ## So call it for them if they didn't + if !$done_testing_has_been_run && !$no_plan { + done_testing; + } +} + # vim: ft=perl6 -- 1.6.0.4