--- trunk/lib/Frey/Test/Runner.pm 2008/11/24 20:51:26 494 +++ trunk/lib/Frey/Test/Runner.pm 2008/11/26 00:51:08 525 @@ -21,11 +21,52 @@ # [ glob('t/*.t') ] # all tests [ Frey::SVK->modified ] }, + documentation => 'run tests which are result of modifications or whole full tests', ); +has test => ( + is => 'rw', + isa => 'Str', + documentation => 'run only this single test', +); + +has depends => ( + is => 'rw', +# isa => 'HashRef[Hashref[Int]', + required => 1, + lazy => 1, + default => sub { + my $self = shift; + my $depends; + + # collect real tests + map { + $depends->{$_}->{'test modified'}++ if m{\.t$}; + } @{ $self->tests }; + + # and tests which depend on modified classes supplied + map { + if ( m{(.+)\.pm$} ) { + my $class = $1; + $class =~ s{^lib/}{}; + $class =~ s{/}{::}g; + warn "extract tests from $_ class $class"; + $depends->{$_}->{$class}++ foreach Frey::PPI->new( class => $class )->has_tests; + } + } @{ $self->tests }; + + return $depends; + }, +); + +our $running; + sub as_markup { my ($self) = @_; + return 'allready running' if $running; + $running = 1; + my $f = TAP::Formatter::HTML->new({ # silent => 1, @@ -37,40 +78,40 @@ formatter => $f, }); - my $tests; + my @tests; - map { - $tests->{$_}++ if m{\.t$}; - } @{ $self->tests }; - - map { - if ( m{(.+)\.pm$} ) { - my $class = $1; - $class =~ s{^lib/}{}; - $class =~ s{/}{::}g; - warn "extract tests from $_ class $class"; - $tests->{$_}++ foreach Frey::PPI->new( class => $class )->has_tests; - } - } @{ $self->tests }; - - my @tests = grep { - ! m{$0} # break recursion - } sort keys %$tests; - die "no tests for files ", dump( $self->tests ),dump( $tests ) unless @tests; + @tests = ( $self->test ) if $self->test; + + if ( my $depends = $self->depends ) { + @tests = grep { + $_ ne '' && + ! m{$0} # break recursion + } sort keys %{ $depends } unless @tests; + } + + $self->add_status( { test => { depends => $self->depends } } ); + + if ( ! @tests ) { + warn "can't find any tests ", dump( $self->tests ), " within depends ", dump( $self->depends ); + warn "running all tests instead"; + @tests = glob('t/*.t'); + } + + $self->title( join(' ', @tests ) ); warn "testing ",dump( @tests ); $h->runtests( @tests ); $self->store( 'var/test/' . time() . '.yaml', $h ); - push @{ $self->status }, { test => $tests }; - my $html = ${ $f->html }; # warn $html; 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| @@ -80,17 +121,39 @@ 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; - $html =~ s{(t/(.+?)}{$3}sg; + $html =~ s{(t/(.+?)}{$3}sg; - return - $self->editor_links( $html ) - . qq|| + $html = $self->editor_links( $html ); + + if ( my $depends = $self->depends ) { + $html .= qq|Test dependencies:| + . qq|| ; + } + $running = 0; + return $html; } 1;