Changeset 351

Show
Ignore:
Timestamp:
01/14/07 15:28:27 (2 years ago)
Author:
miya
Message:

Assurer::Plugin::Fomart* added.
Assurer::Plugin::Results deleted.Now using Test::TAP::Model.
Assurer::Test modified to use Test::TAP::Model.

Assurer: Add Publish plugin mechanism.
Add Format::HTML.
Refactoring Assurer::Test.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • library/perl/trunk/Assurer/examples/config.yaml

    r347 r351  
    11global: 
    2   config: 
    3     no_diag: 1 
     2  no_diag: 0 
    43 
    54test: 
    65  - module: HTTP 
    7     name: http://svn.mizzy.org/ #0 
     6    name: Apache テスト #0 
    87    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! 
    1122 
    1223  - module: HTTP 
    13     name: http://svn.mizzy.org/ #1 
     24    name: Apache テスト #1 
    1425    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 
     53format: 
     54  - module: HTML 
     55    config: 
     56      css_uri: htmlmatrix.css 
     57 
     58publish: 
     59  - module: Term 
  • library/perl/trunk/Assurer/lib/Assurer.pm

    r346 r351  
    88our $VERSION = qv('0.0.1'); 
    99 
     10use base qw( Class::Accessor::Fast ); 
    1011use Assurer::ConfigLoader; 
     12use Assurer::Test; 
    1113use UNIVERSAL::require; 
     14 
     15__PACKAGE__->mk_accessors( qw/ test / ); 
    1216 
    1317my $context; 
     
    3337    my $config_loader = Assurer::ConfigLoader->new; 
    3438    $self->{config} = $config_loader->load($opts->{config}); 
    35  
    3639    Assurer->set_context($self); 
     40 
     41    $self->{test} = Assurer::Test->new; 
    3742 
    3843    return $self; 
     
    4752    $self->run_hook('test'); 
    4853    $self->run_hook('format'); 
    49     $self->run_hook('publish'); 
     54 
     55    for my $format ( @{ $self->formats || [] } ) { 
     56        $self->run_hook('publish', { format => $format }); 
     57    } 
    5058} 
    5159 
     
    5563 
    5664    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'); 
    6667    } 
    6768} 
     
    9293    return shift->{results}; 
    9394} 
     95 
     96sub add_format { 
     97    my $self = shift; 
     98    push @{ $self->{formats} }, shift; 
     99} 
     100 
     101sub formats { 
     102   return shift->{formats}; 
     103} 
     104 
     105sub conf { 
     106    my $self = shift; 
     107    return $self->{config}->{global}; 
     108} 
     109 
    941101; # Magic true value required at end of module 
    95111__END__ 
  • library/perl/trunk/Assurer/lib/Assurer/Plugin.pm

    r346 r351  
    44use warnings; 
    55use UNIVERSAL::require; 
    6 use Assurer::Results; 
    76 
    87sub new { 
     
    2221} 
    2322 
     23sub pre_run  { 
     24    my $self = shift; 
     25    $self->run(@_); 
     26} 
     27 
    2428sub log { 
    2529    my $self = shift; 
  • library/perl/trunk/Assurer/lib/Assurer/Plugin/Test.pm

    r346 r351  
    55 
    66use base qw( Assurer::Plugin ); 
    7 use UNIVERSAL::require; 
    8 use Assurer::Results; 
    97 
    108sub init { 
    119    my $self = shift; 
    12  
    1310    my $name = $self->{name} || 'no name'; 
    14     $self->{results} = Assurer::Results->new($name); 
    1511 
    1612    return $self; 
    1713} 
    1814 
    19 sub finalize
     15sub pre_run
    2016    my $self = shift; 
    21     Assurer->context->add_result($self->{results}); 
     17    Assurer->context->test->init($self->{name}); 
     18    $self->run(@_); 
    2219} 
    2320 
     21sub 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 
    24411; 
  • library/perl/trunk/Assurer/lib/Assurer/Plugin/Test/HTTP.pm

    r346 r351  
    1010    my ( $self, $context, $args ) = @_; 
    1111 
    12     my $test = $args->{test}; 
    13     my $url   = $self->{config}->{url}; 
    14     my $match = $self->{config}->{match}; 
     12    my $test = $context->test; 
    1513 
    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    } 
    2128} 
    2229 
  • library/perl/trunk/Assurer/lib/Assurer/Test.pm

    r347 r351  
    55 
    66use Test::Builder; 
    7 use Term::ANSIColor
     7use Test::TAP::Model
    88 
    99our $AUTOLOAD; 
    1010 
    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  
    1711sub new { 
    1812    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 
    2021    bless $self, $class; 
    2122    return $self; 
     23} 
     24 
     25sub 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); 
    2238} 
    2339 
     
    3046     my $code   = sub { 
    3147         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(@_); 
    5649     }; 
    5750 
     
    5952     *{$func} = $code; 
    6053     goto &$code; 
    61 
     54
    6255 
    6356{ 
     
    6962        return unless @msgs; 
    7063 
    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/; 
    7467    }; 
    7568}