blib/lib/Test/Unit/HarnessUnit.pm

filter: Statementstmt 100% 7 / 7 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 10 / 10 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Test/Unit/Failure.pm ↑ Summary blib/lib/Test/Unit/Runner.pm »
1 package Test::Unit::HarnessUnit;
2 BEGIN {
3 2 ▶ $Test::Unit::HarnessUnit::VERSION = '0.25_1325'; # added by dist-tools/SetVersion.pl
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5 # this is a test runner which outputs in the same
6 # format that Test::Harness expects.
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use base qw(Test::Unit::Runner);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 use Test::Unit::TestSuite;
12 use Test::Unit::Loader;
13  
14 sub new {
15 my $class = shift;
16 my ($filehandle) = @_;
17 # should really use the IO::Handle package here.
18 # this is very ugly.
19 $filehandle = \*STDOUT unless $filehandle;
20 bless { _Print_stream => $filehandle }, $class;
21 }
22  
23 sub print_stream {
24 my $self = shift;
25 return $self->{_Print_stream};
26 }
27  
28 sub _print {
29 my $self = shift;
30 my (@args) = @_;
31 $self->{_Print_stream}->print( @args);
32 }
33  
34 sub start_test {
35 my $self=shift;
36 my $test=shift;
37 }
38  
39 sub not_ok {
40 my $self = shift;
41 my ($test, $exception) = @_;
42 $self->_print("\nnot ok ERROR ",
43 $test->name(),
44 "\n$exception\n");
45 }
46  
47 sub ok {
48 my $self = shift;
49 my ($test) = @_;
50 $self->_print("ok PASS " . $test->name() . "\n");
51 }
52  
53 sub add_error {
54 my $self = shift;
55 $self->not_ok(@_);
56 }
57
58 sub add_failure {
59 my $self = shift;
60 $self->not_ok(@_);
61 }
62  
63 sub add_pass {
64 my $self = shift;
65 $self->ok(@_);
66 }
67  
68 sub end_test {
69 my $self = shift;
70 my ($test) = @_;
71 }
72  
73 sub do_run {
74 my $self = shift;
75 my ($suite) = @_;
76 my $result = $self->create_test_result();
77 $result->add_listener($self);
78 $suite->run($result, $self);
79 }
80  
81 sub main {
82 my $self = shift;
83 my $a_test_runner = __PACKAGE__->new;
84 $a_test_runner->start(@_);
85 }
86  
87 sub run {
88 my $self = shift;
89 my ($class) = @_;
90 my $a_test_runner = Test::Unit::TestRunner->new();
91 if ($class->isa("Test::Unit::Test")) {
92 $a_test_runner->do_run($class, 0);
93 } else {
94 $a_test_runner->do_run(Test::Unit::TestSuite->new($class), 0);
95 }
96 }
97  
98 sub start {
99 my $self = shift;
100 my (@args) = @_;
101  
102 my $test_case = "";
103 my $wait = 0;
104 my $suite = Test::Unit::Loader::load(@args);
105 if ($suite) {
106 my $count=$suite->count_test_cases();
107 $self->_print("STARTING TEST RUN\n1..$count\n");
108 $self->do_run($suite);
109 exit(0);
110 } else {
111 $self->_print("Invalid argument to test runner: $args[0]\n");
112 exit(1);
113 }
114 }
115  
116 1;
117 __END__
« blib/lib/Test/Unit/Failure.pm ↑ Summary blib/lib/Test/Unit/Runner.pm »