From 7ec10e516a04a05a85cb82b30a8f9982f13c6c90 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 4 Mar 2011 04:12:47 +0000 Subject: working with TAP::Harness --- testing/lib/Test/Irssi.pm | 24 +++++++++++++++++----- testing/t/002-init.t | 2 +- testing/test.pl | 46 ++++++++--------------------------------- testing/test2.pl | 38 ---------------------------------- testing/test3.pl | 47 ------------------------------------------ testing/tests/001-basic.t | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 128 deletions(-) delete mode 100755 testing/test2.pl delete mode 100755 testing/test3.pl create mode 100755 testing/tests/001-basic.t (limited to 'testing') diff --git a/testing/lib/Test/Irssi.pm b/testing/lib/Test/Irssi.pm index 72f69ed..f723285 100644 --- a/testing/lib/Test/Irssi.pm +++ b/testing/lib/Test/Irssi.pm @@ -1,7 +1,7 @@ use strictures 1; use MooseX::Declare; -our $VERSION = 0.01; +our $VERSION = 0.02; class Test::Irssi { @@ -10,7 +10,6 @@ class Test::Irssi { use lib $ENV{HOME} . "/projects/poe/lib"; use POE; - use Term::VT102; use Term::Terminfo; use feature qw/say switch/; @@ -85,6 +84,9 @@ class Test::Irssi { required => 1, lazy => 1, builder => '_build_driver_obj', + handles => { + run_headless => 'headless', + } ); has '_callbacks' @@ -118,7 +120,8 @@ class Test::Irssi { default => sub { [] }, traits => [qw/Array/], handles => { - add_completed_test => 'push' + add_completed_test => 'push', + tests_completed => 'count', }, ); @@ -176,6 +179,12 @@ class Test::Irssi { # put the completed one onto the completed pile my $old_test = $self->active_test; $self->add_completed_test($old_test); + + # TAP: print status. + my $tap = sprintf("%s %d - %s", $old_test->passed?'ok':'not ok', + $self->tests_completed, + $old_test->description); + say STDOUT $tap; } method run_test { @@ -188,10 +197,15 @@ class Test::Irssi { } method run { + $self->driver->setup; $self->_vt_setup; $self->log("Driver setup complete"); ### Start a session to encapsulate the previous features. + + # TAP: print number of tests. + print STDOUT "1.." . $self->tests_remaining . "\n"; + $poe_kernel->run(); } @@ -248,8 +262,8 @@ class Test::Irssi { method summarise_test_results { foreach my $test (@{$self->completed_tests}) { my $name = $test->name; - printf("Test %s\t\t-\t%s\n", $name, $test->passed?"pass":"fail"); - $test->details(); + #printf("Test %s\t\t-\t%s\n", $name, $test->passed?"pass":"fail"); + #$test->details(); } } diff --git a/testing/t/002-init.t b/testing/t/002-init.t index df61e1e..b688f9f 100755 --- a/testing/t/002-init.t +++ b/testing/t/002-init.t @@ -19,7 +19,7 @@ if (-f $test->logfile) { ok(unlink $test->logfile, 'deleted old logfile'); } -my $drv = $test->_driver; +my $drv = $test->driver; isa_ok($drv, 'Test::Irssi::Driver', 'driver created ok'); diag "Starting POE session"; diff --git a/testing/test.pl b/testing/test.pl index ea90e1c..bf01530 100755 --- a/testing/test.pl +++ b/testing/test.pl @@ -4,42 +4,14 @@ use strict; use warnings; use feature qw/say/; +#use lib 'blib/lib'; -use lib 'blib/lib'; +use TAP::Harness; +my $harness = TAP::Harness->new({ verbosity => 1, + lib => 'blib/lib', + color => 1, + }); -use Test::Irssi; - -my $tester = Test::Irssi->new - (irssi_binary => "/opt/stow/repo/irssi-debug/bin/irssi", - irssi_homedir => $ENV{HOME} . "/projects/tmp/test/irssi-debug"); - -say "Created test instance"; - - - -my $test = $tester->new_test('test1'); - -$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($_); - $test->add_delay(0.2); -} -$test->add_evaluation_function(sub { 1 }, 'this should succeed'); -$test->add_pattern_match(qr/2345/, 'prompt', 'prompt contains numbers'); - -#$test->add_input_sequence("This is\x0acursor movement\x0a"); -# $test->add_delay(5); -$test->add_input_sequence("\n"); - -$test->add_input_sequence("/clear\n"); - - -my $test2 = $tester->new_test("Test2"); -$test2->add_input_sequence("hello from twooooooo"); -$test2->add_delay(5); -$test2->add_pattern_match(qr/hello/, 'prompt', 'hello'); - - -$tester->run; +my @tests = glob($ARGV[0]); +say "Tests: " . join (", ", @tests); +$harness->runtests(@tests); diff --git a/testing/test2.pl b/testing/test2.pl deleted file mode 100755 index 661e66b..0000000 --- a/testing/test2.pl +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; - -use feature qw/say/; - -use lib 'blib/lib'; - -use Test::Irssi; - -my $tester = Test::Irssi->new - (irssi_binary => "/opt/stow/repo/irssi-debug/bin/irssi", - irssi_homedir => $ENV{HOME} . "/projects/tmp/test/irssi-debug"); - -my $test = $tester->new_test('test2'); -$test->add_input_sequence("/echo 'Window one'\n"); -$test->add_delay(5); -$test->add_input_sequence("/window new hide\n"); -$test->add_input_sequence("/win 2\n"); -for (1..10) { - $test->add_input_sequence($_); - $test->add_delay(0.2); -} -$test->add_input_sequence("\x01/echo \x05\n"); -$test->add_delay(10); -$test->add_input_sequence("\x1b\x31"); -$test->add_delay(10); -#$test->add_input_sequence("This is\x0acursor movement\x0a"); -# $test->add_delay(5); - - - -# $test->add_expected_output("Hello"); - - - -$tester->run; diff --git a/testing/test3.pl b/testing/test3.pl deleted file mode 100755 index 57be5ed..0000000 --- a/testing/test3.pl +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; - -use feature qw/say/; - -use lib 'blib/lib'; - -use Test::Irssi; - -my $tester = Test::Irssi->new - (irssi_binary => "/opt/stow/repo/irssi-debug/bin/irssi", - irssi_homedir => $ENV{HOME} . "/projects/tmp/test/irssi-debug"); - -say "Created test instance"; - -my $test = $tester->new_test('test1'); - -$test->add_input_sequence("/echo Hello cats\n"); -$test->add_delay(1); -$test->add_input_sequence("/echo Hello Again\n"); -$test->add_input_sequence("this is a lang test"); -$test->add_pattern_match(qw/long/, 'prompt', 'prompt contains hello'); -$test->add_pattern_match(qw/longfdajkfd/, 'prompt', 'prompt contains hello'); - - -my $test2 = $tester->new_test('test2'); -$test2->add_delay(2); -$test2->add_input_sequence("\x01"); -$test2->add_delay(0.1); -$test2->add_input_sequence("\x0b"); -$test2->add_delay(0.1); -$test2->add_input_sequence("/clear\n"); -$test2->add_delay(0.1); -$test2->add_input_sequence("/echo moo\n"); - -my $quit = $tester->new_test('quit'); -$quit->add_input_sequence("/quit\n"); - -# for (1..10) { -# $test->add_input_sequence("\xff"); -# $test->add_delay(0.1); - -# } - -$tester->run; diff --git a/testing/tests/001-basic.t b/testing/tests/001-basic.t new file mode 100755 index 0000000..4373855 --- /dev/null +++ b/testing/tests/001-basic.t @@ -0,0 +1,52 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use feature qw/say/; + +#use lib 'blib/lib'; + +use Test::Irssi; + +my $tester = Test::Irssi->new + (irssi_binary => "/opt/stow/repo/irssi-debug/bin/irssi", + irssi_homedir => $ENV{HOME} . "/projects/tmp/test/irssi-debug"); + +say "Created test instance"; +$tester->run_headless(1); + +my $test = $tester->new_test('test1'); +$test->description("simple echo tests"); + +$test->add_input_sequence("/echo Hello cats\n"); +$test->add_delay(1); +$test->add_input_sequence("/echo Hello Again\n"); +$test->add_input_sequence("this is a lang test"); +$test->add_pattern_match(qw/long/, 'prompt', 'prompt contains hello'); +$test->add_pattern_match(qw/longfdajkfd/, 'prompt', 'prompt contains hello'); + + +my $test2 = $tester->new_test('test2'); +$test2->description("cursor movement and deletion"); + +$test2->add_delay(2); +$test2->add_input_sequence("\x01"); +$test2->add_delay(0.1); +$test2->add_input_sequence("\x0b"); +$test2->add_delay(0.1); +$test2->add_input_sequence("/clear\n"); +$test2->add_delay(0.1); +$test2->add_input_sequence("/echo moo\n"); + +my $quit = $tester->new_test('quit'); +$quit->description('quitting'); +$quit->add_input_sequence("/quit\n"); + +# for (1..10) { +# $test->add_input_sequence("\xff"); +# $test->add_delay(0.1); + +# } + +$tester->run; -- cgit v1.2.3