| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Basset::Test::More; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | #Basset::Test::More, copyright and (c) 2004 James A Thomason III | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | $VERSION = '1.00'; | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 2 |  |  | 2 |  | 33539 | use Basset::Test; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 79 |  | 
| 8 |  |  |  |  |  |  | @ISA = qw(Basset::Test); | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 2 |  |  | 2 |  | 16 | use Test::Builder; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 43 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 2 |  |  | 2 |  | 10 | use strict; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 63 |  | 
| 13 | 2 |  |  | 2 |  | 9 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 1018 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =pod | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | =head1 Basset::Test::More | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | Basset::Test::More is a drop-in replacement for Basset::Test. Change the test type in your conf | 
| 20 |  |  |  |  |  |  | file for a global change. | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | Basset::Test will actually test all of your functions and spit out the output. Basset::Test::More | 
| 23 |  |  |  |  |  |  | will generate (to STDOUT) a .t file suitable using Test::More suitable for running through Test::Harness. | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | =cut | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | sub test { | 
| 28 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 29 | 0 |  |  |  |  |  | my $class = shift; | 
| 30 | 0 |  |  |  |  |  | my $superclasses = shift; | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 0 |  |  |  |  |  | $self->singleton(Test::Builder->new); | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 0 |  |  |  |  |  | $self->_output([]); | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 0 |  |  |  |  |  | $self->singleton->no_header(1); | 
| 37 | 0 |  |  |  |  |  | $self->singleton->no_ending(1); | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 0 | 0 |  |  |  |  | my @t = $self->get_all_tests($class, $superclasses) or return; | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 0 |  |  |  |  |  | my $plan = $self->plan(); | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 0 |  |  |  |  |  | print "use Test::More tests => $plan;\n"; | 
| 44 | 0 |  |  |  |  |  | print "use $class;\n"; | 
| 45 | 0 |  |  |  |  |  | print "package $class;\n"; | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 0 |  |  |  |  |  | $self->generate_t($class, @t); | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | sub generate_t { | 
| 51 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 52 | 0 |  |  |  |  |  | my $class = shift; | 
| 53 | 0 |  |  |  |  |  | my @t = @_; | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 0 |  |  |  |  |  | my $tfile = 1; | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | #open (T, ">$tfile") || return $self->error("Could not open t file : $!", "BTM-01"); | 
| 58 | 0 |  |  |  |  |  | open(T, ">-"); | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 0 |  |  |  |  |  | while (@t) { | 
| 61 | 0 |  |  |  |  |  | my $n = shift @t; | 
| 62 | 0 |  |  |  |  |  | my $test = shift (@t); | 
| 63 | 0 | 0 | 0 |  |  |  | if (defined $test && $test =~ /\S/) { | 
| 64 | 0 | 0 |  |  |  |  | next if $test =~ /^\s*#line \d+\s+\w+\s*$/s; | 
| 65 | 0 |  |  |  |  |  | my $t = '{' . $test . '};'; | 
| 66 | 0 |  |  |  |  |  | $t =~ s/__PACKAGE__/$class/g; | 
| 67 | 0 |  |  |  |  |  | $t =~ s/\$test->plan\(.+$//gm; | 
| 68 | 0 |  |  |  |  |  | $t =~ s/\$test->/Test::More::/g; | 
| 69 | 0 |  |  |  |  |  | print T "$t\n"; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  | } | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | #close (T) || return $self->error("Could not close t file : $!", "BTM-02"); | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 0 |  |  |  |  |  | return $tfile; | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | 1; |