| 1 | package Test::Run::Output; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 14 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 14 | extends('Test::Run::Base'); | |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 14 | has 'NoTty' => (is => "rw", isa => "Bool"); | |||||||||||||||||||||||||||||||||
| 11 | 14 | has 'Verbose' => (is => "rw", isa => "Bool"); | |||||||||||||||||||||||||||||||||
| 12 | 14 | has 'last_test_print' => (is => "rw", isa => "Num"); | |||||||||||||||||||||||||||||||||
| 13 | 14 | has 'ml' => (is => "rw", isa => "Str"); | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | Test::Run::Output - Base class for outputting messages to the user in a test | ||||||||||||||||||||||||||||||||||
| 18 | harmess. | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | =cut | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | =head2 BUILD | ||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | For Moose. | ||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | sub BUILD | ||||||||||||||||||||||||||||||||||
| 31 | 51 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 32 | 51 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | 51 | $self->Verbose($args->{Verbose}); | |||||||||||||||||||||||||||||||||
| 35 | 51 | $self->NoTty($args->{NoTty}); | |||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 51 | return 0; | |||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | sub _print_message_raw | ||||||||||||||||||||||||||||||||||
| 41 | 323 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_print_message_raw: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 42 | 323 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||||||||
| 43 | 323 | print $msg; | |||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | =head2 $self->print_message($msg) | ||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | Emits $msg followed by a newline. | ||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | =cut | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | sub print_message | ||||||||||||||||||||||||||||||||||
| 54 | 131 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
print_message: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 55 | 131 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 131 | $self->_print_message_raw($msg); | |||||||||||||||||||||||||||||||||
| 58 | 131 | $self->_newline(); | |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | 131 | return; | |||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | sub _newline | ||||||||||||||||||||||||||||||||||
| 64 | 131 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_newline: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 65 | 131 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 66 | 131 | $self->_print_message_raw("\n"); | |||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | =head2 $self->print_ml($msg) | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | If ml() is defined, print it and $msg. If not - do nothing. | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | sub print_ml | ||||||||||||||||||||||||||||||||||
| 76 | 80 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
print_ml: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 77 | 80 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | 80 | ▶ | if ($self->ml()) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||
| 81 | 1 | $self->_print_message_raw($self->ml . $msg); | |||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 80 | return; | |||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | =head2 $self->print_leader({filename => $filename, width => $width}) | ||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | Prints the file leader for $filename and $width. | ||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | =cut | ||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||
| 93 | sub print_leader | ||||||||||||||||||||||||||||||||||
| 94 | 60 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
print_leader: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 95 | 60 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | $self->_print_message_raw( | ||||||||||||||||||||||||||||||||||
| 98 | $self->_mk_leader( | ||||||||||||||||||||||||||||||||||
| 99 | $args->{filename}, | ||||||||||||||||||||||||||||||||||
| 100 | $args->{width} | ||||||||||||||||||||||||||||||||||
| 101 | ) | ||||||||||||||||||||||||||||||||||
| 102 | 60 | ); | |||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||
| 105 | =head2 $self->print_ml_less($msg) | ||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | Calls print_ml() with $msg every second or less. | ||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | # Print updates only once per second. | ||||||||||||||||||||||||||||||||||
| 112 | sub print_ml_less | ||||||||||||||||||||||||||||||||||
| 113 | 180 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
print_ml_less: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 114 | 180 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||
| 116 | 180 | my $now = CORE::time(); | |||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | 180 | ▶ | if ($self->last_test_print() != $now) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||||||||
| 120 | 52 | $self->print_ml(@args); | |||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | 52 | $self->last_test_print($now); | |||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | sub _mk_leader__calc_te | ||||||||||||||||||||||||||||||||||
| 127 | 60 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_mk_leader__calc_te: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||
| 128 | 60 | my ($self, $te) = @_; | |||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||
| 130 | 60 | chomp($te); | |||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | 60 | $te =~ s{\.\w+$}{}; | |||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||
| 134 | 60 | ▶ | if ($^O eq "VMS") | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 135 | { | ||||||||||||||||||||||||||||||||||
| 136 | 0 | $te =~ s{^.*\.t\.}{\[.t.}s; | |||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||
| 139 | 60 | return $te; | |||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | sub _is_terminal | ||||||||||||||||||||||||||||||||||
| 143 | 59 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_is_terminal: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||
| 144 | 59 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | 59 | ▶ | return ((-t STDOUT) && (! $self->NoTty()) && (! $self->Verbose())); | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
-t STDOUT && !$self->NoTty && !$self->Verbose
-t STDOUT and not $self->NoTty
MC/DC0%0/3
-t STDOUT && !$self->NoTty && !$self->Verbose
-t STDOUT
not $self->NoTty
!$self->Verbose
Truth table25%1/4
A and not(B) && not(C)
A= -t STDOUTB= not $self->NoTtyC= !$self->Verbose
| |||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | sub _mk_leader__calc_leader | ||||||||||||||||||||||||||||||||||
| 150 | 60 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_mk_leader__calc_leader: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 151 | 60 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | 60 | my $te = $self->_mk_leader__calc_te($args->{te}); | |||||||||||||||||||||||||||||||||
| 154 | 60 | return ("$te" . ' ' . ('.' x ($args->{width} - length($te) - 2 )) . ' '); | |||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||
| 157 | sub _mk_leader__calc_ml | ||||||||||||||||||||||||||||||||||
| 158 | 60 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_mk_leader__calc_ml: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 159 | 60 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | 60 | ▶ | if (! $self->_is_terminal()) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||||||||
| 163 | 59 | return ""; | |||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||
| 165 | else | ||||||||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||||||||
| 167 | 1 | return "\r" . (' ' x 77) . "\r" . $args->{leader}; | |||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||
| 171 | =head2 B<_mk_leader> | ||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||
| 173 | my($leader, $ml) = $self->_mk_leader($test_file, $width); | ||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||
| 175 | Generates the 't/foo........' leader for the given C<$test_file> as well | ||||||||||||||||||||||||||||||||||
| 176 | as a similar version which will overwrite the current line (by use of | ||||||||||||||||||||||||||||||||||
| 177 | \r and such). C<$ml> may be empty if Test::Run doesn't think | ||||||||||||||||||||||||||||||||||
| 178 | you're on TTY. | ||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||
| 180 | The C<$width> is the width of the "yada/blah.." string. | ||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||
| 184 | sub _mk_leader | ||||||||||||||||||||||||||||||||||
| 185 | 60 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_mk_leader: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 186 | 60 | my ($self, $_pre_te, $width) = @_; | |||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | 60 | my $leader = $self->_mk_leader__calc_leader( | |||||||||||||||||||||||||||||||||
| 189 | +{ te => $_pre_te, width => $width, } | ||||||||||||||||||||||||||||||||||
| 190 | ); | ||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||
| 192 | 60 | $self->ml( | |||||||||||||||||||||||||||||||||
| 193 | $self->_mk_leader__calc_ml( | ||||||||||||||||||||||||||||||||||
| 194 | { leader => $leader, width => $width, }, | ||||||||||||||||||||||||||||||||||
| 195 | ) | ||||||||||||||||||||||||||||||||||
| 196 | ); | ||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||
| 198 | 60 | return $leader; | |||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||
| 201 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||
| 203 | Shlomi Fish, L<http://www.shlomifish.org/> | ||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||
| 205 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||
| 207 | This file is licensed under the MIT X11 License: | ||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||
| 209 | http://www.opensource.org/licenses/mit-license.php | ||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||
| 211 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||
| 213 | L<Test::Run::Obj>, L<Test::Run::Core>, L<Test::Run::Plugin::CmdLine::Output>. | ||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||
| 215 | =cut | ||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||
| 217 | 14 | 1; | |||||||||||||||||||||||||||||||||