/[Frey]/trunk/lib/Frey/Test/Runner.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/Test/Runner.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 508 - (show annotations)
Tue Nov 25 00:28:52 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 3018 byte(s)
fix depends
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 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 depends => (
34 is => 'rw',
35 # isa => 'HashRef[Hashref[Int]',
36 required => 1,
37 lazy => 1,
38 default => sub {
39 my $self = shift;
40 my $depends;
41
42 # collect real tests
43 map {
44 $depends->{$_}->{'test modified'}++ if m{\.t$};
45 } @{ $self->tests };
46
47 # and tests which depend on modified classes supplied
48 map {
49 if ( m{(.+)\.pm$} ) {
50 my $class = $1;
51 $class =~ s{^lib/}{};
52 $class =~ s{/}{::}g;
53 warn "extract tests from $_ class $class";
54 $depends->{$_}->{$class}++ foreach Frey::PPI->new( class => $class )->has_tests;
55 }
56 } @{ $self->tests };
57
58 return $depends;
59 },
60 );
61
62 sub as_markup {
63 my ($self) = @_;
64
65 my $f = TAP::Formatter::HTML->new({
66 # silent => 1,
67
68 inline_css => 1,
69 inline_js => 0,
70 });
71 my $h = TAP::Harness->new({
72 merge => 1,
73 formatter => $f,
74 });
75
76 my @tests;
77
78 @tests = ( $self->test ) if $self->test;
79
80 if ( my $depends = $self->depends ) {
81 @tests = grep {
82 ! m{$0} # break recursion
83 } sort keys %{ $depends } unless @tests;
84 }
85
86 $self->add_status( { test => { depends => $self->depends } } );
87
88 if ( ! @tests ) {
89 warn "can't find any tests ", dump( $self->tests ), " within depends ", dump( $self->depends );
90 warn "running all tests instead";
91 @tests = glob('t/*.t');
92 }
93
94 warn "testing ",dump( @tests );
95 $h->runtests( @tests );
96
97 $self->store( 'var/test/' . time() . '.yaml', $h );
98
99 my $html = ${ $f->html };
100 # warn $html;
101 warn "got ",length($html), " bytes";
102
103 while ( $html =~ s{(<style.+?/style>)}{}gs ) {
104 $self->add_head( $1 );
105 }
106
107 $self->add_head(qq|
108 <style type="text/css">
109 /* CSS to show-hide full text results */
110 ul.test-out { display: none; }
111 td.results:hover ul.test-out { display: block; }
112 </style>
113 |);
114
115 $html =~ s{^.*<body>}{}s;
116 $html =~ s{</body>.*$}{}s;
117
118 $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;
119
120 $html = $self->editor_links( $html );
121
122 if ( my $depends = $self->depends ) {
123 $html .= qq|Test dependencies:|
124 . qq|<ul><li>|
125 . join("</li>\n<li>",
126 map {
127 qq|<a href="#$_"><tt>$_</tt></a> &larr; |
128 .
129 join(' ',
130 map {
131 if ( m{\s} ) {
132 $_ # human comment with space
133 } else {
134 qq|<a target="introspect" href="/$_" title="introspect">$_</a>|
135 # qq|<a target="editor" href="/editor+$_+1" title="edit">$_</a>|
136 }
137 } keys %{ $self->depends->{$_} }
138 )
139 } @tests )
140 . qq|</li></ul>|
141 ;
142 }
143
144 }
145
146 1;

  ViewVC Help
Powered by ViewVC 1.1.26