aboutsummaryrefslogtreecommitdiffstats
path: root/testing/lib/Test/Irssi/API.pm
diff options
context:
space:
mode:
authorTom Feist <shabble@metavore.org>2011-02-24 01:59:38 +0000
committerTom Feist <shabble@metavore.org>2011-02-24 01:59:38 +0000
commit754328bfe7acbc9409fd4d38340d76aabf96845c (patch)
tree8f8ec9ab17dce112c9b3e4f0c8a24ba45ffc2d2c /testing/lib/Test/Irssi/API.pm
parentadded test and launcher script (diff)
downloadirssi-scripts-754328bfe7acbc9409fd4d38340d76aabf96845c.tar.gz
irssi-scripts-754328bfe7acbc9409fd4d38340d76aabf96845c.zip
more work on testing system for irssi. Most of the screenscraping now works,
trying to finalise an API for actual testing usage.
Diffstat (limited to 'testing/lib/Test/Irssi/API.pm')
-rw-r--r--testing/lib/Test/Irssi/API.pm80
1 files changed, 80 insertions, 0 deletions
diff --git a/testing/lib/Test/Irssi/API.pm b/testing/lib/Test/Irssi/API.pm
new file mode 100644
index 0000000..3a659ed
--- /dev/null
+++ b/testing/lib/Test/Irssi/API.pm
@@ -0,0 +1,80 @@
+use strictures 1;
+use MooseX::Declare;
+
+class Test::Irssi::API {
+
+ use POE;
+ use Data::Dumper;
+
+ has 'parent'
+ => (
+ is => 'ro',
+ isa => 'Test::Irssi',
+ required => 1,
+ );
+
+
+ has 'tests'
+ => (
+ traits => [qw/Hash/],
+ is => 'rw',
+ isa => 'HashRef',
+ default => sub { {} },
+ handles => {
+ test_names => 'keys',
+ },
+ );
+
+
+ sub create_test {
+ my ($self, $name, $desc) = @_;
+ $self->tests->{$name} = {desc => $desc, input => [], output => []};
+ }
+
+ sub simulate_input {
+ my ($self, $name, $input) = @_;
+ push @{ $self->tests->{$name}->{input} }, { input => $input };
+ }
+
+ sub simulate_delay {
+ my ($self, $name, $delay) = @_;
+ push @{ $self->tests->{$name}->{input} }, { delay => $delay };
+
+ }
+
+ sub expect_output {
+ my ($self, $name, $regex, $line) = @_; # line is optional?
+ push @{ $self->tests->{$name}->{output} }, { regex => $regex, line => $line };
+ }
+
+ sub run_test {
+ my ($self, $test_name) = @_;
+ my $data = $self->tests->{$test_name};
+ foreach my $entry (@{ $data->{input} }) {
+ if (exists $entry->{input}) {
+ my $text = $entry->{input};
+ $self->parent->inject_text($text);
+ } elsif (exists $entry->{delay}) {
+ my $delay = $entry->{delay};
+ _do_delay($delay);
+ } else {
+ die "What: " . Dumper($entry);
+ }
+ }
+ }
+
+ sub run_tests {
+ my ($self) = @_;
+ foreach my $test_name ($self->test_names) {
+ my $test = $self->tests->{$test_name};
+ print "Going to prcess: $test_name";
+ print Dumper($test);
+
+ }
+ }
+
+
+ sub _do_delay {
+ $poe_kernel->post('IrssiTestDriver' => create_delay => 5);
+ }
+}