Changeset 2228


Ignore:
Timestamp:
12/28/08 17:01:15 (3 years ago)
Author:
adamk
Message:

Fixing the test suite to pass again

Location:
trunk/Padre
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/PluginManager.pm

    r2226 r2228  
    274274    my $plugins = $self->plugins; 
    275275    return grep { 
    276         $plugins->{$_}->{status} eq 'failed' 
     276        $plugins->{$_}->{status} eq 'error' 
    277277    } keys %$plugins; 
    278278} 
     
    385385            $@, 
    386386        ); 
    387         $plugin->status('failed'); 
     387        $plugin->status('error'); 
    388388        return; 
    389389    } 
     
    397397            ), $name, 
    398398        ); 
    399         $plugin->status('failed'); 
     399        $plugin->status('error'); 
    400400        return; 
    401401    } 
     
    409409            ), $name, 
    410410        ); 
    411         $plugin->status('failed'); 
     411        $plugin->status('error'); 
    412412        return; 
    413413    } 
     
    422422            $name, 
    423423        ); 
    424         $plugin->status('failed'); 
     424        $plugin->status('error'); 
    425425        return; 
    426426    } 
     
    431431        # TODO report error in a nicer way 
    432432        $self->{errstr} = $@; 
    433         $plugin->status('failed'); 
     433        $plugin->status('error'); 
    434434        return; 
    435435    } 
     
    442442            $name, 
    443443        ); 
    444         $plugin->status('failed'); 
     444        $plugin->status('error'); 
    445445        return; 
    446446    } 
     
    503503    # Unload the plugin class itself 
    504504    require Class::Unload; 
    505     Class::Unload->unload($handle->module); 
     505    Class::Unload->unload($handle->class); 
    506506 
    507507    # Finally, remove the handle (and flush the sort order) 
     
    696696    $config->{plugins}->{$filename}->{enabled} = 1; 
    697697    $self->load_plugin($filename); 
    698     if ( $self->plugins->{$filename}->{status} eq 'failed' ) { 
     698    if ( $self->plugins->{$filename}->{status} eq 'error' ) { 
    699699        $main->error(sprintf(Wx::gettext("Failed to load the plugin '%s'"), $filename)); 
    700700        return; 
  • trunk/Padre/t/82-plugin-manager.t

    r2169 r2228  
    44use warnings; 
    55 
    6 use FindBin      qw($Bin); 
    7 use File::Spec   (); 
    8 use Data::Dumper qw(Dumper); 
    9  
    106use Test::More; 
    117BEGIN { 
    12     if (not $ENV{DISPLAY} and not $^O eq 'MSWin32') { 
     8    unless ( $ENV{DISPLAY} or $^O eq 'MSWin32' ) { 
    139        plan skip_all => 'Needs DISPLAY'; 
    1410        exit 0; 
     
    1612} 
    1713 
    18 plan tests => 25; 
     14plan tests => 23; 
    1915 
     16use FindBin      qw($Bin); 
     17use File::Spec   (); 
     18use Data::Dumper qw(Dumper); 
    2019use Test::NoWarnings; 
    21  
    2220use t::lib::Padre; 
    2321use Padre; 
     22use Padre::PluginManager; 
    2423 
    25 use_ok('Padre::PluginManager'); 
     24my $padre = Padre->new; 
    2625 
    27 my $padre = Padre->new(); 
    28 my $plugin_m1 = Padre::PluginManager->new($padre); 
    29 isa_ok $plugin_m1, 'Padre::PluginManager'; 
     26# Test the default loading behaviour 
     27SCOPE: { 
     28    my $manager = Padre::PluginManager->new($padre); 
     29    isa_ok( $manager, 'Padre::PluginManager' ); 
     30    is( 
     31        $manager->plugin_dir, 
     32        Padre::Config->default_plugin_dir, 
     33        '->default_plugin_dir ok', 
     34    ); 
     35    is( keys %{$manager->plugins}, 0, 'Found no plugins' ); 
     36    ok( 
     37        ! defined($manager->load_plugins()), 
     38        'load_plugins always returns undef' 
     39    ); 
    3040 
    31 is $plugin_m1->plugin_dir, Padre::Config->default_plugin_dir; 
    32 is keys %{$plugin_m1->plugins}, 0; 
    33  
    34 ok !defined($plugin_m1->load_plugins()), 'load_plugins always returns undef'; 
    35  
    36  
    37 # check if we have the plugins that come with Padre 
    38 cmp_ok (keys %{$plugin_m1->plugins}, '>=', 1); 
    39 #is $plugin_m1->plugins->{'Development::Tools'},  'Padre::Plugin::Development::Tools'; 
    40 ok !$plugin_m1->plugins->{'Development::Tools'},  'no second level plugin'; 
    41  
    42 # try load again 
    43 #{ 
    44 #my $st = $plugin_m1->load_plugin('Development::Tools'); 
    45 #is $st, undef; 
    46 #} 
     41    # check if we have the plugins that come with Padre 
     42    cmp_ok( keys %{$manager->plugins}, '>=', 1, 'Loaded at least one plugin' ); 
     43    ok( ! $manager->plugins->{'Development::Tools'}, 'No second level plugin' ); 
     44} 
    4745 
    4846## Test loading single plugins 
    49 $plugin_m1 = Padre::PluginManager->new($padre); 
    50 is keys %{$plugin_m1->plugins}, 0; 
    51 ok(!$plugin_m1->load_plugin('My')); 
    52 is keys %{$plugin_m1->plugins}, 1; 
    53 is( $plugin_m1->plugins->{My}{status}, 'disabled' ); 
    54 $padre->config->{plugins}{My}{enabled} = 1; 
    55 ok($plugin_m1->load_plugin('My')); 
    56 is( $plugin_m1->plugins->{My}{status}, 'enabled' ); 
    57 ok($plugin_m1->reload_plugin('My')); 
    58 is( $plugin_m1->plugins->{My}{status}, 'enabled' ); 
    59 ok($plugin_m1->unload_plugin('My')); 
    60 ok( !defined($plugin_m1->plugins->{My}) ); 
    61  
     47SCOPE: { 
     48    my $manager = Padre::PluginManager->new($padre); 
     49    is( keys %{$manager->plugins}, 0, 'No plugins loaded' ); 
     50    ok( ! $manager->load_plugin('My'), 'Loaded My Plugin' ); 
     51    is( keys %{$manager->plugins}, 1, 'Loaded something' ); 
     52    my $handle = $manager->_plugin('My'); 
     53    isa_ok( $handle, 'Padre::PluginHandle' ); 
     54    is( $handle->name, 'My', 'Loaded My Plugin' ); 
     55    ok( $handle->disabled, 'My Plugin is disabled' ); 
     56    ok( $manager->unload_plugin('My'), '->unload_plugin ok' ); 
     57    ok( ! defined($manager->plugins->{My}), 'Plugin no longer loaded' ); 
     58    is( eval("\$Padre::Plugin::My::VERSION"), undef, 'My Plugin was cleaned up' ); 
     59} 
    6260 
    6361## Test With custom plugins 
    64 my $custom_dir = File::Spec->catfile( $Bin, 'lib' ); 
    65 my $plugin_m2  = Padre::PluginManager->new($padre, plugin_dir => $custom_dir); 
     62SCOPE: { 
     63    my $custom_dir = File::Spec->catfile( $Bin, 'lib' ); 
     64    my $manager  = Padre::PluginManager->new($padre, plugin_dir => $custom_dir); 
     65    is( $manager->plugin_dir, $custom_dir ); 
     66    is( keys %{$manager->plugins}, 0 ); 
    6667 
    67 is $plugin_m2->plugin_dir, $custom_dir; 
    68 is keys %{$plugin_m2->plugins}, 0; 
     68    $manager->_load_plugins_from_inc; 
     69    # cannot compare with the exact numbers as there might be plugins already installed 
     70    cmp_ok(keys %{$manager->plugins}, '>=', 3, 'at least 3 plugins') 
     71    or 
     72    diag(Dumper(\$manager->plugins)); 
    6973 
    70 $plugin_m2->_load_plugins_from_inc(); 
    71 # cannot compare with the exact numbers as there might be plugins already installed 
    72 cmp_ok (keys %{$plugin_m2->plugins}, '>=', 3, 'at least 3 plugins') 
    73     or diag(Dumper(\$plugin_m2->plugins)); 
     74    ok( ! exists $manager->plugins->{'Development::Tools'},  'no second level plugin' ); 
     75    is( $manager->_plugin('TestPlugin')->class, 'Padre::Plugin::TestPlugin' ); 
     76    ok( !defined $manager->plugins->{'Test::Plugin'},        'no second level plugin' ); 
    7477 
    75 #is $plugin_m2->plugins->{'Development::Tools'},  'Padre::Plugin::Development::Tools'; 
    76 ok !exists $plugin_m2->plugins->{'Development::Tools'},  'no second level plugin'; 
    77 is $plugin_m2->plugins->{TestPlugin}{module},     'Padre::Plugin::TestPlugin'; 
    78 #is $plugin_m2->plugins->{'Test::Plugin'},        'Padre::Plugin::Test::Plugin'; 
    79 ok !defined $plugin_m2->plugins->{'Test::Plugin'},        'no second level plugin'; 
    80  
    81 # try load again 
    82 { 
    83     my $st = $plugin_m2->load_plugin('TestPlugin'); 
    84     is $st, undef; 
     78    # try load again 
     79    my $st = $manager->load_plugin('TestPlugin'); 
     80    is( $st, undef ); 
    8581} 
    86  
    87 ### XXX? TODO, test par 
    88  
    89 1; 
Note: See TracChangeset for help on using the changeset viewer.