--- trunk/lib/Frey/Test/Runner.pm 2008/11/24 21:35:34 500 +++ trunk/lib/Frey/Test/Runner.pm 2008/11/25 13:39:44 511 @@ -21,6 +21,42 @@ # [ 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; + }, ); sub as_markup { @@ -37,34 +73,30 @@ formatter => $f, }); - my $tests; + my @tests; + + @tests = ( $self->test ) if $self->test; - 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->{$_}->{$class}++ 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; + 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'); + } 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"; @@ -86,8 +118,10 @@ $html =~ s{(t/(.+?)}{$3}sg; - return - $self->editor_links( $html ) + $html = $self->editor_links( $html ); + + if ( my $depends = $self->depends ) { + $html .= qq|Test dependencies:| . qq|| ; + } }