--- trunk/lib/Frey/Test/Runner.pm 2008/11/25 13:39:44 511 +++ trunk/lib/Frey/Test/Runner.pm 2008/11/26 22:29:13 549 @@ -8,6 +8,7 @@ use TAP::Harness; use TAP::Formatter::HTML; use Data::Dump qw/dump/; +use File::Slurp; use Frey::SVK; use Frey::PPI; @@ -30,7 +31,8 @@ documentation => 'run only this single test', ); -has depends => ( +has test_because => ( + documentation => 'returns classes responsable for each test run', is => 'rw', # isa => 'HashRef[Hashref[Int]', required => 1, @@ -62,6 +64,22 @@ sub as_markup { my ($self) = @_; + my $path = 'var/test/'; + my $running_pid = "$path/running.pid"; + + my $pid = read_file $running_pid if -e $running_pid; + if ( $pid ) { + if ( kill 0, $pid ) { + warn "ABORTING: $self started twice"; + return 'abort'; + } else { + warn "got $pid from $running_pid but no process alive, ignoring..."; + } + } + + write_file( $running_pid, $$ ); + warn "# started $self with pid $$ -> $running_pid"; + my $f = TAP::Formatter::HTML->new({ # silent => 1, @@ -77,21 +95,23 @@ @tests = ( $self->test ) if $self->test; - if ( my $depends = $self->depends ) { + if ( my $depends = $self->test_because ) { @tests = grep { $_ ne '' && ! m{$0} # break recursion } sort keys %{ $depends } unless @tests; } - $self->add_status( { test => { depends => $self->depends } } ); + $self->add_status( { test => { depends => $self->test_because } } ); if ( ! @tests ) { - warn "can't find any tests ", dump( $self->tests ), " within depends ", dump( $self->depends ); + warn "can't find any tests ", dump( $self->tests ), " within depends ", dump( $self->test_because ); warn "running all tests instead"; @tests = glob('t/*.t'); } + $self->title( join(' ', @tests ) ); + warn "testing ",dump( @tests ); $h->runtests( @tests ); @@ -102,7 +122,9 @@ warn "got ",length($html), " bytes"; while ( $html =~ s{()}{}gs ) { - $self->add_head( $1 ); + my $style = $1; + $style =~ s[((?:body|html)\s+{[^}]+})][/\* $1 \*/]sg; # remove some styles + $self->add_head( $style ); } $self->add_head(qq| @@ -112,6 +134,7 @@ td.results:hover ul.test-out { display: block; } |); + $html =~ s{}{}sg; # remove menu which doesn't work without JavaScript $html =~ s{^.*}{}s; $html =~ s{.*$}{}s; @@ -120,12 +143,12 @@ $html = $self->editor_links( $html ); - if ( my $depends = $self->depends ) { + if ( my $depends = $self->test_because ) { $html .= qq|Test dependencies:| . qq|| ; } - + + $self->add_icon( $1 ) if $html =~ m{class="(passed|failed)"}; + + unlink $running_pid or die "can't remove $running_pid: $!"; + + return $html; } 1;