aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Feist <shabble@metavore.org>2011-02-28 00:32:04 +0000
committerTom Feist <shabble@metavore.org>2011-02-28 00:32:04 +0000
commit1063657c9145eed77b9228066488c91880093391 (patch)
tree0c83a09d88e70150bef99c3d301c2b20f714445d
parentrandom checkin, thinks are a bit in flux and about to change greatly so I'm (diff)
downloadirssi-scripts-1063657c9145eed77b9228066488c91880093391.tar.gz
irssi-scripts-1063657c9145eed77b9228066488c91880093391.zip
refactor everything to make tests more test-like.
-rw-r--r--testing/lib/Test/Irssi.pm29
-rw-r--r--testing/lib/Test/Irssi/Driver.pm40
-rw-r--r--testing/lib/Test/Irssi/Test.pm14
-rwxr-xr-xtesting/test.pl6
4 files changed, 47 insertions, 42 deletions
diff --git a/testing/lib/Test/Irssi.pm b/testing/lib/Test/Irssi.pm
index 65e22b6..d776573 100644
--- a/testing/lib/Test/Irssi.pm
+++ b/testing/lib/Test/Irssi.pm
@@ -104,8 +104,9 @@ class Test::Irssi {
default => sub { [] },
traits => [qw/Array/],
handles => {
- add_pending_test => 'push',
- next_pending_test => 'pop',
+ add_pending_test => 'push',
+ next_pending_test => 'shift',
+ tests_remaining => 'count',
}
);
@@ -130,7 +131,8 @@ class Test::Irssi {
sub new_test {
my ($self, $name, @params) = @_;
my $new = Test::Irssi::Test->new(name => $name, parent => $self);
- $self->add_pending_test, $new;
+ $self->add_pending_test($new);
+ return $new;
}
method _build_callback_obj {
@@ -170,17 +172,14 @@ class Test::Irssi {
}
- sub log {
- my ($self, $msg) = @_;
- $self->_logfile_fh->say($msg);
- }
-
- method run_test {
+ method complete_test {
# put the completed one onto the completed pile
my $old_test = $self->active_test;
$self->add_completed_test($old_test);
+ }
+ method run_test {
# and make the next pending one active.
my $test = $self->next_pending_test;
$self->active_test($test);
@@ -238,11 +237,17 @@ class Test::Irssi {
}
method summarise_test_results {
- foreach my $t_name (sort keys %{$self->tests}) {
- my $t_obj = $self->tests->{$t_name};
- printf("Test %s\t\t-\t%s\n", $t_name, $t_obj->passed?"pass":"fail");
+ foreach my $test ($self->completed_tests) {
+ my $name = $test->name;
+ printf("Test %s\t\t-\t%s\n", $name, $test->passed?"pass":"fail");
}
}
+
+ sub log {
+ my ($self, $msg) = @_;
+ $self->_logfile_fh->say($msg);
+ }
+
}
__END__
diff --git a/testing/lib/Test/Irssi/Driver.pm b/testing/lib/Test/Irssi/Driver.pm
index 80199ef..3b6000b 100644
--- a/testing/lib/Test/Irssi/Driver.pm
+++ b/testing/lib/Test/Irssi/Driver.pm
@@ -39,6 +39,7 @@ sub START {
InputEvent => "got_terminal_stdin",
Filter => POE::Filter::Stream->new(),
);
+
$self->log("stdio options: " . dump(@stdio_options));
# Start the terminal reader/writer.
@@ -75,7 +76,7 @@ sub STOP {
$self->parent->_logfile_fh->close();
say "\n\n";
- $self->parent->summarise_test_results();
+ #$self->parent->summarise_test_results();
}
### Handle terminal STDIN. Send it to the background program's STDIN.
@@ -161,32 +162,35 @@ sub testing_ready {
# begin by fetching a test from the pending queue.
$self->log("Starting to run tests");
$self->log("-" x 80);
- $self->parent->run_tests();
+ $self->parent->run_test;
+}
+
+sub execute_test {
+ my ($self, $heap, $kernel, $test) = @_[OBJECT,HEAP, KERNEL, ARG0];
+ # do some stuff here to evaluate it.
+
+ $test->evaluate_test;
+
}
-sub testing_complete {
+sub test_complete {
my ($self, $kernel) = @_[OBJECT, KERNEL];
- # make sure all tests have run to completion.
- my $done = 1;
- $self->log("Testing to see if we can quit: ");
- foreach my $test ($self->parent->all_tests) {
- if (not $test->complete) {
- $self->log("\t" . $test->name . " is not complete");
- $done = 0;
- }
- }
- if ($done) {
- $kernel->yield('shutdown');
- } else {
- # ???
- $self->parent->active_test->resume_from_timer;
+
+ $self->parent->complete_test;
+
+ if ($self->parent->tests_remaining) {
+ $self->parent->run_test;
}
+
+ # otherwise, we're done, and can shutdown.
+ #$kernel->yield('shutdown');
+
}
sub timer_created {
my ($self, $heap, $kernel, $duration) = @_[OBJECT, HEAP, KERNEL, ARG0];
$kernel->delay(got_delay => $duration);
- $self->log("Timer created");
+ $self->log("Timer created for $duration");
}
sub timer_expired {
diff --git a/testing/lib/Test/Irssi/Test.pm b/testing/lib/Test/Irssi/Test.pm
index 45e9bb1..7ee511f 100644
--- a/testing/lib/Test/Irssi/Test.pm
+++ b/testing/lib/Test/Irssi/Test.pm
@@ -7,6 +7,7 @@ class Test::Irssi::Test {
use Test::Irssi;
use Test::Irssi::Driver;
use feature qw/say/;
+ use Data::Dump qw/dump/;
has 'parent'
=> (
@@ -167,17 +168,11 @@ class Test::Irssi::Test {
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) = @_;
while (my $state = $self->get_next_state) {
+ $self->log("Evaluating Test: " . dump($state));
# stimuli
if ( exists($state->{delay})) {
@@ -208,11 +203,12 @@ class Test::Irssi::Test {
}
}
+
+ $poe_kernel->post(IrssiTestDriver => 'test_complete');
+
$self->complete(1);
$self->log("Test Execution Finished");
-
- $poe_kernel->post('IrssiTestDriver' => 'test_complete');
}
sub resume_from_timer {
diff --git a/testing/test.pl b/testing/test.pl
index d505758..ea90e1c 100755
--- a/testing/test.pl
+++ b/testing/test.pl
@@ -19,8 +19,8 @@ say "Created test instance";
my $test = $tester->new_test('test1');
-$test->add_input_sequence("/echo Hello\n");
-$test->add_delay(2);
+$test->add_input_sequence("/echo Hello cats\n");
+$test->add_delay(20);
$test->add_input_sequence("/echo Hello Again\n");
for (1..10) {
$test->add_input_sequence($_);
@@ -37,7 +37,7 @@ $test->add_input_sequence("/clear\n");
my $test2 = $tester->new_test("Test2");
-$test2->add_input_sequence("hello");
+$test2->add_input_sequence("hello from twooooooo");
$test2->add_delay(5);
$test2->add_pattern_match(qr/hello/, 'prompt', 'hello');