| 1 | package PerlActor::Runner::Console; | ||
| 2 | use strict; | ||
| 3 | use base 'PerlActor::Runner'; | ||
| 4 | use fields qw( run passed failed aborted failedReport abortedReport started ended ); | ||
| 5 | |||
| 6 | $| = 1; | ||
| 7 | |||
| 8 | use Benchmark; | ||
| 9 | |||
| 10 | #=============================================================================================== | ||
| 11 | # Public Methods | ||
| 12 | #=============================================================================================== | ||
| 13 | |||
| 14 | sub start | ||
| 15 | { | ||
| 16 | my $self = shift; | ||
| 17 | |||
| 18 | $self->_resetCounters(); | ||
| 19 | $self->_resetReports(); | ||
| 20 | $self->_printHeader(); | ||
| 21 | $self->_startClock(); | ||
| 22 | } | ||
| 23 | |||
| 24 | sub end | ||
| 25 | { | ||
| 26 | my $self = shift; | ||
| 27 | |||
| 28 | $self->_stopClock(); | ||
| 29 | |||
| 30 | my $runTime = timediff($self->{ended}, $self->{started}); | ||
| 31 | |||
| 32 | print "\n" . $self->trim(timestr($runTime)); | ||
| 33 | print "\nRun: $self->{run}, Passed: $self->{passed}, Failed: $self->{failed}, Aborted: $self->{aborted}.\n"; | ||
| 34 | |||
| 35 | $self->_printReports($self->{failedReport},'FAILED'); | ||
| 36 | $self->_printReports($self->{abortedReport},'ABORTED'); | ||
| 37 | |||
| 38 | unless ($self->{failed} or $self->{aborted}) | ||
| 39 | { | ||
| 40 | print "\nOK ($self->{passed} scripts)"; | ||
| 41 | } | ||
| 42 | print "\n"; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub _printReports | ||
| 46 | { | ||
| 47 | my $self = shift; | ||
| 48 | my $reports = shift; | ||
| 49 | my $label = shift; | ||
| 50 | |||
| 51 | if (@{$reports}) | ||
| 52 | { | ||
| 53 | print "\n!!!$label!!!\n"; | ||
| 54 | my $count = 0; | ||
| 55 | map { $count++; print "\n$count) $_\n" } @{$reports}; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | sub scriptStarted | ||
| 60 | { | ||
| 61 | my $self = shift; | ||
| 62 | $self->{run}++; | ||
| 63 | } | ||
| 64 | |||
| 65 | sub scriptPassed | ||
| 66 | { | ||
| 67 | my $self = shift; | ||
| 68 | $self->{passed}++; | ||
| 69 | print "."; | ||
| 70 | } | ||
| 71 | |||
| 72 | sub scriptAborted | ||
| 73 | { | ||
| 74 | my ($self, $script, $exception) = @_; | ||
| 75 | $self->{aborted}++; | ||
| 76 | print "E"; | ||
| 77 | $self->_addReport($script, $exception, 'ABORTED', $self->{abortedReport}); | ||
| 78 | } | ||
| 79 | |||
| 80 | sub scriptFailed | ||
| 81 | { | ||
| 82 | my ($self, $script, $exception) = @_; | ||
| 83 | $self->{failed}++; | ||
| 84 | print "F"; | ||
| 85 | $self->_addReport($script, $exception, 'FAILED', $self->{failedReport}); | ||
| 86 | } | ||
| 87 | |||
| 88 | #=============================================================================================== | ||
| 89 | # Protected Methods - Don't even think about calling these from outside the class. | ||
| 90 | #=============================================================================================== | ||
| 91 | |||
| 92 | sub _resetCounters | ||
| 93 | { | ||
| 94 | my $self = shift; | ||
| 95 | $self->{run} = 0; | ||
| 96 | $self->{passed} = 0; | ||
| 97 | $self->{failed} = 0; | ||
| 98 | $self->{aborted} = 0; | ||
| 99 | } | ||
| 100 | |||
| 101 | sub _resetReports | ||
| 102 | { | ||
| 103 | my $self = shift; | ||
| 104 | $self->{failedReport} = []; | ||
| 105 | $self->{abortedReport} = []; | ||
| 106 | } | ||
| 107 | |||
| 108 | sub _addReport | ||
| 109 | { | ||
| 110 | my ($self, $script, $exception, $label, $reportType) = @_; | ||
| 111 | chomp $exception; | ||
| 112 | push @{$reportType}, "$label: '$exception' " . $script->getTraceInfo(); | ||
| 113 | } | ||
| 114 | |||
| 115 | sub _startClock | ||
| 116 | { | ||
| 117 | my $self = shift; | ||
| 118 | $self->{started} = new Benchmark(); | ||
| 119 | } | ||
| 120 | |||
| 121 | sub _stopClock | ||
| 122 | { | ||
| 123 | my $self = shift; | ||
| 124 | $self->{ended} = new Benchmark(); | ||
| 125 | } | ||
| 126 | |||
| 127 | sub _printHeader | ||
| 128 | { | ||
| 129 | print "\nRunning Acceptance Tests\n"; | ||
| 130 | print "========================\n"; | ||
| 131 | } | ||
| 132 | |||
| 133 | # Keep Perl happy. | ||
| 134 | 1; |