1#!/usr/bin/perl
2
3package Test::TAP::Model::File::Visual;
4use base qw/Test::TAP::Model::File/;
5
6use strict;
7use warnings;
8
9use Test::TAP::Model::Colorful;
10use Test::TAP::Model::Subtest::Visual;
11use URI::file;
12
13sub subtest_class { "Test::TAP::Model::Subtest::Visual" }
14
15sub desc_string {
16	my $self = shift;
17	$self->{_desc_string} = shift if @_;
18	$self->{_desc_string} ||= "";
19}
20
21sub cases {
22	my $self = shift;
23	return $self->SUPER::cases(@_) unless wantarray;
24
25	my @ret = $self->SUPER::cases(@_);
26	return @ret if @ret;
27
28	# if there are no tests, return a stub that represents the whole file
29	return $self->subtest_class->new({
30		type => "test",
31		ok => $self->ok,
32		skip => $self->skipped,
33		line => "stub"
34	});
35}
36
37sub str_status {
38	my $self = shift;
39	return "SKIPPED" if $self->skipped;
40	return "BAILED OUT" if $self->bailed_out;
41
42	return "OK"
43		if $self->ok
44		and $self->actual_cases == $self->planned
45		and $self->actual_cases > 0;
46
47	return "FAILED";
48}
49
50sub link { URI::file->new($_[0]->name) }
51
52sub case_rows {
53	my $self = shift;
54	my @cases = $self->cases;
55	my @ret;
56
57	my $rows = int(.9 + @cases / 50) || 1;
58	my $per_row = int(.9 + @cases / $rows);
59
60	push @ret, { cases => [ splice(@cases, 0, $per_row) ] } while @cases;
61
62	\@ret;
63}
64
65__PACKAGE__
66
67__END__
68
69=pod
70
71=head1 NAME
72
73Test::TAP::Model::File::Visual - A test file with additional display oriented
74methods.
75
76=head1 SYNOPSIS
77
78	See the template.
79
80=head1 DESCRIPTION
81
82This module is a subclass of L<Test::TAP::Model::File> that provides some
83methods that ease display.
84
85It also inherits from L<Test::TAP::Model::Colorful>, which
86provides additional methods.
87
88=head1 METHODS
89
90=over 4
91
92=item cases
93
94An overridden version of L<Test::TAP::Model::File/cases> which will return a single stub case if the case list is actually empty.
95
96=item str_status
97
98A string, "OK" or "FAILED"
99
100=item link
101
102Just the name of the test. Should be overridden to contain a proper path.
103
104=item case_rows
105
106The test's test cases, split into rows close to 50 elements in size.
107
108The structure returned is:
109
110
111	[ { cases => [ case, case, ... ] }, { cases => [ ... ] }, ... ];
112
113=item subtest_class
114
115This method overrides L<Test::TAP::Model::File/subtest_class> to return
116L<Test::TAP::Model::Subtest::Visual>.
117
118=item desc_string ?$new_value
119
120A short descriptive string used to distinguish this file from others in the
121various report views.
122
123=back
124
125=cut
126