Changeset 346

Show
Ignore:
Timestamp:
01/08/07 00:55:49 (2 years ago)
Author:
miya
Message:

Assurer: Split plugin phases to test, format, publish.
Add Assurer::Results class.

Files:

Legend:

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

    r345 r346  
    11global: 
    22  config: 
    3     no_diag: 1 
     3    no_diag: 0 
    44 
    5 plugins
     5test
    66  - module: HTTP 
    77    name: http://svn.mizzy.org/ #0 
  • library/perl/trunk/Assurer/lib/Assurer.pm

    r345 r346  
    4343    $args ||= {}; 
    4444 
    45     for my $plugin ( @{ $self->{config}->{plugins} } ) { 
    46         my $class = "Assurer::Plugin::$plugin->{module}"; 
    47         $class->use or die $@; 
    48  
    49         $class->new({ 
    50             config => $plugin->{config}, 
    51             name   => $plugin->{name}, 
    52         })->run; 
     45    $self->load_plugins; 
     46 
     47    $self->run_hook('test'); 
     48    $self->run_hook('format'); 
     49    $self->run_hook('publish'); 
     50
     51 
     52sub run_hook { 
     53    my ( $self, $hook, $args ) = @_; 
     54    $args ||= {}; 
     55 
     56    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'); 
     66    } 
     67
     68 
     69sub load_plugins { 
     70    my $self = shift; 
     71 
     72    for my $hook ( qw/test format publish/ ) { 
     73        for my $plugin ( @{ $self->{config}->{$hook} || [] } ) { 
     74            my $class = "Assurer::Plugin::" . ucfirst $hook . "::$plugin->{module}"; 
     75            $class->use or die $@; 
     76            push @{ $self->{hooks}->{$hook} }, $class->new($plugin); 
     77        } 
    5378    } 
    5479} 
     
    5984} 
    6085 
     86sub add_result { 
     87    my $self = shift; 
     88    push @{ $self->{results} }, shift; 
     89} 
     90 
     91sub results { 
     92    return shift->{results}; 
     93} 
    61941; # Magic true value required at end of module 
    6295__END__ 
  • library/perl/trunk/Assurer/lib/Assurer/Plugin.pm

    r345 r346  
    44use warnings; 
    55use UNIVERSAL::require; 
     6use Assurer::Results; 
    67 
    78sub new { 
     
    1213    bless $self, $class; 
    1314 
    14     my $name = $self->{name} || 'no name'
    15     $self->log('info', "Testing $name"); 
     15    $self->init
     16 
    1617    return $self; 
     18} 
     19 
     20sub init { 
     21 
    1722} 
    1823 
  • library/perl/trunk/Assurer/lib/Assurer/Test.pm

    r345 r346  
    3131my $diag; 
    3232 
     33sub new { 
     34    my $class = shift; 
     35    my $self = { plugin => shift }; 
     36    bless $self, $class; 
     37    return $self; 
     38} 
     39 
    3340sub AUTOLOAD { 
    34      my ($self) = @_; 
    3541     my $func   = $AUTOLOAD; 
    3642     return if $func =~ /::DESTROY$/; 
     
    3945 
    4046     my $code   = sub { 
    41          my $memfile; 
    42          open my $out, '>', \$memfile; 
     47         my $self = shift; 
     48 
     49         my $result; 
     50         open my $out, '>', \$result; 
    4351         $test->output($out); 
    44  
    4552         $test->$method(@_); 
    4653 
    47          if ( $memfile =~ /^ok/ ) { 
     54         if ( $result =~ /^ok/ ) { 
    4855             print color 'blue'; 
    4956         } 
     
    5259         } 
    5360 
    54          print "$memfile"; 
     61         print "$result"; 
    5562 
    5663         print color 'reset'; 
    5764         print $diag if $diag; 
     65 
     66         $self->{plugin}->{results}->add({ 
     67             result => $result, 
     68             diag   => $diag, 
     69         }); 
    5870 
    5971         $diag = '';