| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # This is a makeover of Test::Harness to allow its tests | 
| 2 |  |  |  |  |  |  | # to be retrofitted as unit tests. | 
| 3 |  |  |  |  |  |  | package Test::Unit::UnitHarness; | 
| 4 |  |  |  |  |  |  | BEGIN { | 
| 5 | 2 |  |  | 2 |  | 54 | $Test::Unit::UnitHarness::VERSION = '0.25_1325'; # added by dist-tools/SetVersion.pl | 
| 6 |  |  |  |  |  |  | } | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 2 |  |  | 2 |  | 120 | BEGIN {require 5.002;} | 
| 9 | 2 |  |  | 2 |  | 10 | use base qw(Test::Unit::Runner Test::Unit::Test Exporter); | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 295 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 2 |  |  | 2 |  | 12 | use Config; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 95 |  | 
| 12 | 2 |  |  | 2 |  | 11 | use Carp; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 172 |  | 
| 13 | 2 |  |  | 2 |  | 12 | use Class::Inner; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 49 |  | 
| 14 | 2 |  |  | 2 |  | 17 | use FileHandle; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 16 |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 | 2 |  |  | 2 |  | 1003 | use Test::Unit::Debug qw(debug); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 113 |  | 
| 17 | 2 |  |  | 2 |  | 10 | use Test::Unit::TestCase; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 45 |  | 
| 18 | 2 |  |  | 2 |  | 11 | use Test::Unit::Exception; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 15 |  | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 2 |  |  | 2 |  | 100 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 91 |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 2 |  |  |  |  | 2533 | use vars qw($VERSION $verbose $switches $have_devel_corestack $curtest | 
| 23 | 2 |  |  | 2 |  | 12 | @EXPORT @EXPORT_OK); | 
|  | 2 |  |  |  |  | 2 |  | 
| 24 |  |  |  |  |  |  | $have_devel_corestack = 0; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | # This file was derived from a v1.1502, but that is not the current | 
| 27 |  |  |  |  |  |  | # version number | 
| 28 |  |  |  |  |  |  | # | 
| 29 |  |  |  |  |  |  | # $VERSION = "1.1502"; | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | @EXPORT = qw(&runtests); | 
| 32 |  |  |  |  |  |  | @EXPORT_OK = qw($verbose $switches); | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | $verbose = 0; | 
| 35 |  |  |  |  |  |  | $switches = "-w"; | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | # class and object methods | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub new { | 
| 40 | 0 |  |  | 0 | 0 |  | my $class = shift; | 
| 41 | 0 |  |  |  |  |  | my ($name) = @_; | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 0 |  |  |  |  |  | my @_Tests = (); | 
| 44 | 0 |  |  |  |  |  | my $self = { | 
| 45 |  |  |  |  |  |  | _Tests => \@_Tests, | 
| 46 |  |  |  |  |  |  | _Name => $name, | 
| 47 |  |  |  |  |  |  | _Names => [], | 
| 48 |  |  |  |  |  |  | }; | 
| 49 | 0 |  |  |  |  |  | bless $self, $class; | 
| 50 | 0 |  |  |  |  |  | debug(ref($self) . "::new($name) called\n"); | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 0 |  |  |  |  |  | return $self; | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | sub run { | 
| 56 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 57 | 0 |  |  |  |  |  | my $result = shift; | 
| 58 | 0 |  |  |  |  |  | my $test = $self->{_Name}; | 
| 59 | 0 |  |  |  |  |  | my $fh = new FileHandle; | 
| 60 | 0 |  |  |  |  |  | my $next = 1; | 
| 61 | 0 |  |  |  |  |  | my $max = 0; | 
| 62 | 0 |  |  |  |  |  | my $message = ""; | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | # pass -I flags to children | 
| 65 | 0 |  |  |  |  |  | my $old5lib = $ENV{PERL5LIB}; | 
| 66 | 0 |  |  |  |  |  | local($ENV{'PERL5LIB'}) = join($Config{path_sep}, @INC); | 
| 67 |  |  |  |  |  |  |  | 
| 68 | 0 | 0 |  |  |  |  | if ($^O eq 'VMS') { $switches =~ s/-(\S*[A-Z]\S*)/"-$1"/g } | 
|  | 0 |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 0 | 0 |  |  |  |  | $fh->open($test) or print "can't open $test. $!\n"; | 
| 71 | 0 |  |  |  |  |  | my $first = <$fh>; | 
| 72 | 0 |  |  |  |  |  | my $s = $switches; | 
| 73 | 0 | 0 |  |  |  |  | $s .= q[ "-T"] if $first =~ /^#!.*\bperl.*-\w*T/; | 
| 74 | 0 | 0 |  |  |  |  | $fh->close or print "can't close $test. $!\n"; | 
| 75 | 0 |  |  |  |  |  | my $cmd = "$^X $s $test|"; | 
| 76 | 0 | 0 |  |  |  |  | $cmd = "MCR $cmd" if $^O eq 'VMS'; | 
| 77 | 0 | 0 |  |  |  |  | $fh->open($cmd) or print "can't run $test. $!\n"; | 
| 78 | 0 |  |  |  |  |  | for my $line (<$fh>) { | 
| 79 | 0 | 0 |  |  |  |  | print $line if $verbose; | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 0 | 0 | 0 |  |  |  | if ($line =~ /^1\.\.([0-9]+)/) { | 
|  |  | 0 |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | # Not supported in Result - It's needed!!! | 
| 83 |  |  |  |  |  |  | #$result->plan($1); | 
| 84 | 0 |  |  |  |  |  | $next = 1; | 
| 85 | 0 |  |  |  |  |  | $max = $1; | 
| 86 | 0 |  |  |  |  |  | $message = ""; | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  | elsif ($max && $line =~ /^(not\s+)?ok\b/) { | 
| 89 | 0 |  |  |  |  |  | my $this = $next; | 
| 90 | 0 | 0 |  |  |  |  | if ($line =~ /^not ok\s*(\d*)/) { | 
|  |  | 0 |  |  |  |  |  | 
| 91 | 0 | 0 |  |  |  |  | $this = $1 if $1 > 0; | 
| 92 | 0 |  |  |  |  |  | my $testcase = new Test::Unit::TestCase("$test case $this"); | 
| 93 | 0 |  |  |  |  |  | $result->start_test($testcase); | 
| 94 | 0 |  |  |  |  |  | $result->add_failure( | 
| 95 |  |  |  |  |  |  | Test::Unit::UnitHarness::TestCase->new("$test case $this"), | 
| 96 |  |  |  |  |  |  | Test::Unit::UnitHarness::Exception->new($message) | 
| 97 |  |  |  |  |  |  | ); | 
| 98 | 0 |  |  |  |  |  | $result->end_test($testcase); | 
| 99 | 0 |  |  |  |  |  | $message = ""; | 
| 100 |  |  |  |  |  |  | } | 
| 101 |  |  |  |  |  |  | elsif ($line =~ /^ok\s*(\d*)/) { | 
| 102 | 0 | 0 |  |  |  |  | $this = $1 if $1; | 
| 103 | 0 |  |  |  |  |  | my $testcase = | 
| 104 |  |  |  |  |  |  | Test::Unit::UnitHarness::TestCase->new("$test case $this"); | 
| 105 | 0 |  |  |  |  |  | $result->start_test($testcase); | 
| 106 | 0 |  |  |  |  |  | $result->add_pass($testcase); | 
| 107 | 0 |  |  |  |  |  | $result->end_test($testcase); | 
| 108 | 0 |  |  |  |  |  | $message = ""; | 
| 109 |  |  |  |  |  |  | } | 
| 110 | 0 |  |  |  |  |  | $next++; | 
| 111 |  |  |  |  |  |  | } | 
| 112 |  |  |  |  |  |  | else { | 
| 113 |  |  |  |  |  |  | # this is the message, not the medium... | 
| 114 |  |  |  |  |  |  | # this wasnt part of the Test::Harness protocol, so it | 
| 115 |  |  |  |  |  |  | # must be output from the program. Collect this, it might | 
| 116 |  |  |  |  |  |  | # prove useful! | 
| 117 | 0 |  |  |  |  |  | $message .= $line; | 
| 118 |  |  |  |  |  |  | } | 
| 119 |  |  |  |  |  |  | } | 
| 120 | 0 |  |  |  |  |  | $fh->close;             # must close to reap child resource values | 
| 121 | 0 | 0 |  |  |  |  | if ($^O eq 'VMS') { | 
| 122 | 0 | 0 |  |  |  |  | if (defined $old5lib) { | 
| 123 | 0 |  |  |  |  |  | $ENV{PERL5LIB} = $old5lib; | 
| 124 |  |  |  |  |  |  | } else { | 
| 125 | 0 |  |  |  |  |  | delete $ENV{PERL5LIB}; | 
| 126 |  |  |  |  |  |  | } | 
| 127 |  |  |  |  |  |  | } | 
| 128 |  |  |  |  |  |  | } | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | sub name { | 
| 131 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 132 | 0 |  |  |  |  |  | return $self->{_Name}; | 
| 133 |  |  |  |  |  |  | } | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | sub names { | 
| 136 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 137 | 0 |  |  |  |  |  | return $self->{_Names}; | 
| 138 |  |  |  |  |  |  | } | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | sub add_test { | 
| 141 | 0 |  |  | 0 | 0 |  | croak "This is suite is not mutable."; | 
| 142 |  |  |  |  |  |  | } | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | sub add_test_method { | 
| 145 | 0 |  |  | 0 | 0 |  | croak "This suite is not mutable."; | 
| 146 |  |  |  |  |  |  | } | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | sub count_test_cases { | 
| 149 | 0 |  |  | 0 | 0 |  | return 0; | 
| 150 |  |  |  |  |  |  | } | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | sub to_string { | 
| 153 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 154 | 0 |  |  |  |  |  | return $self->{_Name}; | 
| 155 |  |  |  |  |  |  | } | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | sub warning { | 
| 158 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 159 | 0 |  |  |  |  |  | my ($message) = @_; | 
| 160 |  |  |  |  |  |  | return Class::Inner->new( | 
| 161 |  |  |  |  |  |  | parent => 'Test::Unit::TestCase', | 
| 162 | 0 |  |  | 0 |  |  | methods => { run_test => sub { (shift)->fail($message) } }, | 
| 163 | 0 |  |  |  |  |  | args => ['warning'], | 
| 164 |  |  |  |  |  |  | ); | 
| 165 |  |  |  |  |  |  | } | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | package Test::Unit::UnitHarness::TestCase; | 
| 168 | 2 |  |  | 2 |  | 14 | use base qw(Test::Unit::TestCase); | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 304 |  | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | sub run_test { | 
| 171 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 172 | 0 |  |  |  |  |  | my $class = ref($self); | 
| 173 | 0 |  |  |  |  |  | my $method = $self->name(); | 
| 174 | 0 |  |  |  |  |  | $self->fail("This test is not restartable"); | 
| 175 |  |  |  |  |  |  | } | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | package Test::Unit::UnitHarness::Exception; | 
| 178 | 2 |  |  | 2 |  | 12 | use base qw(Test::Unit::Exception); | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 167 |  | 
| 179 | 2 |  |  | 2 |  | 10 | use strict; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 309 |  | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | sub new { | 
| 182 | 0 |  |  | 0 |  |  | my $class = shift; | 
| 183 | 0 |  |  |  |  |  | my ($message) = @_; | 
| 184 | 0 |  |  |  |  |  | my $stacktrace = ''; | 
| 185 |  |  |  |  |  |  |  | 
| 186 | 0 | 0 |  |  |  |  | $message = '' unless defined($message); | 
| 187 | 0 |  |  |  |  |  | $stacktrace = $class . ": Output from external test\n" | 
| 188 |  |  |  |  |  |  | . $message . "\n"; | 
| 189 |  |  |  |  |  |  |  | 
| 190 | 0 |  |  |  |  |  | bless { stacktrace => $stacktrace }, $class; | 
| 191 |  |  |  |  |  |  | } | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | sub stacktrace { | 
| 194 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 195 | 0 |  |  |  |  |  | return $self->{stacktrace}; | 
| 196 |  |  |  |  |  |  | } | 
| 197 |  |  |  |  |  |  |  | 
| 198 |  |  |  |  |  |  | 1; | 
| 199 |  |  |  |  |  |  |  | 
| 200 |  |  |  |  |  |  | __END__ |