File: 01_load.t

package info (click to toggle)
libpoe-component-irc-perl 6.35%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,520 kB
  • ctags: 1,061
  • sloc: perl: 14,612; sh: 48; makefile: 5
file content (74 lines) | stat: -rw-r--r-- 1,787 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use strict;
use warnings;
use POE qw(Filter::Line);
use POE::Component::IRC;
use POE::Component::IRC::Plugin::FollowTail;
use Test::More;

my $fh;
eval {
    open $fh, '>', 'followtail' or die "$!\n";
    $fh->autoflush(1);
    print $fh "moocow\n";
};

if ($@) {
    plan skip_all => "Couldn't create a file and write to it";
}

plan tests => 5;
my $bot = POE::Component::IRC->spawn( plugin_debug => 1 );

POE::Session->create(
    package_states => [
        main => [ qw(_start irc_plugin_add irc_plugin_del irc_tail_input) ],
    ],
);

$poe_kernel->run();

sub _start {
    $bot->yield(register => 'all');

    my $plugin = POE::Component::IRC::Plugin::FollowTail->new( 
        filename => 'followtail',
        filter   => POE::Filter::Line->new(),
    );
    
    isa_ok($plugin, 'POE::Component::IRC::Plugin::FollowTail');
  
    if (!$bot->plugin_add('TestPlugin', $plugin) ) {
        fail('plugin_add failed');
        $bot->yield('shutdown');
    }
}

sub irc_plugin_add {
    my ($name, $plugin) = @_[ARG0, ARG1];
    return if $name ne 'TestPlugin';
    
    isa_ok($plugin, 'POE::Component::IRC::Plugin::FollowTail');
    print $fh "Cows go moo, yes they do\n";
}

sub irc_tail_input {
    my ($sender, $filename, $input) = @_[SENDER, ARG0, ARG1];
    my $irc = $sender->get_heap();
    
    is($filename, 'followtail', 'Filename is okay');
    is($input, 'Cows go moo, yes they do', 'Cows go moo!');

    if (!$irc->plugin_del('TestPlugin')) {
        fail('plugin_del failed');
        $irc->yield('shutdown');
    }
}

sub irc_plugin_del {
    my ($sender, $name, $plugin) = @_[SENDER, ARG0, ARG1];
    my $irc = $sender->get_heap();
    return if $name ne 'TestPlugin';

    isa_ok($plugin, 'POE::Component::IRC::Plugin::FollowTail'); 
    $irc->yield('shutdown');
}