/usr/share/perl5/Test/Unit/TestRunner.pm is in libtest-unit-perl 0.25-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | package Test::Unit::TestRunner;
use strict;
use base qw(Test::Unit::Runner);
use Test::Unit; # for copyright & version number
use Test::Unit::TestSuite;
use Test::Unit::Loader;
use Test::Unit::Result;
use Benchmark;
sub new {
my $class = shift;
my ($filehandle) = @_;
$filehandle = \*STDOUT unless $filehandle;
select((select($filehandle), $| = 1)[0]);
bless { _Print_stream => $filehandle }, $class;
}
sub print_stream {
my $self = shift;
return $self->{_Print_stream};
}
sub _print {
my $self = shift;
my (@args) = @_;
$self->print_stream->print(@args);
}
sub add_error {
my $self = shift;
my ($test, $exception) = @_;
$self->_print("E");
}
sub add_failure {
my $self = shift;
my ($test, $exception) = @_;
$self->_print("F");
}
sub add_pass {
# in this runner passes are ignored.
}
sub do_run {
my $self = shift;
my ($suite, $wait) = @_;
my $result = $self->create_test_result();
$result->add_listener($self);
my $start_time = new Benchmark();
$suite->run($result, $self);
my $end_time = new Benchmark();
$self->print_result($result, $start_time, $end_time);
if ($wait) {
print "<RETURN> to continue"; # go to STDIN any case
<STDIN>;
}
$self->_print("\nTest was not successful.\n")
unless $result->was_successful;
return $result->was_successful;
}
sub end_test {
}
sub main {
my $self = shift;
my $a_test_runner = Test::Unit::TestRunner->new();
$a_test_runner->start(@_);
}
sub print_result {
my $self = shift;
my ($result, $start_time, $end_time) = @_;
my $run_time = timediff($end_time, $start_time);
$self->_print("\n", "Time: ", timestr($run_time), "\n");
$self->print_header($result);
$self->print_errors($result);
$self->print_failures($result);
}
sub print_errors {
my $self = shift;
my ($result) = @_;
return unless my $error_count = $result->error_count();
my $msg = "\nThere " .
($error_count == 1 ?
"was 1 error"
: "were $error_count errors") .
":\n";
$self->_print($msg);
my $i = 0;
for my $e (@{$result->errors()}) {
chomp(my $e_to_str = $e);
$i++;
$self->_print("$i) $e_to_str\n");
$self->_print("\nAnnotations:\n", $e->object->annotations())
if $e->object->annotations();
}
}
sub print_failures {
my $self = shift;
my ($result) = @_;
return unless my $failure_count = $result->failure_count;
my $msg = "\nThere " .
($failure_count == 1 ?
"was 1 failure"
: "were $failure_count failures") .
":\n";
$self->_print($msg);
my $i = 0;
for my $f (@{$result->failures()}) {
chomp(my $f_to_str = $f);
$self->_print("\n") if $i++;
$self->_print("$i) $f_to_str\n");
$self->_print("\nAnnotations:\n", $f->object->annotations())
if $f->object->annotations();
}
}
sub print_header {
my $self = shift;
my ($result) = @_;
if ($result->was_successful()) {
$self->_print("\n", "OK", " (", $result->run_count(), " tests)\n");
} else {
$self->_print("\n", "!!!FAILURES!!!", "\n",
"Test Results:\n",
"Run: ", $result->run_count(),
", Failures: ", $result->failure_count(),
", Errors: ", $result->error_count(),
"\n");
}
}
sub run {
my $self = shift;
my ($class) = @_;
my $a_test_runner = Test::Unit::TestRunner->new();
$a_test_runner->do_run(Test::Unit::TestSuite->new($class), 0);
}
sub run_and_wait {
my $self = shift;
my ($test) = @_;
my $a_test_runner = Test::Unit::TestRunner->new();
$a_test_runner->do_run(Test::Unit::TestSuite->new($test), 1);
}
sub start {
my $self = shift;
my (@args) = @_;
my $test = "";
my $wait = 0;
for (my $i = 0; $i < @args; $i++) {
if ($args[$i] eq "-wait") {
$wait = 1;
} elsif ($args[$i] eq "-v") {
print Test::Unit::COPYRIGHT_SHORT;
} else {
$test = $args[$i];
}
}
if ($test eq "") {
die "Usage: TestRunner.pl [-wait] name, where name is the name of the Test class\n";
}
my $suite = Test::Unit::Loader::load($test);
$self->do_run($suite, $wait);
}
sub start_test {
my $self = shift;
my ($test) = @_;
$self->_print(".");
}
1;
__END__
=head1 NAME
Test::Unit::TestRunner - unit testing framework helper class
=head1 SYNOPSIS
use Test::Unit::TestRunner;
my $testrunner = Test::Unit::TestRunner->new();
$testrunner->start($my_test_class);
=head1 DESCRIPTION
This class is the test runner for the command line style use
of the testing framework.
It is used by simple command line tools like the F<TestRunner.pl>
script provided.
The class needs one argument, which is the name of the class
encapsulating the tests to be run.
=head1 OPTIONS
=over 4
=item -wait
wait for user confirmation between tests
=item -v
version info
=back
=head1 AUTHOR
Copyright (c) 2000-2002, 2005 the PerlUnit Development Team
(see L<Test::Unit> or the F<AUTHORS> file included in this
distribution).
All rights reserved. This program is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.
=head1 SEE ALSO
=over 4
=item *
L<Test::Unit::TestCase>
=item *
L<Test::Unit::Listener>
=item *
L<Test::Unit::TestSuite>
=item *
L<Test::Unit::Result>
=item *
L<Test::Unit::TkTestRunner>
=item *
For further examples, take a look at the framework self test
collection (t::tlib::AllTests).
=back
=cut
|