| 1 | package Test::Group::Plan; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Test::Group::Plan - test plans for test groups | ||||||||||
| 8 | |||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||
| 10 | |||||||||||
| 11 | use Test::Group; | ||||||||||
| 12 | use Test::Group::Plan; | ||||||||||
| 13 | |||||||||||
| 14 | test_plan 3, mytest => sub { | ||||||||||
| 15 | ok 1, "one"; | ||||||||||
| 16 | ok 2, "two"; | ||||||||||
| 17 | ok 3, "three"; | ||||||||||
| 18 | }; | ||||||||||
| 19 | |||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||
| 21 | |||||||||||
| 22 | This module is an extension for L<Test::Group>. It allows you to | ||||||||||
| 23 | declare the number of tests that a particular group will run. | ||||||||||
| 24 | |||||||||||
| 25 | If you are not already familiar with L<Test::Group> now would be | ||||||||||
| 26 | a good time to go take a look. | ||||||||||
| 27 | |||||||||||
| 28 | By default, L<Test::Group> doesn't care how many tests you run within | ||||||||||
| 29 | each group. This is convenient, but sometimes you know how many tests | ||||||||||
| 30 | should be run, and a plan provides a useful extra check that your test | ||||||||||
| 31 | script is doing what you think it is. | ||||||||||
| 32 | |||||||||||
| 33 | =head1 EXPORTS | ||||||||||
| 34 | |||||||||||
| 35 | The following function is exported by default. | ||||||||||
| 36 | |||||||||||
| 37 | =head2 test_plan ($plan, $name, $groupsub) | ||||||||||
| 38 | |||||||||||
| 39 | As the test() function exported by L<Test::Group>, but with an additional | ||||||||||
| 40 | I<$plan> parameter. The value of I<$plan> must be numeric. | ||||||||||
| 41 | |||||||||||
| 42 | An extra test will be run after I<$groupsub> returns, to check that | ||||||||||
| 43 | the number of tests run was as expected. Note that you should B<not> | ||||||||||
| 44 | add 1 to the plan to account for this extra test. | ||||||||||
| 45 | |||||||||||
| 46 | =cut | ||||||||||
| 47 | |||||||||||
| 48 | 1 | ▶ | use Exporter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 49 | 1 | ▶ | use vars qw(@ISA @EXPORT $VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 1 | @ISA = qw(Exporter); | |||||||||
| 51 | 1 | @EXPORT = qw(test_plan); | |||||||||
| 52 | 1 | $VERSION = '0.01'; | |||||||||
| 53 | |||||||||||
| 54 | 1 | ▶ | use Test::Builder; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 55 | 1 | ▶ | use Test::Group (); # keep this namespace clean | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 56 | |||||||||||
| 57 | 20 | ▶ | sub test_plan ($$&) { | ||||||||
|
Subroutine
test_plan: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 58 | 20 | my $plan = shift; | |||||||||
| 59 | |||||||||||
| 60 | 24 | ▶ | Test::Group::next_test_plugin { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 61 | 24 | my $next = shift; | |||||||||
| 62 | |||||||||||
| 63 | 24 | my $before = Test::Group::_Runner->current->subtests; | |||||||||
| 64 | 24 | $next->(); | |||||||||
| 65 | 24 | my $after = Test::Group::_Runner->current->subtests; | |||||||||
| 66 | 24 | my $count = $after - $before; | |||||||||
| 67 | |||||||||||
| 68 | 24 | my $T = Test::Builder->new; | |||||||||
| 69 | 24 | ▶ | unless ($T->ok($count == $plan, "group test plan")) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 12 | $T->diag(" group planned $plan tests but ran $count"); | |||||||||
| 71 | } | ||||||||||
| 72 | 20 | }; | |||||||||
| 73 | |||||||||||
| 74 | 20 | goto &Test::Group::test; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | =head1 SEE ALSO | ||||||||||
| 78 | |||||||||||
| 79 | L<Test::Group> | ||||||||||
| 80 | |||||||||||
| 81 | =head1 AUTHORS | ||||||||||
| 82 | |||||||||||
| 83 | Nick Cleaton <ncleaton@cpan.org> | ||||||||||
| 84 | |||||||||||
| 85 | Dominique Quatravaux <domq@cpan.org> | ||||||||||
| 86 | |||||||||||
| 87 | =head1 LICENSE | ||||||||||
| 88 | |||||||||||
| 89 | Copyright (c) 2009 by Nick Cleaton and Dominique Quatravaux | ||||||||||
| 90 | |||||||||||
| 91 | This library is free software; you can redistribute it and/or modify | ||||||||||
| 92 | it under the same terms as Perl itself, either Perl version 5.8.1 or, | ||||||||||
| 93 | at your option, any later version of Perl 5 you may have available. | ||||||||||
| 94 | |||||||||||
| 95 | =cut | ||||||||||
| 96 | |||||||||||
| 97 | 1 | 1; | |||||||||