1 package TAP::Formatter::Console::Session;
4 use TAP::Formatter::Session;
6 use vars qw($VERSION @ISA);
8 @ISA = qw(TAP::Formatter::Session);
13 my @CLOSURE_BINDING = qw( header result clear_for_close close_test );
15 for my $method (@CLOSURE_BINDING) {
19 return ( $self->{_closures} ||= $self->_closures )->{$method}
27 TAP::Formatter::Console::Session - Harness output delegate for default console output
39 This provides console orientated output formatting for TAP::Harness.
43 sub _get_output_result {
47 { test => sub { $_->is_test && !$_->is_ok },
50 { test => sub { $_->is_test && $_->has_skip },
56 { test => sub { $_->is_test && $_->has_todo },
61 my $formatter = $self->formatter;
62 my $parser = $self->parser;
64 return $formatter->_colorizer
67 for my $col (@color_map) {
69 if ( $col->{test}->() ) {
70 $formatter->_set_colors( @{ $col->{colors} } );
74 $formatter->_output( $self->_format_for_output($result) );
75 $formatter->_set_colors('reset');
78 $formatter->_output( $self->_format_for_output(shift) );
85 my $parser = $self->parser;
86 my $formatter = $self->formatter;
87 my $pretty = $formatter->_format_name( $self->name );
88 my $show_count = $self->show_count;
90 my $really_quiet = $formatter->really_quiet;
91 my $quiet = $formatter->quiet;
92 my $verbose = $formatter->verbose;
93 my $directives = $formatter->directives;
94 my $failures = $formatter->failures;
95 my $comments = $formatter->comments;
97 my $output_result = $self->_get_output_result;
99 my $output = '_output';
101 my $newline_printed = 0;
103 my $last_status_printed = 0;
107 $formatter->_output($pretty)
108 unless $really_quiet;
114 if ( $result->is_bailout ) {
115 $formatter->_failure_output(
116 "Bailout called. Further testing stopped: "
117 . $result->explanation
121 return if $really_quiet;
123 my $is_test = $result->is_test;
125 # These are used in close_test - but only if $really_quiet
126 # is false - so it's safe to only set them here unless that
127 # relationship changes.
130 my $planned = $parser->tests_planned || '?';
131 $plan = "/$planned ";
133 $output = $formatter->_get_output_method($parser);
135 if ( $show_count and $is_test ) {
136 my $number = $result->number;
137 my $now = CORE::time;
139 # Print status roughly once per second.
140 # We will always get the first number as a side effect of
141 # $last_status_printed starting with the value 0, which $now
142 # will never be. (Unless someone sets their clock to 1970)
143 if ( $last_status_printed != $now ) {
144 $formatter->$output("\r$pretty$number$plan");
145 $last_status_printed = $now;
151 || ( $is_test && $failures && !$result->is_ok )
152 || ( $comments && $result->is_comment )
153 || ( $directives && $result->has_directive ) )
156 unless ($newline_printed) {
157 $formatter->_output("\n");
158 $newline_printed = 1;
160 $output_result->($result);
161 $formatter->_output("\n");
165 clear_for_close => sub {
167 = ' ' x length( '.' . $pretty . $plan . $parser->tests_run );
168 $formatter->$output("\r$spaces");
172 if ( $show_count && !$really_quiet ) {
173 $self->clear_for_close;
174 $formatter->$output("\r$pretty");
177 # Avoid circular references
178 $self->parser(undef);
179 $self->{_closures} = {};
181 return if $really_quiet;
183 if ( my $skip_all = $parser->skip_all ) {
184 $formatter->_output("skipped: $skip_all\n");
186 elsif ( $parser->has_problems ) {
187 $self->_output_test_failure($parser);
190 my $time_report = '';
191 if ( $formatter->timer ) {
192 my $start_time = $parser->start_time;
193 my $end_time = $parser->end_time;
194 if ( defined $start_time and defined $end_time ) {
195 my $elapsed = $end_time - $start_time;
197 = $self->time_is_hires
198 ? sprintf( ' %8d ms', $elapsed * 1000 )
199 : sprintf( ' %8s s', $elapsed || '<1' );
203 $formatter->_output("ok$time_report\n");
209 =head2 C<< clear_for_close >>
211 =head2 C<< close_test >>