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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
use strictures 1;
use MooseX::Declare;
our $VERSION = 0.01;
class Test::Irssi {
# requires the latest pre-release POE from
# https://github.com/rcaputo/poe until a new release is...released.
use lib $ENV{HOME} . "/projects/poe/lib";
use POE;
use Term::VT102;
use Term::Terminfo;
use feature qw/say switch/;
use Data::Dump;
use IO::File;
use Test::Irssi::Driver;
use Test::Irssi::Callbacks;
use Test::Irssi::API;
has 'irssi_binary'
=> (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'irssi_homedir'
=> (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'terminal_width'
=> (
is => 'ro',
isa => 'Int',
required => 1,
default => 80,
);
has 'terminal_height'
=> (
is => 'ro',
isa => 'Int',
required => 1,
default => 24,
);
has 'vt'
=> (
is => 'ro',
isa => 'Term::VT102',
required => 1,
lazy => 1,
builder => '_build_vt_obj',
);
has 'logfile'
=> (
is => 'ro',
isa => 'Str',
required => 1,
default => 'irssi-test.log',
);
has '_logfile_fh'
=> (
is => 'ro',
isa => 'IO::File',
required => 1,
lazy => 1,
builder => '_build_logfile_fh',
);
has '_driver'
=> (
is => 'ro',
isa => 'Test::Irssi::Driver',
required => 1,
lazy => 1,
builder => '_build_driver_obj',
);
has '_callbacks'
=> (
is => 'ro',
isa => 'Test::Irssi::Callbacks',
required => 1,
lazy => 1,
builder => '_build_callback_obj',
);
has 'api'
=> (
is => 'ro',
isa => "Test::Irssi::API",
required => 1,
lazy => 1,
builder => "_build_api"
);
method _build_api {
Test::Irssi::API->new(parent => $self);
}
method _build_callback_obj {
Test::Irssi::Callbacks->new(parent => $self);
}
method _build_driver_obj {
Test::Irssi::Driver->new(parent => $self);
}
method _build_vt_obj {
my $rows = $self->terminal_height;
my $cols = $self->terminal_width;
Term::VT102->new($cols, $rows);
}
method _build_logfile_fh {
my $logfile = $self->logfile;
my $fh = IO::File->new($logfile, 'w');
die "Couldn't open $logfile for writing: $!" unless defined $fh;
$fh->autoflush(1);
return $fh;
}
method _vt_setup {
# options
my $vt = $self->vt;
$vt->option_set(LINEWRAP => 1);
$vt->option_set(LFTOCRLF => 1);
$self->_callbacks->register_callbacks;;
}
sub log {
my ($self, $msg) = @_;
$self->_logfile_fh->say($msg);
}
method run {
$self->_driver->setup;
$self->_vt_setup;
$self->log("Driver setup complete");
### Start a session to encapsulate the previous features.
$poe_kernel->run();
}
sub inject_text {
my ($self, $text) = @_;
$poe_kernel->post(IrssiTestDriver => got_terminal_stdin
=> $text);
}
sub simulate_keystroke {
my ($self, $text) = @_;
$poe_kernel->post(IrssiTestDriver => got_terminal_stdin
=> $text);
}
method get_prompt_line {
return $self->vt->row_plaintext($self->terminal_height)
}
method get_window_statusbar_line {
return $self->vt->row_plaintext($self->terminal_height() - 1)
}
}
__END__
=head1 NAME
Test::Irssi - A cunning testing system for Irssi scripts
=head1 SYNOPSIS
blah blah blah
|