8 |
use TAP::Harness; |
use TAP::Harness; |
9 |
use TAP::Formatter::HTML; |
use TAP::Formatter::HTML; |
10 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
11 |
|
use File::Slurp; |
12 |
|
|
13 |
use Frey::SVK; |
use Frey::SVK; |
14 |
use Frey::PPI; |
use Frey::PPI; |
19 |
required => 1, |
required => 1, |
20 |
lazy => 1, # FIXME ask users which tests to run |
lazy => 1, # FIXME ask users which tests to run |
21 |
default => sub { |
default => sub { |
|
# [ glob('t/*.t') ] # all tests |
|
22 |
[ Frey::SVK->modified ] |
[ Frey::SVK->modified ] |
23 |
}, |
}, |
24 |
|
documentation => 'run tests which are result of modifications or whole full tests', |
25 |
|
); |
26 |
|
|
27 |
|
has test => ( |
28 |
|
is => 'rw', |
29 |
|
isa => 'Str', |
30 |
|
documentation => 'run only this single test', |
31 |
|
); |
32 |
|
|
33 |
|
has test_because => ( |
34 |
|
documentation => 'returns classes responsable for each test run', |
35 |
|
is => 'rw', |
36 |
|
# isa => 'HashRef[Hashref[Int]', |
37 |
|
required => 1, |
38 |
|
lazy => 1, |
39 |
|
default => sub { |
40 |
|
my $self = shift; |
41 |
|
my $depends; |
42 |
|
|
43 |
|
# collect real tests |
44 |
|
map { |
45 |
|
$depends->{$_}->{'test modified'}++ if m{\.t$}; |
46 |
|
} @{ $self->tests }; |
47 |
|
|
48 |
|
# and tests which depend on modified classes supplied |
49 |
|
map { |
50 |
|
if ( m{(.+)\.pm$} ) { |
51 |
|
my $class = $1; |
52 |
|
$class =~ s{^lib/}{}; |
53 |
|
$class =~ s{/}{::}g; |
54 |
|
warn "extract tests from $_ class $class"; |
55 |
|
$depends->{$_}->{$class}++ foreach Frey::PPI->new( class => $class )->has_tests; |
56 |
|
} |
57 |
|
} @{ $self->tests }; |
58 |
|
|
59 |
|
return $depends; |
60 |
|
}, |
61 |
); |
); |
62 |
|
|
63 |
sub as_markup { |
sub as_markup { |
64 |
my ($self) = @_; |
my ($self) = @_; |
65 |
|
|
66 |
|
=for later |
67 |
|
|
68 |
|
my $path = 'var/test/'; |
69 |
|
my $running_pid = "$path/running.pid"; |
70 |
|
|
71 |
|
my $pid = read_file $running_pid if -e $running_pid; |
72 |
|
if ( $pid ) { |
73 |
|
if ( kill 0, $pid ) { |
74 |
|
warn "ABORTING: $self allready running as pid $pid"; |
75 |
|
return 'abort'; |
76 |
|
} else { |
77 |
|
warn "got $pid from $running_pid but no process alive, ignoring..."; |
78 |
|
} |
79 |
|
} |
80 |
|
|
81 |
|
write_file( $running_pid, $$ ); |
82 |
|
warn "# started $self with pid $$ -> $running_pid"; |
83 |
|
|
84 |
|
=cut |
85 |
|
|
86 |
my $f = TAP::Formatter::HTML->new({ |
my $f = TAP::Formatter::HTML->new({ |
87 |
# silent => 1, |
silent => 1, |
88 |
|
|
89 |
inline_css => 1, |
inline_css => 1, |
90 |
inline_js => 0, |
inline_js => 0, |
94 |
formatter => $f, |
formatter => $f, |
95 |
}); |
}); |
96 |
|
|
97 |
my $tests; |
my @tests; |
98 |
|
|
99 |
map { |
@tests = ( $self->test ) if $self->test; |
|
$tests->{$_}++ if m{\.t$}; |
|
|
} @{ $self->tests }; |
|
|
|
|
|
map { |
|
|
if ( m{(.+)\.pm$} ) { |
|
|
my $class = $1; |
|
|
$class =~ s{^lib/}{}; |
|
|
$class =~ s{/}{::}g; |
|
|
warn "extract tests from $_ class $class"; |
|
|
$tests->{$_}++ foreach Frey::PPI->new( class => $class )->has_tests; |
|
|
} |
|
|
} @{ $self->tests }; |
|
100 |
|
|
101 |
my @tests = grep { |
if ( my $depends = $self->test_because ) { |
102 |
! m{$0} # break recursion |
@tests = grep { |
103 |
} sort keys %$tests; |
$_ ne '' && |
104 |
die "no tests for files ", dump( $self->tests ),dump( $tests ) unless @tests; |
-e $_ && |
105 |
|
! m{$0} # break recursion |
106 |
|
} sort keys %{ $depends } unless @tests; |
107 |
|
} |
108 |
|
|
109 |
|
$self->add_status( { test => { depends => $self->test_because } } ); |
110 |
|
|
111 |
|
if ( ! @tests ) { |
112 |
|
warn "can't find any tests ", dump( $self->tests ), " within depends ", dump( $self->test_because ); |
113 |
|
# warn "running all tests instead"; |
114 |
|
# @tests = glob('t/*.t'); |
115 |
|
@tests = ( qw{t/00-load.t t/pod.t} ); # XXX default tests |
116 |
|
} |
117 |
|
|
118 |
|
$self->title( join(' ', @tests ) ); |
119 |
|
|
120 |
warn "testing ",dump( @tests ); |
warn "testing ",dump( @tests ); |
121 |
$h->runtests( @tests ); |
$h->runtests( @tests ); |
125 |
my $html = ${ $f->html }; |
my $html = ${ $f->html }; |
126 |
# warn $html; |
# warn $html; |
127 |
warn "got ",length($html), " bytes"; |
warn "got ",length($html), " bytes"; |
128 |
# $html =~ s{^.*<body>}{}s; |
|
129 |
# $html =~ s{</body>.*$}{}s; |
while ( $html =~ s{(<style.+?/style>)}{}gs ) { |
130 |
return $self->editor_links( $html ); |
my $style = $1; |
131 |
|
$style =~ s[((?:body|html)\s+{[^}]+})][/\* $1 \*/]sg; # remove some styles |
132 |
|
$self->add_head( $style ); |
133 |
|
} |
134 |
|
|
135 |
|
$self->add_head(qq| |
136 |
|
<style type="text/css"> |
137 |
|
/* CSS to show-hide full text results */ |
138 |
|
ul.test-out { display: none; } |
139 |
|
td.results:hover ul.test-out { display: block; } |
140 |
|
</style> |
141 |
|
|); |
142 |
|
$html =~ s{<div id="menu">.+?</div>}{}sg; # remove menu which doesn't work without JavaScript |
143 |
|
|
144 |
|
$html =~ s{^.*<body>}{}s; |
145 |
|
$html =~ s{</body>.*$}{}s; |
146 |
|
|
147 |
|
$html =~ s{(<a class="file") href="#"(.+?)>t/(.+?)</a>}{<a target="editor" href="/editor+t/$3.t+1" name="t/$3.t" $2>$3</a>}sg; |
148 |
|
|
149 |
|
$html = $self->html_links( $html ); |
150 |
|
|
151 |
|
if ( my $depends = $self->test_because ) { |
152 |
|
$html .= qq|Test dependencies:| |
153 |
|
. qq|<ul><li>| |
154 |
|
. join("</li>\n<li>", |
155 |
|
map { |
156 |
|
my $test = $_; |
157 |
|
my $depends = |
158 |
|
join(' ', |
159 |
|
map { |
160 |
|
if ( m{\s} ) { |
161 |
|
$_ # human comment with space |
162 |
|
} else { |
163 |
|
qq|<a target="introspect" href="/$_" title="introspect">$_</a>| |
164 |
|
# qq|<a target="editor" href="/editor+$_+1" title="edit">$_</a>| |
165 |
|
} |
166 |
|
} keys %{ $depends->{$_} } |
167 |
|
); |
168 |
|
qq|<a href="?test=$test"><tt>$test</tt></a>| |
169 |
|
. ( $depends ? qq| ← $depends| : '' ) |
170 |
|
; |
171 |
|
} @tests ) |
172 |
|
. qq|</li></ul>| |
173 |
|
; |
174 |
|
} else { |
175 |
|
warn "# test_because empty"; |
176 |
|
} |
177 |
|
|
178 |
|
$self->add_icon( $1 ) if $html =~ m{class="(passed|failed)"}; |
179 |
|
|
180 |
|
=for later |
181 |
|
|
182 |
|
unlink $running_pid or die "can't remove $running_pid: $!"; |
183 |
|
|
184 |
|
=cut |
185 |
|
|
186 |
|
return $html; |
187 |
} |
} |
188 |
|
|
189 |
1; |
1; |