Changeset 351
- Timestamp:
- 01/14/07 15:28:27 (2 years ago)
- Files:
-
- library/perl/trunk/Assurer/examples/config.yaml (modified) (1 diff)
- library/perl/trunk/Assurer/lib/Assurer.pm (modified) (5 diffs)
- library/perl/trunk/Assurer/lib/Assurer/Format.pm (added)
- library/perl/trunk/Assurer/lib/Assurer/Plugin.pm (modified) (2 diffs)
- library/perl/trunk/Assurer/lib/Assurer/Plugin/Format (added)
- library/perl/trunk/Assurer/lib/Assurer/Plugin/Format.pm (added)
- library/perl/trunk/Assurer/lib/Assurer/Plugin/Format/HTML.pm (added)
- library/perl/trunk/Assurer/lib/Assurer/Plugin/Format/Text.pm (added)
- library/perl/trunk/Assurer/lib/Assurer/Plugin/Publish (added)
- library/perl/trunk/Assurer/lib/Assurer/Plugin/Publish.pm (added)
- library/perl/trunk/Assurer/lib/Assurer/Plugin/Publish/Term.pm (added)
- library/perl/trunk/Assurer/lib/Assurer/Plugin/Test.pm (modified) (1 diff)
- library/perl/trunk/Assurer/lib/Assurer/Plugin/Test/HTTP.pm (modified) (1 diff)
- library/perl/trunk/Assurer/lib/Assurer/Results.pm (deleted)
- library/perl/trunk/Assurer/lib/Assurer/Test.pm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
library/perl/trunk/Assurer/examples/config.yaml
r347 r351 1 1 global: 2 config: 3 no_diag: 1 2 no_diag: 0 4 3 5 4 test: 6 5 - module: HTTP 7 name: http://svn.mizzy.org/#06 name: Apache ãã¹ã #0 8 7 config: 9 url: http://svn.mizzy.org/ 10 match: It works! 8 - url: http://svn.mizzy.org/ 9 match: It not works! 10 - url: http://svn.mizzy.org/ 11 match: It works! 12 - url: http://svn.mizzy.org/ 13 match: It not works! 14 - url: http://svn.mizzy.org/ 15 match: It works! 16 - url: http://svn.mizzy.org/ 17 match: It works! 18 - url: http://svn.mizzy.org/ 19 match: It works! 20 - url: http://svn.mizzy.org/ 21 match: It works! 11 22 12 23 - module: HTTP 13 name: http://svn.mizzy.org/#124 name: Apache ãã¹ã #1 14 25 config: 15 url: http://svn.mizzy.org/ 16 match: It not works! 26 - url: http://svn.mizzy.org/ 27 match: It works! 28 - url: http://svn.mizzy.org/ 29 match: It not works! 30 - url: http://svn.mizzy.org/ 31 match: It works! 32 - url: http://svn.mizzy.org/ 33 match: It works! 34 35 - module: HTTP 36 name: Apache ãã¹ã #2 37 config: 38 - url: http://svn.mizzy.org/ 39 match: It works! 40 - url: http://svn.mizzy.org/ 41 match: It works! 42 - url: http://svn.mizzy.org/ 43 match: It works! 44 45 - module: HTTP 46 name: Apache ãã¹ã #3 47 config: 48 - url: http://svn.mizzy.org/ 49 match: It not works! 50 - url: http://svn.mizzy.org/ 51 match: It not works! 52 53 format: 54 - module: HTML 55 config: 56 css_uri: htmlmatrix.css 57 58 publish: 59 - module: Term library/perl/trunk/Assurer/lib/Assurer.pm
r346 r351 8 8 our $VERSION = qv('0.0.1'); 9 9 10 use base qw( Class::Accessor::Fast ); 10 11 use Assurer::ConfigLoader; 12 use Assurer::Test; 11 13 use UNIVERSAL::require; 14 15 __PACKAGE__->mk_accessors( qw/ test / ); 12 16 13 17 my $context; … … 33 37 my $config_loader = Assurer::ConfigLoader->new; 34 38 $self->{config} = $config_loader->load($opts->{config}); 35 36 39 Assurer->set_context($self); 40 41 $self->{test} = Assurer::Test->new; 37 42 38 43 return $self; … … 47 52 $self->run_hook('test'); 48 53 $self->run_hook('format'); 49 $self->run_hook('publish'); 54 55 for my $format ( @{ $self->formats || [] } ) { 56 $self->run_hook('publish', { format => $format }); 57 } 50 58 } 51 59 … … 55 63 56 64 for my $plugin ( @{ $self->{hooks}->{$hook} || [] } ) { 57 if ( $hook eq 'test' ) { 58 $args = { 59 %$args, 60 test => Assurer::Test->new($plugin), 61 }; 62 } 63 64 $plugin->run($context, $args); 65 $plugin->finalize if $plugin->can('finalize'); 65 $plugin->pre_run($context, $args); 66 $plugin->finalize($context, $args) if $plugin->can('finalize'); 66 67 } 67 68 } … … 92 93 return shift->{results}; 93 94 } 95 96 sub add_format { 97 my $self = shift; 98 push @{ $self->{formats} }, shift; 99 } 100 101 sub formats { 102 return shift->{formats}; 103 } 104 105 sub conf { 106 my $self = shift; 107 return $self->{config}->{global}; 108 } 109 94 110 1; # Magic true value required at end of module 95 111 __END__ library/perl/trunk/Assurer/lib/Assurer/Plugin.pm
r346 r351 4 4 use warnings; 5 5 use UNIVERSAL::require; 6 use Assurer::Results;7 6 8 7 sub new { … … 22 21 } 23 22 23 sub pre_run { 24 my $self = shift; 25 $self->run(@_); 26 } 27 24 28 sub log { 25 29 my $self = shift; library/perl/trunk/Assurer/lib/Assurer/Plugin/Test.pm
r346 r351 5 5 6 6 use base qw( Assurer::Plugin ); 7 use UNIVERSAL::require;8 use Assurer::Results;9 7 10 8 sub init { 11 9 my $self = shift; 12 13 10 my $name = $self->{name} || 'no name'; 14 $self->{results} = Assurer::Results->new($name);15 11 16 12 return $self; 17 13 } 18 14 19 sub finalize{15 sub pre_run { 20 16 my $self = shift; 21 Assurer->context->add_result($self->{results}); 17 Assurer->context->test->init($self->{name}); 18 $self->run(@_); 22 19 } 23 20 21 sub finalize { 22 my ( $self, $context, $args ) = @_; 23 24 my $test = $context->test; 25 26 my @results = split "\n", ${ $test->{result} }; 27 my $count = @results; 28 push @results, "1..$count"; 29 30 my %result = $test->{model}->analyze_fh($self->{name}, \@results); 31 $test->{test_file}->{results} = \%result; 32 delete $test->{test_file}->{results}{details}; 33 34 $test->{model}->{meat}->{end_time} = time; 35 36 Assurer->context->add_result($test->{model}); 37 } 38 39 40 24 41 1; library/perl/trunk/Assurer/lib/Assurer/Plugin/Test/HTTP.pm
r346 r351 10 10 my ( $self, $context, $args ) = @_; 11 11 12 my $test = $args->{test}; 13 my $url = $self->{config}->{url}; 14 my $match = $self->{config}->{match}; 12 my $test = $context->test; 15 13 16 $test->like ( 17 get($url), 18 qr/$match/, 19 "Content of $url matches '$match'", 20 ); 14 my $config = $self->{config}; 15 16 $config = [ $config ] if ref $config eq 'HASH'; 17 18 for ( @$config ) { 19 my $url = $_->{url}; 20 my $match = $_->{match}; 21 22 $test->like ( 23 get($url), 24 qr/$match/, 25 "Content of $url matches '$match'", 26 ); 27 } 21 28 } 22 29 library/perl/trunk/Assurer/lib/Assurer/Test.pm
r347 r351 5 5 6 6 use Test::Builder; 7 use Te rm::ANSIColor;7 use Test::TAP::Model; 8 8 9 9 our $AUTOLOAD; 10 10 11 my $test = Test::Builder->new;12 $test->plan('no_plan');13 $test->no_diag(Assurer->context->{config}->{global}->{config}->{no_diag});14 15 my $diag;16 17 11 sub new { 18 12 my $class = shift; 19 my $self = { plugin => shift }; 13 my $self = { }; 14 15 my $test = Test::Builder->new; 16 $test->plan('no_plan'); 17 $test->no_diag(Assurer->context->conf->{no_diag}); 18 19 $self->{test} = $test; 20 20 21 bless $self, $class; 21 22 return $self; 23 } 24 25 sub init { 26 my $self = shift; 27 my $result; 28 open my $out, '>', \$result; 29 $self->{test}->output($out); 30 31 $self->{result} = \$result; 32 33 $self->{model} = Test::TAP::Model->new; 34 $self->{test_file} = $self->{model}->start_file(shift); 35 $self->{model}->{meat}->{start_time} = time; 36 37 $self->{test}->current_test(0); 22 38 } 23 39 … … 30 46 my $code = sub { 31 47 my $self = shift; 32 33 my $result; 34 open my $out, '>', \$result; 35 $test->output($out); 36 $test->$method(@_); 37 38 if ( $result =~ /^ok/ ) { 39 print color 'blue'; 40 } 41 else { 42 print color 'red'; 43 } 44 45 print "$result"; 46 47 print color 'reset'; 48 print $diag if $diag; 49 50 $self->{plugin}->{results}->add({ 51 result => $result, 52 diag => $diag, 53 }); 54 55 $diag = ''; 48 $self->{test}->$method(@_); 56 49 }; 57 50 … … 59 52 *{$func} = $code; 60 53 goto &$code; 61 }54 } 62 55 63 56 { … … 69 62 return unless @msgs; 70 63 71 $diag = join '', map { defined($_) ? $_ : 'undef' } @msgs;72 $diag =~ s/^/# /gm;73 $diag .= "\n" unless $diag =~ /\n\Z/;64 #$diag = join '', map { defined($_) ? $_ : 'undef' } @msgs; 65 #$diag =~ s/^/# /gm; 66 #$diag .= "\n" unless $diag =~ /\n\Z/; 74 67 }; 75 68 }
