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