aboutsummaryrefslogtreecommitdiffstats
path: root/testing/lib/Test/Irssi/Test.pm
diff options
context:
space:
mode:
authorTom Feist <shabble@metavore.org>2011-02-26 00:37:11 +0000
committerTom Feist <shabble@metavore.org>2011-02-26 00:37:11 +0000
commitbf563d29e40e6bb6cb9732b4457e633468a8c6c2 (patch)
treefddb146dd73cf06f75d21801cd70d89a487dae7f /testing/lib/Test/Irssi/Test.pm
parentadded T:I:T as the base object for creating tests with. (diff)
downloadirssi-scripts-bf563d29e40e6bb6cb9732b4457e633468a8c6c2.tar.gz
irssi-scripts-bf563d29e40e6bb6cb9732b4457e633468a8c6c2.zip
lots of work moving things around so it mostly works. Hooray
Diffstat (limited to 'testing/lib/Test/Irssi/Test.pm')
-rw-r--r--testing/lib/Test/Irssi/Test.pm168
1 files changed, 165 insertions, 3 deletions
diff --git a/testing/lib/Test/Irssi/Test.pm b/testing/lib/Test/Irssi/Test.pm
index f1e217d..ca53739 100644
--- a/testing/lib/Test/Irssi/Test.pm
+++ b/testing/lib/Test/Irssi/Test.pm
@@ -3,8 +3,170 @@ use MooseX::Declare;
class Test::Irssi::Test {
- has 'items'
+ use Test::Irssi;
+ use Test::Irssi::Driver;
+ use feature qw/say/;
+
+ has 'parent'
+ => (
+ is => 'ro',
+ isa => 'Test::Irssi',
+ required => 1,
+ );
+ has 'name'
+ => (
+ is => 'ro',
+ isa => 'Str',
+ required => 1,
+ );
+
+ has 'description'
+ => (
+ is => 'rw',
+ isa => 'Str',
+ default => '',
+ );
+
+ has 'states'
+ => (
+ is => 'ro',
+ isa => 'ArrayRef',
+ traits => [qw/Array/],
+ default => sub { [] },
+ lazy => 1,
+ handles => {
+ add_state => 'push',
+ state_count => 'count',
+ get_state => 'get',
+ },
+ );
+
+ has 'results'
+ => (
+ is => 'ro',
+ isa => 'ArrayRef',
+ default => sub { [] },
+ );
+
+ has '_next_state'
=> (
-
+ is => 'rw',
+ isa => 'Int',
+ default => 0,
+ traits => [qw/Counter/],
+ handles => {
+ _increment_state_counter => 'inc',
+ _clear_state => 'reset',
+ },
);
-}c
+
+
+ method add_input_sequence(Str $input) {
+ $self->add_state({input => $input });
+ $self->log("Adding $input as input");
+ }
+
+ method add_delay (Num $delay) {
+ $self->add_state({delay => $delay });
+ $self->log("Adding $delay as delay");
+
+ }
+
+ sub add_pattern_match {
+ my ($self, $pattern, $constraints) = @_;
+ $self->add_state({output => 1,
+ pattern => $expected,
+ constraints => $constraints});
+
+ $self->log("Adding $expected as output match ");
+ }
+
+ sub add_evaluation_function {
+ my ($self, $coderef) = @_;
+ $self->add_state({code => $coderef});
+ }
+
+ method process_next_state {
+ my $state_num = $self->_next_state;
+ $self->log("PNS: $state_num");
+ my $state = $self->states->[$state_num];
+
+ my $return = 0;
+
+
+ $self->_next_state($state_num+1);
+ if ($self->has_next_state) {
+ $self->log("Has another state");
+ } else {
+ $self->log("Has no more state");
+
+ return 2;
+ }
+
+ return $return;
+ }
+
+ sub check_output {
+ my ($self, $pattern) = @_;
+ say "All Goodn\n\n";
+ }
+
+ sub get_next_state {
+ my ($self) = @_;
+ my $item = $self->get_state($self->_next_state);
+ $self->_increment_state_counter;
+
+ return $item;
+ }
+
+ sub execute {
+ my ($self) = @_;
+ # set this as hte currently active test.
+ $self->parent->active_test($self);
+ $self->evaluate_test;
+ }
+
+ sub evaluate_test {
+
+ my ($self) = @_;
+ $self->log("Eval Test:");
+ while (my $state = $self->get_next_state) {
+ if ( exists($state->{delay})) {
+ $self->parent->apply_delay($state->{delay});
+ return;
+ } else {
+
+ if (exists $state->{input}) {
+ $self->parent->inject_text($state->{input});
+ $self->log("input: ". $state->{input});
+ }
+
+ if (exists $state->{code}) {
+ my @args = ($self, $self->parent, $self->parent->vt);
+ my $ret = $state->{code}->(@args);
+
+ if (exists $state->{output}) {
+ my $pattern = $state->{pattern};
+ $self->check_output($pattern);
+ }
+
+ }
+ }
+ $self->log("Execution Finished");
+ }
+
+ sub resume_from_timer {
+ my ($self) = @_;
+ $self->log("Resuming after timeout");
+ $self->evaluate_test;
+ }
+ sub log {
+ my ($self, $msg) = @_;
+ $self->parent->_logfile_fh->say($msg);
+ }
+
+}
+
+
+
+ __END__