1 |
package Frey::Test::Runner; |
2 |
use Moose; |
3 |
|
4 |
extends 'Frey'; |
5 |
with 'Frey::Web'; |
6 |
with 'Frey::Storage'; |
7 |
|
8 |
use TAP::Harness; |
9 |
use TAP::Formatter::HTML; |
10 |
use Data::Dump qw/dump/; |
11 |
|
12 |
use Frey::SVK; |
13 |
use Frey::PPI; |
14 |
|
15 |
has tests => ( |
16 |
is => 'rw', |
17 |
isa => 'ArrayRef[Str]', |
18 |
required => 1, |
19 |
lazy => 1, # FIXME ask users which tests to run |
20 |
default => sub { |
21 |
# [ glob('t/*.t') ] # all tests |
22 |
[ Frey::SVK->modified ] |
23 |
}, |
24 |
); |
25 |
|
26 |
sub as_markup { |
27 |
my ($self) = @_; |
28 |
|
29 |
my $f = TAP::Formatter::HTML->new({ |
30 |
# silent => 1, |
31 |
|
32 |
inline_css => 1, |
33 |
inline_js => 0, |
34 |
}); |
35 |
my $h = TAP::Harness->new({ |
36 |
merge => 1, |
37 |
formatter => $f, |
38 |
}); |
39 |
|
40 |
my $tests; |
41 |
|
42 |
map { |
43 |
$tests->{$_}->{'test modified'}++ if m{\.t$}; |
44 |
} @{ $self->tests }; |
45 |
|
46 |
map { |
47 |
if ( m{(.+)\.pm$} ) { |
48 |
my $class = $1; |
49 |
$class =~ s{^lib/}{}; |
50 |
$class =~ s{/}{::}g; |
51 |
warn "extract tests from $_ class $class"; |
52 |
$tests->{$_}->{$class}++ foreach Frey::PPI->new( class => $class )->has_tests; |
53 |
} |
54 |
} @{ $self->tests }; |
55 |
|
56 |
my @tests = grep { |
57 |
! m{$0} # break recursion |
58 |
} sort keys %$tests; |
59 |
die "no tests for files ", dump( $self->tests ),dump( $tests ) unless @tests; |
60 |
|
61 |
warn "testing ",dump( @tests ); |
62 |
$h->runtests( @tests ); |
63 |
|
64 |
$self->store( 'var/test/' . time() . '.yaml', $h ); |
65 |
|
66 |
push @{ $self->status }, { test => $tests }; |
67 |
|
68 |
my $html = ${ $f->html }; |
69 |
# warn $html; |
70 |
warn "got ",length($html), " bytes"; |
71 |
|
72 |
while ( $html =~ s{(<style.+?/style>)}{}gs ) { |
73 |
$self->add_head( $1 ); |
74 |
} |
75 |
|
76 |
$self->add_head(qq| |
77 |
<style type="text/css"> |
78 |
/* CSS to show-hide full text results */ |
79 |
ul.test-out { display: none; } |
80 |
td.results:hover ul.test-out { display: block; } |
81 |
</style> |
82 |
|); |
83 |
|
84 |
$html =~ s{^.*<body>}{}s; |
85 |
$html =~ s{</body>.*$}{}s; |
86 |
|
87 |
$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; |
88 |
|
89 |
return |
90 |
$self->editor_links( $html ) |
91 |
. qq|<ul><li>| |
92 |
. join("</li>\n<li>", |
93 |
map { |
94 |
qq|<a href="#$_"><tt>$_</tt></a> ← | |
95 |
. |
96 |
join(' ', |
97 |
map { |
98 |
if ( m{\s} ) { |
99 |
$_ # human comment with space |
100 |
} else { |
101 |
qq|<a target="introspect" href="/$_" title="introspect">$_</a>| |
102 |
# qq|<a target="editor" href="/editor+$_+1" title="edit">$_</a>| |
103 |
} |
104 |
} keys %{ $tests->{$_} } |
105 |
) |
106 |
} @tests ) |
107 |
. qq|</li></ul>| |
108 |
; |
109 |
|
110 |
} |
111 |
|
112 |
1; |