/[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 491 by dpavlin, Mon Nov 24 18:29:41 2008 UTC revision 519 by dpavlin, Tue Nov 25 17:15:18 2008 UTC
# Line 21  has tests => ( Line 21  has tests => (
21  #               [ glob('t/*.t') ] # all tests  #               [ 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 depends => (
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    our $running;
63    exit if $running;
64    
65  sub as_markup {  sub as_markup {
66          my ($self) = @_;          my ($self) = @_;
67    
68            return 'allready running' if $running;
69            $running = 1;
70    
71          my $f = TAP::Formatter::HTML->new({          my $f = TAP::Formatter::HTML->new({
72  #               silent => 1,  #               silent => 1,
73    
# Line 37  sub as_markup { Line 79  sub as_markup {
79                  formatter => $f,                  formatter => $f,
80          });          });
81    
82          my $tests;          my @tests;
83    
84            @tests = ( $self->test ) if $self->test;
85    
86          map {          if ( my $depends = $self->depends ) {
87                  $tests->{$_}++ if m{\.t$};                  @tests = grep {
88          } @{ $self->tests };                          $_ ne '' &&
89                            ! m{$0} # break recursion      
90          map {                  } sort keys %{ $depends } unless @tests;
91                  if ( m{(.+)\.pm$} ) {          }
92                          my $class = $1;  
93                          $class =~ s{^lib/}{};          $self->add_status( { test => { depends => $self->depends } } );
94                          $class =~ s{/}{::}g;  
95                          warn "extract tests from $_ class $class";          if ( ! @tests ) {
96                          $tests->{$_}++ foreach Frey::PPI->new( class => $class )->has_tests;                  warn "can't find any tests ", dump( $self->tests ), " within depends ", dump( $self->depends );
97                  }                  warn "running all tests instead";
98          } @{ $self->tests };                  @tests = glob('t/*.t');
99            }
100          my @tests = grep {  
101                  ! m{$0} # break recursion                $self->title( join(' ', @tests ) );
         } sort keys %$tests;  
         die "no tests for files ", dump( $self->tests ),dump( $tests ) unless @tests;  
102    
103          warn "testing ",dump( @tests );          warn "testing ",dump( @tests );
104          $h->runtests( @tests );          $h->runtests( @tests );
# Line 66  sub as_markup { Line 108  sub as_markup {
108          my $html = ${ $f->html };          my $html = ${ $f->html };
109  #       warn $html;  #       warn $html;
110          warn "got ",length($html), " bytes";          warn "got ",length($html), " bytes";
111  #       $html =~ s{^.*<body>}{}s;  
112  #       $html =~ s{</body>.*$}{}s;          while ( $html =~ s{(<style.+?/style>)}{}gs ) {
113          return $self->editor_links( $html );                  my $style = $1;
114                    $style =~ s[((?:body|html)\s+{[^}]+})][/\* $1 \*/]sg; # remove some styles
115                    $self->add_head( $style );
116            }
117    
118            $self->add_head(qq|
119                    <style type="text/css">
120                    /* CSS to show-hide full text results */
121                    ul.test-out { display: none; }
122                    td.results:hover ul.test-out { display: block; }
123                    </style>
124            |);
125            $html =~ s{<div id="menu">.+?</div>}{}sg; # remove menu which doesn't work without JavaScript
126    
127            $html =~ s{^.*<body>}{}s;
128            $html =~ s{</body>.*$}{}s;
129    
130            $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;
131    
132            $html = $self->editor_links( $html );
133    
134            if ( my $depends = $self->depends ) {
135                    $html .= qq|Test dependencies:|
136                    . qq|<ul><li>|
137                    . join("</li>\n<li>",
138                            map {
139                                    qq|<a href="?test=$_"><tt>$_</tt></a> &larr; |
140                                    .
141                                    join(' ',
142                                            map {
143                                                    if ( m{\s} ) {
144                                                            $_      # human comment with space
145                                                    } else {
146                                                            qq|<a target="introspect" href="/$_" title="introspect">$_</a>|
147    #                                                       qq|<a target="editor" href="/editor+$_+1" title="edit">$_</a>|
148                                                    }
149                                            } keys %{ $self->depends->{$_} }
150                                    )
151                            } @tests )
152                    . qq|</li></ul>|
153                    ;
154            }
155            
156            $running = 0;
157            return $html;
158  }  }
159    
160  1;  1;

Legend:
Removed from v.491  
changed lines
  Added in v.519

  ViewVC Help
Powered by ViewVC 1.1.26