File Coverage

File:t/bot-irc-run.t
Coverage:100.0%

linestmtbrancondsubpodtimecode
1
1
1
1
40652
8
50
use strict;
2
1
1
1
9
4
54
use warnings;
3
4
1
1
1
2756
875941
14
use Test::Most;
5
1
1
1
1250593
113535
555
use Test::MockModule;
6
1
1
1
59662
1004088
27
use Test::Output;
7
8
1
932133
my $socket = Test::MockModule->new('IO::Socket::INET');
9$socket->mock( new => sub {
10
1
18
    return bless( {}, shift );
11
1
50
} );
12
1
100
$socket->mock( print => sub {} );
13
14
1
59
my $device = Test::MockModule->new('Daemon::Device');
15$device->mock( new => sub {
16
1
9
    return bless( {}, shift );
17
1
52
} );
18
1
164
$device->mock( run => sub {} );
19
1
1
64
9
$device->mock( ppid => sub { return 42 } );
20
1
1
42
9
$device->mock( children => sub { return [ 1024, 1138 ] } );
21
1
69
$device->mock( message => sub {} );
22
23
1
1
1
3111
7
692
use constant MODULE => 'Bot::IRC';
24
25
1
1
1
1
1
48
5565
65
58
6170
BEGIN { use_ok(MODULE); }
26
27
1
65
my $settings = {
28    spawn  => 3,
29    daemon => {
30        name        => 'bot',
31        lsb_sdesc   => 'IRC Bot',
32        pid_file    => 'bot.pid',
33        stderr_file => 'bot.err',
34        stdout_file => 'bot.log',
35    },
36    connect => {
37        server => 'irc.perl.org',
38        port   => '6667',
39        nick   => 'bot',
40        name   => 'Yet Another IRC Bot',
41        join   => [ '#test', '#perl' ],
42        ssl    => 0,
43    },
44};
45
46
1
7
my $bot;
47
1
37
lives_ok( sub { $bot = MODULE->new(
48    %$settings,
49
1
25
) }, MODULE . '->new(@config)' );
50
51
1
1
633
142
lives_ok( sub { $bot->run }, MODULE . '->run' );
52
53stdout_is(
54
1
8500
    sub { $bot->say( qw( line0 line1 ) ) },
55
1
184
    "<<< line0\n<<< line1\n",
56    '$bot->say',
57);
58
59stdout_is(
60
1
643
    sub { $bot->msg( '#test', 'Message.' ) },
61
1
1634
    "<<< PRIVMSG #test :Message.\n",
62    '$bot->msg',
63);
64
65warning_like(
66
1
63
    sub { $bot->reply('Message.') },
67
1
565
    qr/Didn't have a target to send reply to/,
68    '$bot->reply without forum',
69);
70
71stdout_is(
72
1
1243
    sub { $bot->nick('new') },
73
1
268
    "<<< NICK new\n",
74    '$bot->nick',
75);
76
77
1
2081
done_testing;