/[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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 503 by dpavlin, Mon Nov 24 21:50:05 2008 UTC revision 1133 by dpavlin, Tue Jun 30 15:10:55 2009 UTC
# Line 2  package Frey::Test::Runner; Line 2  package Frey::Test::Runner;
2  use Moose;  use Moose;
3    
4  extends 'Frey';  extends 'Frey';
5  with 'Frey::Web';  with 'Frey::Web', 'Frey::Storage';
 with 'Frey::Storage';  
6    
7  use TAP::Harness;  use TAP::Harness;
8  use TAP::Formatter::HTML;  use TAP::Formatter::HTML;
9  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
10    use File::Slurp;
11    
12  use Frey::SVK;  use Frey::SVK;
13  use Frey::PPI;  use Frey::PPI;
# Line 18  has tests => ( Line 18  has tests => (
18          required => 1,          required => 1,
19          lazy => 1, # FIXME ask users which tests to run          lazy => 1, # FIXME ask users which tests to run
20          default => sub {          default => sub {
 #               [ glob('t/*.t') ] # all tests  
21                  [ Frey::SVK->modified ]                  [ Frey::SVK->modified ]
22          },          },
23            documentation => 'run tests which are result of modifications or whole full tests',
24    );
25    
26    has test => (
27            is => 'rw',
28            isa => 'Str',
29            documentation => 'run only this single test',
30    );
31    
32    has test_because => (
33            documentation => 'returns classes responsable for each test run',
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 {  sub as_markup {
63          my ($self) = @_;          my ($self) = @_;
64    
65    =for later
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 allready running as pid $pid";
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    =cut
84    
85          my $f = TAP::Formatter::HTML->new({          my $f = TAP::Formatter::HTML->new({
86  #               silent => 1,                  silent => 1,
87    
88                  inline_css => 1,                  inline_css => 1,
89                  inline_js  => 0,                  inline_js  => 0,
# Line 37  sub as_markup { Line 93  sub as_markup {
93                  formatter => $f,                  formatter => $f,
94          });          });
95    
96          my $tests;          my @tests;
97    
98          map {          @tests = ( $self->test ) if $self->test;
99                  $tests->{$_}->{'test modified'}++ if m{\.t$};  
100          } @{ $self->tests };          if ( my $depends = $self->test_because ) {
101                    @tests = grep {
102          map {                          $_ ne '' &&
103                  if ( m{(.+)\.pm$} ) {                          -e $_ &&
104                          my $class = $1;                          ! m{$0} # break recursion      
105                          $class =~ s{^lib/}{};                  } sort keys %{ $depends } unless @tests;
106                          $class =~ s{/}{::}g;          }
                         warn "extract tests from $_ class $class";  
                         $tests->{$_}->{$class}++ foreach Frey::PPI->new( class => $class )->has_tests;  
                 }  
         } @{ $self->tests };  
107    
108          my @tests = grep {          $self->add_status( { test => { depends => $self->test_because } } );
109                  ! m{$0} # break recursion        
110          } sort keys %$tests;          if ( ! @tests ) {
111          die "no tests for files ", dump( $self->tests ),dump( $tests ) unless @tests;                  warn "can't find any tests ", dump( $self->tests ), " within depends ", dump( $self->test_because );
112    #               warn "running all tests instead";
113    #               @tests = glob('t/*.t');
114                    @tests = ( qw{t/00-load.t t/pod.t} ); # XXX default tests
115            }
116    
117            $self->title( join(' ', @tests ) );
118    
119          warn "testing ",dump( @tests );          warn "testing ",dump( @tests );
120          $h->runtests( @tests );          $h->runtests( @tests );
121    
122          $self->store( 'var/test/' . time() . '.yaml', $h );          $self->store( 'var/test/' . time() . '.yaml', $h );
123    
         push @{ $self->status }, { test => $tests };  
   
124          my $html = ${ $f->html };          my $html = ${ $f->html };
125  #       warn $html;  #       warn $html;
126          warn "got ",length($html), " bytes";          warn "got ",length($html), " bytes";
127    
128          while ( $html =~ s{(<style.+?/style>)}{}gs ) {          while ( $html =~ s{(<style.+?/style>)}{}gs ) {
129                  $self->add_head( $1 );                  my $style = $1;
130                    $style =~ s[((?:body|html)\s+{[^}]+})][/\* $1 \*/]sg; # remove some styles
131                    $self->add_head( $style );
132          }          }
133    
134          $self->add_head(qq|          $self->add_head(qq|
# Line 80  sub as_markup { Line 138  sub as_markup {
138                  td.results:hover ul.test-out { display: block; }                  td.results:hover ul.test-out { display: block; }
139                  </style>                  </style>
140          |);          |);
141            $html =~ s{<div id="menu">.+?</div>}{}sg; # remove menu which doesn't work without JavaScript
142    
143          $html =~ s{^.*<body>}{}s;          $html =~ s{^.*<body>}{}s;
144          $html =~ s{</body>.*$}{}s;          $html =~ s{</body>.*$}{}s;
145    
146          $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;          $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;
147    
148          return          $html = $self->html_links( $html );
149                  $self->editor_links( $html )  
150            if ( my $depends = $self->test_because ) {
151                    $html .= qq|Test dependencies:|
152                  . qq|<ul><li>|                  . qq|<ul><li>|
153                  . join("</li>\n<li>",                  . join("</li>\n<li>",
154                          map {                          map {
155                                  qq|<a href="#$_"><tt>$_</tt></a> &larr; |                                  my $test = $_;
156                                  .                                  my $depends =
157                                  join(' ',                                  join(' ',
158                                          map {                                          map {
159                                                  if ( m{\s} ) {                                                  if ( m{\s} ) {
# Line 101  sub as_markup { Line 162  sub as_markup {
162                                                          qq|<a target="introspect" href="/$_" title="introspect">$_</a>|                                                          qq|<a target="introspect" href="/$_" title="introspect">$_</a>|
163  #                                                       qq|<a target="editor" href="/editor+$_+1" title="edit">$_</a>|  #                                                       qq|<a target="editor" href="/editor+$_+1" title="edit">$_</a>|
164                                                  }                                                  }
165                                          } keys %{ $tests->{$_} }                                          } keys %{ $depends->{$_} }
166                                  )                                  );
167                                    qq|<a href="?test=$test"><tt>$test</tt></a>|
168                                    . ( $depends ? qq| &larr; $depends| : '' )
169                                    ;
170                          } @tests )                          } @tests )
171                  . qq|</li></ul>|                  . qq|</li></ul>|
172                  ;                  ;
173                    } else {
174                    warn "# test_because empty";
175            }
176    
177            $self->add_icon( $1 ) if $html =~ m{class="(passed|failed)"};
178    
179    =for later
180    
181            unlink $running_pid or die "can't remove $running_pid: $!";
182    
183    =cut
184    
185            return $html;
186  }  }
187    
188    __PACKAGE__->meta->make_immutable;
189    no Moose;
190    
191  1;  1;

Legend:
Removed from v.503  
changed lines
  Added in v.1133

  ViewVC Help
Powered by ViewVC 1.1.26