/[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 583 by dpavlin, Fri Nov 28 13:24:53 2008 UTC
# Line 8  with 'Frey::Storage'; Line 8  with 'Frey::Storage';
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;
# Line 18  has tests => ( Line 19  has tests => (
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            my $path = 'var/test/';
67            my $running_pid = "$path/running.pid";
68    
69            my $pid = read_file $running_pid if -e $running_pid;
70            if ( $pid ) {
71                    if ( kill 0, $pid ) {
72                            warn "ABORTING: $self started twice";
73                            return 'abort';
74                    } else {
75                            warn "got $pid from $running_pid but no process alive, ignoring...";
76                    }
77            }
78    
79            write_file( $running_pid, $$ );
80            warn "# started $self with pid $$ -> $running_pid";
81    
82          my $f = TAP::Formatter::HTML->new({          my $f = TAP::Formatter::HTML->new({
83  #               silent => 1,  #               silent => 1,
84    
# Line 37  sub as_markup { Line 90  sub as_markup {
90                  formatter => $f,                  formatter => $f,
91          });          });
92    
93          my $tests;          my @tests;
94    
95          map {          @tests = ( $self->test ) if $self->test;
96                  $tests->{$_}->{'test modified'}++ if m{\.t$};  
97          } @{ $self->tests };          if ( my $depends = $self->test_because ) {
98                    @tests = grep {
99          map {                          $_ ne '' &&
100                  if ( m{(.+)\.pm$} ) {                          ! m{$0} # break recursion      
101                          my $class = $1;                  } sort keys %{ $depends } unless @tests;
102                          $class =~ s{^lib/}{};          }
103                          $class =~ s{/}{::}g;  
104                          warn "extract tests from $_ class $class";          $self->add_status( { test => { depends => $self->test_because } } );
105                          $tests->{$_}->{$class}++ foreach Frey::PPI->new( class => $class )->has_tests;  
106                  }          if ( ! @tests ) {
107          } @{ $self->tests };                  warn "can't find any tests ", dump( $self->tests ), " within depends ", dump( $self->test_because );
108    #               warn "running all tests instead";
109    #               @tests = glob('t/*.t');
110                    @tests = glob('t/00-load.t'); # XXX default tests
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|
# Line 80  sub as_markup { Line 134  sub as_markup {
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 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;
143    
144          return          $html = $self->editor_links( $html );
145                  $self->editor_links( $html )  
146            if ( my $depends = $self->test_because ) {
147                    $html .= qq|Test dependencies:|
148                  . qq|<ul><li>|                  . qq|<ul><li>|
149                  . join("</li>\n<li>",                  . join("</li>\n<li>",
150                          map {                          map {
151                                  qq|<a href="#$_"><tt>$_</tt></a> &larr; |                                  qq|<a href="?test=$_"><tt>$_</tt></a> &larr; |
152                                  .                                  .
153                                  join(' ',                                  join(' ',
154                                          map {                                          map {
# Line 101  sub as_markup { Line 158  sub as_markup {
158                                                          qq|<a target="introspect" href="/$_" title="introspect">$_</a>|                                                          qq|<a target="introspect" href="/$_" title="introspect">$_</a>|
159  #                                                       qq|<a target="editor" href="/editor+$_+1" title="edit">$_</a>|  #                                                       qq|<a target="editor" href="/editor+$_+1" title="edit">$_</a>|
160                                                  }                                                  }
161                                          } keys %{ $tests->{$_} }                                          } keys %{ $depends->{$_} }
162                                  )                                  )
163                          } @tests )                          } @tests )
164                  . qq|</li></ul>|                  . qq|</li></ul>|
165                  ;                  ;
166                    } else {
167                    warn "# test_because empty";
168            }
169    
170            $self->add_icon( $1 ) if $html =~ m{class="(passed|failed)"};
171    
172            unlink $running_pid or die "can't remove $running_pid: $!";
173    
174            return $html;
175  }  }
176    
177  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26