Thread: [poe-commits] SF.net SVN: poe: [2210] trunk/poe-test-loops
Brought to you by:
rcaputo
From: <rc...@us...> - 2007-08-11 09:18:45
|
Revision: 2210 http://poe.svn.sourceforge.net/poe/?rev=2210&view=rev Author: rcaputo Date: 2007-08-11 02:18:48 -0700 (Sat, 11 Aug 2007) Log Message: ----------- More additions. Added Paths: ----------- trunk/poe-test-loops/MANIFEST trunk/poe-test-loops/Makefile.PL trunk/poe-test-loops/bin/poe-gen-tests trunk/poe-test-loops/lib/POE/Test/DondeEstan.pm trunk/poe-test-loops/t/01_no_tests.t Added: trunk/poe-test-loops/MANIFEST =================================================================== --- trunk/poe-test-loops/MANIFEST (rev 0) +++ trunk/poe-test-loops/MANIFEST 2007-08-11 09:18:48 UTC (rev 2210) @@ -0,0 +1,31 @@ +# $Id$ +CHANGES +MANIFEST +Makefile.PL +README +bin/poe-gen-tests +lib/POE/Test/DondeEstan.pm +lib/POE/Test/Loops/all_errors.pm +lib/POE/Test/Loops/comp_tcp.pm +lib/POE/Test/Loops/comp_tcp_concurrent.pm +lib/POE/Test/Loops/k_alarms.pm +lib/POE/Test/Loops/k_aliases.pm +lib/POE/Test/Loops/k_detach.pm +lib/POE/Test/Loops/k_selects.pm +lib/POE/Test/Loops/k_sig_child.pm +lib/POE/Test/Loops/k_signals.pm +lib/POE/Test/Loops/k_signals_rerun.pm +lib/POE/Test/Loops/sbk_signal_init.pm +lib/POE/Test/Loops/ses_nfa.pm +lib/POE/Test/Loops/ses_session.pm +lib/POE/Test/Loops/wheel_accept.pm +lib/POE/Test/Loops/wheel_curses.pm +lib/POE/Test/Loops/wheel_readline.pm +lib/POE/Test/Loops/wheel_readwrite.pm +lib/POE/Test/Loops/wheel_run.pm +lib/POE/Test/Loops/wheel_sf_ipv6.pm +lib/POE/Test/Loops/wheel_sf_tcp.pm +lib/POE/Test/Loops/wheel_sf_udp.pm +lib/POE/Test/Loops/wheel_sf_unix.pm +lib/POE/Test/Loops/wheel_tail.pm +t/01_no_tests.t Added: trunk/poe-test-loops/Makefile.PL =================================================================== --- trunk/poe-test-loops/Makefile.PL (rev 0) +++ trunk/poe-test-loops/Makefile.PL 2007-08-11 09:18:48 UTC (rev 2210) @@ -0,0 +1,26 @@ +# $Id$ + +use ExtUtils::MakeMaker; + +# Touch auto-generated files so we don't see warnings. +open(CHANGES, ">>CHANGES") and close CHANGES; +open(README, ">>README") and close README; + +WriteMakefile( + NAME => 'POE::Test::Loops', + AUTHOR => 'Rocco Caputo <rc...@cp...>', + ABSTRACT => 'POE::Loop test suite', + LICENSE => 'perl', + VERSION => 1.0, + PREREQ_PM => { + 'Test::More' => 0, + }, + dist => { + COMPRESS => 'gzip -9f', + SUFFIX => 'gz', + PREOP => ( + 'svn-log.perl | tee ./$(DISTNAME)-$(VERSION)/CHANGES > ./CHANGES;' . + 'perldoc bin/poe-gen-tests > README' + ), + }, +); Copied: trunk/poe-test-loops/bin/poe-gen-tests (from rev 2207, trunk/poe/mylib/gen-tests.perl) =================================================================== --- trunk/poe-test-loops/bin/poe-gen-tests (rev 0) +++ trunk/poe-test-loops/bin/poe-gen-tests 2007-08-11 09:18:48 UTC (rev 2210) @@ -0,0 +1,322 @@ +#!/usr/bin/perl -w + +use strict; +use File::Spec; +use File::Path; +use File::Find; +use Getopt::Long; + +my $dir_base; +my $flag_help; +my @loop_modules; +my $flag_verbose; + +my $result = GetOptions( + 'dirbase=s' => \$dir_base, + 'loop=s' => \@loop_modules, + 'verbose' => \$flag_verbose, + help => \$flag_help, +); + +if ( + !$result or !$dir_base or $flag_help or !@loop_modules +) { + die( + "$0 usage:\n", + " --dirbase DIR (required) base directory for tests\n", + " --loop MODULE (required) loop modules to test\n", + " --verbose show some extra output\n", + " --help you're reading it\n", + ); +} + +### Find the test libraries. + +use lib qw(./lib ../lib); +use POE::Test::DondeEstan; +my $source_base = POE::Test::DondeEstan->marco(); + +### Generate loop tests. + +foreach my $loop (@loop_modules) { + my $loop_dir = $loop; + $loop_dir =~ s/::/_/g; + + my $fqmn = find_event_loop_file($loop); + unless ($fqmn) { + $flag_verbose and print "Couldn't find a loop for $loop ...\n"; + next; + } + + $flag_verbose and print "Found $fqmn\n"; + + my $loop_cfg = get_loop_cfg($fqmn); + unless (defined $loop_cfg) { + $flag_verbose and print "Couldn't find configuration for $loop ...\n"; + next; + } + + # Replace configuration directives with code. + + if ( + $loop_cfg->{not_os} and exists $loop_cfg->{not_os}{$^O} + ) { + $loop_cfg->{not_os} = ( + "\n" . + "BEGIN {\n" . + " \$| = 1;\n" . + " print qq(1..0 # Skip This test cannot be run on $^O\\n);\n" . + " CORE::exit(0);\n" . + "}\n" + ); + } + else { + $loop_cfg->{not_os} = ""; + } + + if ($loop_cfg->{display}) { + if ($^O ne "MSWin32") { + $loop_cfg->{display} = ( + "\n" . + "BEGIN {\n" . + " unless (\$ENV{DISPLAY}) {\n" . + " \$| = 1;\n" . + " print qq(1..0 # " . + "Skip $loop needs a DISPLAY (set one today, okay?)\\n);\n" . + " CORE::exit(0);\n" . + " }\n" . + "}\n" + ); + } + else { + $loop_cfg->{display} = ""; + } + } + else { + $loop_cfg->{display} = ""; + } + + if ($loop_cfg->{module}) { + $loop_cfg->{module} = ( + "\n" . + "BEGIN {\n" . + " eval 'use $loop_cfg->{module}';\n" . + " if (\$@) {\n" . + " \$| = 1;\n" . + " print qq(1..0 # Skip Could not load $loop_cfg->{module}\\n);\n" . + " CORE::exit(0);\n" . + " }\n" . + "}\n" + ); + } + else { + $loop_cfg->{module} = ""; + } + + my $source = ( + "#!/usr/bin/perl -w\n" . + "# \$Id\$\n" . + "\n" . + "use strict;\n" . + "--not_os--" . + "use lib qw(--base_lib--);\n" . + "use Test::More;\n" . + "use POSIX qw(_exit);\n" . + "--display--" . + "--module--" . + "\n" . + "require '--base_file--';\n" . + "\n" . + "_exit 0 if \$^O eq 'MSWin32';\n" . + "CORE::exit 0;\n" + ); + + # Full directory where source files are found. + + my $dir_src = File::Spec->catfile($source_base, "Loops"); + my $dir_dst = File::Spec->catfile($dir_base, $loop_dir); + + # Gather the list of source files. + # Each will be used to generate a real test file. + + opendir BASE, $dir_src or die $!; + my @base_files = grep /\.pm$/, readdir(BASE); + closedir BASE; + + # Initialize the destination directory. Clear or create as needed. + + $dir_dst =~ tr[/][/]s; + $dir_dst =~ s{/+$}{}; + + rmtree($dir_dst); + mkpath($dir_dst, 0, 0755); + + # For each source file, generate a corresponding one in the + # configured destination directory. Expand various bits to + # customize the test. + + foreach my $base_file (@base_files) { + my $full_file = File::Spec->catfile($dir_dst, $base_file); + $full_file =~ s/\.pm$/.t/; + + # These hardcoded expansions are for the base file to be required, + # and the base library directory where it'll be found. + + my $expanded_src = $source; + $expanded_src =~ s/--base_file--/$base_file/g; + $expanded_src =~ s/--base_lib--/$dir_src/g; + + # The others are plugged in from the directory configuration. + + while (my ($key, $val) = each %$loop_cfg) { + $expanded_src =~ s/--\Q$key\E--/$val/g; + } + + # Write with lots of error checking. + + open EXPANDED, ">$full_file" or die $!; + print EXPANDED $expanded_src; + close EXPANDED or die $!; + } +} + +exit 0; + +sub find_event_loop_file { + my $loop_name = shift; + $loop_name =~ s/::/_/g; + + my $loop_module = File::Spec->catfile("POE", "Loop", $loop_name) . ".pm"; + + foreach my $inc (@INC) { + my $fqmn = File::Spec->catfile($inc, $loop_module); + next unless -f $fqmn; + return $fqmn; + } + + return; +} + +sub get_loop_cfg { + my $fqmn = shift; + + my ($in_test_block, @test_source); + + open SOURCE, "<$fqmn" or die $!; + while (<SOURCE>) { + if ($in_test_block) { + $in_test_block = 0, next if /^=cut\s*$/; + push @test_source, $_; + next; + } + + next unless /^=for\s+poe_tests\s*/; + $in_test_block = 1; + } + + eval join "", @test_source; +} + +__END__ + +=head1 NAME + +poe-gen-tests - Generate POE tests from templates and configuration. + +=head1 SYNOPSIS + + poe-gen-tests --dirbase t/loops --loop Select --loop Tk + +=head1 DESCRIPTION + +This program and the POE::Test::Loop::* modules comprise POE's tests +for POE::Loop subclasses. These tests are designed to run identically +regardless of the current event loop. POE uses them to test the event +loops it bundles: + + POE::Loop::Gtk + POE::Loop::IO_Poll + POE::Loop::Tk + POE::Loop::Event + POE::Loop::Select + +Developers of other POE::Loop modules can use this package to generate +over 420 comprehensive tests for their work. + +=head1 USAGE + +The poe-gen-tests utility creates test files for one or more event +loops beneath the directory specified in --dirbase. For example: + + poe-gen-tests --dirbase t/loops --loop Select + +generates the following test files: + + t/loops/Select/all_errors.t + t/loops/Select/comp_tcp.t + t/loops/Select/comp_tcp_concurrent.t + t/loops/Select/k_alarms.t + t/loops/Select/k_aliases.t + t/loops/Select/k_detach.t + t/loops/Select/k_selects.t + t/loops/Select/k_sig_child.t + t/loops/Select/k_signals.t + t/loops/Select/k_signals_rerun.t + t/loops/Select/sbk_signal_init.t + t/loops/Select/ses_nfa.t + t/loops/Select/ses_session.t + t/loops/Select/wheel_accept.t + t/loops/Select/wheel_curses.t + t/loops/Select/wheel_readline.t + t/loops/Select/wheel_readwrite.t + t/loops/Select/wheel_run.t + t/loops/Select/wheel_sf_ipv6.t + t/loops/Select/wheel_sf_tcp.t + t/loops/Select/wheel_sf_udp.t + t/loops/Select/wheel_sf_unix.t + t/loops/Select/wheel_tail.t + +=head1 INSTALL SCRIPT INTEGRATION + +Use system() to invoke the script from your Makefile.PL, Build.PL, or +whatever you're using. For example: + + system( + $^X, "poe-gen-tests", "--dirbase", "t/loops", "--loop", "Event::Lib" + ) and die $!; + +Naturally "Event::Lib" would be replaced by the event loop your module +targets. + +Test files should not be included in the MANIFEST. They are generated +during the install process and won't be included by "make dist". + +=head1 SKIPPING NETWORK TESTS + +Several tests require a network to be present. Those tests will be +skipped by default. They may be enabled by creating the file +"run_network_tests" in the distribution's main directory. + +Tests will look for the file in the current directory, which is the +distribution's main directory when running "make test" or "prove". + +=head1 TODO + +* Complete usage documentation. +** How to set the dependency so the tests are pre-installed. + +* Set $VERSION in this script. +** Use that version for the distro. + +=head1 AUTHOR & COPYRIGHT + +Rocco Caputo <rc...@cp...>. +Benjamin Smith <bm...@cp...>. +Countless other people. + +These tests are Copyright 1998-2007 by Rocco Caputo, Benjamin Smith, +and countless contributors. All rights are reserved. These tests are +free software; you may redistribute them and/or modify them under the +same terms as Perl itself. + +=cut Added: trunk/poe-test-loops/lib/POE/Test/DondeEstan.pm =================================================================== --- trunk/poe-test-loops/lib/POE/Test/DondeEstan.pm (rev 0) +++ trunk/poe-test-loops/lib/POE/Test/DondeEstan.pm 2007-08-11 09:18:48 UTC (rev 2210) @@ -0,0 +1,19 @@ +# $Id$ + +package POE::Test::DondeEstan; + +use warnings; +use strict; + +use File::Spec; + +# It's a pun on Marco Polo, the swimming game, and Macro Antonio +# Manzo, this cool dude I know. Hi, Marco! + +sub marco { + my @aqui = File::Spec->splitdir(__FILE__); + pop @aqui; + return File::Spec->catdir(@aqui); +} + +1; Added: trunk/poe-test-loops/t/01_no_tests.t =================================================================== --- trunk/poe-test-loops/t/01_no_tests.t (rev 0) +++ trunk/poe-test-loops/t/01_no_tests.t 2007-08-11 09:18:48 UTC (rev 2210) @@ -0,0 +1,2 @@ +# $Id$ +print "1..0 # Skip This distribution consists of tests.\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2007-08-11 18:08:52
|
Revision: 2211 http://poe.svn.sourceforge.net/poe/?rev=2211&view=rev Author: rcaputo Date: 2007-08-11 11:08:55 -0700 (Sat, 11 Aug 2007) Log Message: ----------- Document more magic, converting it to merely technology. Modified Paths: -------------- trunk/poe-test-loops/Makefile.PL trunk/poe-test-loops/bin/poe-gen-tests Modified: trunk/poe-test-loops/Makefile.PL =================================================================== --- trunk/poe-test-loops/Makefile.PL 2007-08-11 09:18:48 UTC (rev 2210) +++ trunk/poe-test-loops/Makefile.PL 2007-08-11 18:08:55 UTC (rev 2211) @@ -11,7 +11,7 @@ AUTHOR => 'Rocco Caputo <rc...@cp...>', ABSTRACT => 'POE::Loop test suite', LICENSE => 'perl', - VERSION => 1.0, + VERSION_FROM => 'bin/poe-gen-tests', PREREQ_PM => { 'Test::More' => 0, }, Modified: trunk/poe-test-loops/bin/poe-gen-tests =================================================================== --- trunk/poe-test-loops/bin/poe-gen-tests 2007-08-11 09:18:48 UTC (rev 2210) +++ trunk/poe-test-loops/bin/poe-gen-tests 2007-08-11 18:08:55 UTC (rev 2211) @@ -6,6 +6,10 @@ use File::Find; use Getopt::Long; +use vars qw($VERSION $REVISION); +$VERSION = '1.0000'; # NOTE - Should be #.#### (four decimal places) +$REVISION = do {my($r)=(q$Revision$=~/(\d+)/);sprintf"1.%04d",$r}; + my $dir_base; my $flag_help; my @loop_modules; @@ -221,21 +225,21 @@ =head1 NAME -poe-gen-tests - Generate POE tests from templates and configuration. +poe-gen-tests - generate standard POE tests for third-party modules =head1 SYNOPSIS - poe-gen-tests --dirbase t/loops --loop Select --loop Tk + poe-gen-tests --dirbase t/loops --loop Glib --loop Kqueue =head1 DESCRIPTION -This program and the POE::Test::Loop::* modules comprise POE's tests +This program and the POE::Test::Loop::* modules make up POE's tests for POE::Loop subclasses. These tests are designed to run identically -regardless of the current event loop. POE uses them to test the event -loops it bundles: +regardless of the current event loop. POE uses them to test the +event loops it bundles: POE::Loop::Gtk - POE::Loop::IO_Poll + POE::Loop::IO_Poll (--loop IO::Poll) POE::Loop::Tk POE::Loop::Event POE::Loop::Select @@ -246,7 +250,7 @@ =head1 USAGE The poe-gen-tests utility creates test files for one or more event -loops beneath the directory specified in --dirbase. For example: +loops beneath the directory specified in --dirbase. For example, poe-gen-tests --dirbase t/loops --loop Select @@ -276,6 +280,94 @@ t/loops/Select/wheel_sf_unix.t t/loops/Select/wheel_tail.t +Per POE conventions, the event loop is named POE::Loop::Something, +where "Something" is the name of the event loop module with :: +replaced by underscores. For example, an Event::Lib loop would be +named POE::Loop::Event_Lib. + +poe-gen-tests needs to know certain things about POE::Loop classes in +order to test them properly. It looks for this information in a "=for +poe_tests" block within the class source code. For example: + + =for poe_tests + + { + module => "Gtk2", + display => 1, + not_os => { MSWin32 => 1 }, + } + + =cut + +So far poe-gen-tests understands these configuration directives: + +=over 2 + +=item display + +An optional Boolean indicating whether the event loop requires a +DISPLAY to be set. + +=item module + +An optional scalar defining the module, if any, that must be available +for the test to run. It's optional because POE::Loop::Select uses the +built-in select() function and doesn't need to load a module. + +=item no_os + +A scalar hash reference, keyed on the $^O values of systems where the +test should never be run. + +=back + +=head2 Example poe_tests Directives + +From POE::Loop::Event: + + =for poe_tests + + { + module => "Event", + display => 0, + } + + =cut + +From POE::Loop::Gtk: + + =for poe_tests + + { + module => "Gtk", + display => 1, + } + + =cut + +From POE::Loop::IO_Poll + + =for poe_tests + + { + module => "IO::Poll", + display => 0, + not_os => { MSWin32 => 1 }, + } + + =cut + +From POE::Loop::Select + + =for poe_tests + + { + module => "", + display => 0, + } + + =cut + =head1 INSTALL SCRIPT INTEGRATION Use system() to invoke the script from your Makefile.PL, Build.PL, or @@ -291,6 +383,23 @@ Test files should not be included in the MANIFEST. They are generated during the install process and won't be included by "make dist". +=head1 CLEANING UP + +The tests are generated on the target machine, so they don't appear in +MANIFEST and will not be cleaned up as part of "make clean" or "make +distclean". If you'd like to ensure they are, you'll need to add +something like this to your WriteMakefile() invocation: + + clean => { + FILES => "t/loops/*/* t/loops/*", + } + +This assumes the "t/loops" directory contains only generated tests. +It's recommended that generated and hand-coded tests not coexist in +the same directory. + +Modify the recipe accordingly if you're not using ExtUtils::MakeMaker. + =head1 SKIPPING NETWORK TESTS Several tests require a network to be present. Those tests will be @@ -300,18 +409,61 @@ Tests will look for the file in the current directory, which is the distribution's main directory when running "make test" or "prove". -=head1 TODO +Here's the code POE's Makefile.PL uses to prompt the user whether +network tests should run: -* Complete usage documentation. -** How to set the dependency so the tests are pre-installed. + # Switch to default behavior if STDIN isn't a tty. -* Set $VERSION in this script. -** Use that version for the distro. + unless (-t STDIN) { + warn( + "\n", + "=============================================\n\n", + "STDIN is not a terminal. Assuming --default.\n\n", + "=============================================\n\n", + ); + push @ARGV, "--default"; + } + # Remind the user she can use --default. + + unless (grep /^--default$/, @ARGV) { + warn( + "\n", + "=============================================\n\n", + "Prompts may be bypassed by running:\n", + " $^X $0 --default\n\n", + "=============================================\n\n", + ); + } + + # Should we skip the network tests? + + my $prompt = ( + "Some of POE's tests require a functional network.\n" . + "You can skip these tests if you'd like.\n\n" . + "Would you like to skip the network tests?" + ); + + my $ret = "n"; + if (grep /^--default$/, @ARGV) { + print $prompt, " [$ret] $ret\n\n"; + } + else { + $ret = prompt($prompt, "n"); + } + + my $marker = 'run_network_tests'; + unlink $marker; + if ($ret =~ /^Y$/i) { + open(TOUCH,"+>$marker") and close TOUCH; + } + + print "\n"; + =head1 AUTHOR & COPYRIGHT Rocco Caputo <rc...@cp...>. -Benjamin Smith <bm...@cp...>. +Benjamin Smith <bs...@cp...>. Countless other people. These tests are Copyright 1998-2007 by Rocco Caputo, Benjamin Smith, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2008-03-24 05:11:30
|
Revision: 2299 http://poe.svn.sourceforge.net/poe/?rev=2299&view=rev Author: rcaputo Date: 2008-03-23 22:11:33 -0700 (Sun, 23 Mar 2008) Log Message: ----------- Update tests to match POE 0.9999_03. Add POE::Test::Loops and move the VERSION number there so that the package name can be installed and/or depended upon. Add keyword expansion to files that didn't have it set. Bump the version to 0.98. Modified Paths: -------------- trunk/poe-test-loops/MANIFEST trunk/poe-test-loops/Makefile.PL trunk/poe-test-loops/bin/poe-gen-tests trunk/poe-test-loops/lib/POE/Test/Loops/comp_tcp_concurrent.pm trunk/poe-test-loops/lib/POE/Test/Loops/k_signals_rerun.pm trunk/poe-test-loops/lib/POE/Test/Loops/wheel_curses.pm trunk/poe-test-loops/lib/POE/Test/Loops/wheel_readline.pm trunk/poe-test-loops/lib/POE/Test/Loops/wheel_run.pm trunk/poe-test-loops/lib/POE/Test/Loops/wheel_sf_ipv6.pm trunk/poe-test-loops/t/01_no_tests.t Added Paths: ----------- trunk/poe-test-loops/lib/POE/Test/Loops.pm Property Changed: ---------------- trunk/poe-test-loops/MANIFEST trunk/poe-test-loops/Makefile.PL trunk/poe-test-loops/lib/POE/Test/DondeEstan.pm trunk/poe-test-loops/t/01_no_tests.t Modified: trunk/poe-test-loops/MANIFEST =================================================================== --- trunk/poe-test-loops/MANIFEST 2008-03-23 01:43:22 UTC (rev 2298) +++ trunk/poe-test-loops/MANIFEST 2008-03-24 05:11:33 UTC (rev 2299) @@ -5,6 +5,7 @@ README bin/poe-gen-tests lib/POE/Test/DondeEstan.pm +lib/POE/Test/Loops.pm lib/POE/Test/Loops/all_errors.pm lib/POE/Test/Loops/comp_tcp.pm lib/POE/Test/Loops/comp_tcp_concurrent.pm Property changes on: trunk/poe-test-loops/MANIFEST ___________________________________________________________________ Name: svn:keywords + Id Revision Date Author URL Modified: trunk/poe-test-loops/Makefile.PL =================================================================== --- trunk/poe-test-loops/Makefile.PL 2008-03-23 01:43:22 UTC (rev 2298) +++ trunk/poe-test-loops/Makefile.PL 2008-03-24 05:11:33 UTC (rev 2299) @@ -11,7 +11,7 @@ AUTHOR => 'Rocco Caputo <rc...@cp...>', ABSTRACT => 'POE::Loop test suite', LICENSE => 'perl', - VERSION_FROM => 'bin/poe-gen-tests', + VERSION_FROM => 'lib/POE/Test/Loops.pm', PREREQ_PM => { 'Test::More' => 0, }, Property changes on: trunk/poe-test-loops/Makefile.PL ___________________________________________________________________ Name: svn:keywords + Id Revision Date Author URL Modified: trunk/poe-test-loops/bin/poe-gen-tests =================================================================== --- trunk/poe-test-loops/bin/poe-gen-tests 2008-03-23 01:43:22 UTC (rev 2298) +++ trunk/poe-test-loops/bin/poe-gen-tests 2008-03-24 05:11:33 UTC (rev 2299) @@ -5,11 +5,8 @@ use File::Path; use File::Find; use Getopt::Long; +use POE::Test::Loops; -use vars qw($VERSION $REVISION); -$VERSION = '0.97'; # NOTE - Should be #.## (two decimal places) -$REVISION = do {my($r)=(q$Revision$=~/(\d+)/);sprintf"0.%04d",$r}; - my $dir_base; my $flag_help; my @loop_modules; @@ -451,7 +448,7 @@ Benjamin Smith <bs...@cp...>. Countless other people. -These tests are Copyright 1998-2007 by Rocco Caputo, Benjamin Smith, +These tests are Copyright 1998-2008 by Rocco Caputo, Benjamin Smith, and countless contributors. All rights are reserved. These tests are free software; you may redistribute them and/or modify them under the same terms as Perl itself. Property changes on: trunk/poe-test-loops/lib/POE/Test/DondeEstan.pm ___________________________________________________________________ Name: svn:keywords + Id Revision Date Author URL Modified: trunk/poe-test-loops/lib/POE/Test/Loops/comp_tcp_concurrent.pm =================================================================== --- trunk/poe-test-loops/lib/POE/Test/Loops/comp_tcp_concurrent.pm 2008-03-23 01:43:22 UTC (rev 2298) +++ trunk/poe-test-loops/lib/POE/Test/Loops/comp_tcp_concurrent.pm 2008-03-24 05:11:33 UTC (rev 2299) @@ -17,8 +17,11 @@ } } -use Test::More tests => (42); +my $NUM_CLIENTS; +BEGIN { $NUM_CLIENTS = 9 } # rt.cpan.org 32034 +use Test::More tests => $NUM_CLIENTS * 2; + diag( "You might see a 'disconnect' error during this test." ); diag( "It may be ignored." ); @@ -193,7 +196,7 @@ } sub do_clients { - foreach my $N (1..21) { + foreach my $N (1..$NUM_CLIENTS) { DEBUG and warn "$$: SPAWN\n"; two_clients($N); } @@ -228,7 +231,7 @@ ServerInput => sub { my ($heap, $input) = @_[HEAP, ARG0]; DEBUG and warn("$$: acceptor client $N got input ($input)"); - if( $input =~ /#21$/ ) { + if( $input =~ /#$NUM_CLIENTS$/ ) { $_[HEAP]->{server}->put( 'quit' ); } @@ -273,7 +276,7 @@ ServerInput => sub { my ($heap, $input) = @_[HEAP, ARG0]; DEBUG and warn("$$: callback client $N got input ($input)"); - if( $input =~ /#21$/ ) { + if( $input =~ /#$NUM_CLIENTS$/ ) { $_[HEAP]->{server}->put( 'quit' ); } $_[KERNEL]->yield('shutdown'); Modified: trunk/poe-test-loops/lib/POE/Test/Loops/k_signals_rerun.pm =================================================================== --- trunk/poe-test-loops/lib/POE/Test/Loops/k_signals_rerun.pm 2008-03-23 01:43:22 UTC (rev 2298) +++ trunk/poe-test-loops/lib/POE/Test/Loops/k_signals_rerun.pm 2008-03-24 05:11:33 UTC (rev 2299) @@ -11,6 +11,7 @@ use Test::More; if ($^O eq "MSWin32") { + plan skip_all => "Perl can't handle these tests on $^O - it crashes"; eval 'use Win32::Console'; if ($@) { plan skip_all => "Win32::Console is required on $^O - try ActivePerl"; @@ -21,6 +22,7 @@ if (exists $INC{'Event.pm'}) { plan skip_all => "Perl crashes in this test with Event on $^O"; } + plan skip_all => "Perl on $^O is too fragile for this test - it crashes"; } plan tests => 9; @@ -37,6 +39,7 @@ inline_states => { stdout => sub { }, stdin => sub { }, + _parent => sub { }, _start => sub { my ( $kernel, $session, $heap ) = @_[KERNEL, SESSION, HEAP]; @@ -88,6 +91,7 @@ }, _stop => sub { }, _child => sub { }, + _parent => sub { }, }, ); Modified: trunk/poe-test-loops/lib/POE/Test/Loops/wheel_curses.pm =================================================================== --- trunk/poe-test-loops/lib/POE/Test/Loops/wheel_curses.pm 2008-03-23 01:43:22 UTC (rev 2298) +++ trunk/poe-test-loops/lib/POE/Test/Loops/wheel_curses.pm 2008-03-24 05:11:33 UTC (rev 2299) @@ -113,7 +113,7 @@ $heap->{child_input} .= $input; if ($heap->{child_input} =~ /!/) { - delete $heap->{curses}; } + delete $heap->{curses}; delete $heap->{readwrite}; ok( $heap->{child_input} eq "this is a test!", "got keystrokes" ); } Modified: trunk/poe-test-loops/lib/POE/Test/Loops/wheel_readline.pm =================================================================== --- trunk/poe-test-loops/lib/POE/Test/Loops/wheel_readline.pm 2008-03-23 01:43:22 UTC (rev 2298) +++ trunk/poe-test-loops/lib/POE/Test/Loops/wheel_readline.pm 2008-03-24 05:11:33 UTC (rev 2299) @@ -132,14 +132,6 @@ if ($^O eq "MSWin32") { $error = "$^O cannot multiplex terminals"; } - if ($^O eq "darwin") { - foreach my $bad (qw(Event.pm IO/Poll.pm)) { - if (exists $INC{$bad}) { - $error = "$bad can't work with ttys under $^O"; - last; - } - } - } if (!-t STDIN) { $error = "not running in a terminal"; } Modified: trunk/poe-test-loops/lib/POE/Test/Loops/wheel_run.pm =================================================================== --- trunk/poe-test-loops/lib/POE/Test/Loops/wheel_run.pm 2008-03-23 01:43:22 UTC (rev 2298) +++ trunk/poe-test-loops/lib/POE/Test/Loops/wheel_run.pm 2008-03-24 05:11:33 UTC (rev 2299) @@ -29,6 +29,9 @@ elsif (exists $INC{"Event.pm"}) { $error = "$^O\'s fork() emulation breaks Event"; } + else { + $error = "Signal handling on $^O is too fragile - Perl crashes"; + } $RUNNING_WIN32 = 1; } @@ -84,7 +87,7 @@ sleep 10; } END - $text =~ s/\n/ /g; + $text =~ s/\s+/ /g; my $os_quote = ($^O eq 'MSWin32') ? q(") : q('); $chld_program_string = [ $^X, "-we", "$text CORE::exit 0" ]; @@ -189,7 +192,7 @@ } sub do_error { - DEBUG and warn "$_[HEAP]->{label}: $_[ARG0] error $_[ARG1]: $_[ARG2]"; + DEBUG and warn "$_[HEAP]->{label}: $_[ARG0] error $_[ARG1]: $_[ARG2]\n"; } # {{{ definition of the main test session @@ -202,17 +205,17 @@ my $action = $heap->{expected}->[0][0]; unless (ref $action) { - DEBUG and warn "$heap->{label}: performing put state: $action"; + DEBUG and warn "$heap->{label}: performing put state: $action\n"; eval { $heap->{wheel}->put( $action ) }; } elsif ($action->[0] =~ m/^(?:pause|resume)_std(?:out|err)$/) { my $method = $action->[0]; - DEBUG and warn "$heap->{label}: performing method state: $method"; + DEBUG and warn "$heap->{label}: performing method state: $method\n"; $heap->{wheel}->$method(); } elsif ($action->[0] eq "kill") { - DEBUG and warn "$heap->{label}: performing kill"; + DEBUG and warn "$heap->{label}: performing kill\n"; $heap->{wheel}->kill(); } elsif ($action->[0] eq "shutdown_stdin") { - DEBUG and warn "$heap->{label}: shutdown_stdin"; + DEBUG and warn "$heap->{label}: shutdown_stdin\n"; $heap->{wheel}->shutdown_stdin(); } else { warn "weird action @$action, this is a bug in the test script"; @@ -281,7 +284,7 @@ # timeout delay timeout_incref(); - DEBUG and warn "$heap->{label}: _start"; + DEBUG and warn "$heap->{label}: _start\n"; } my $x__ = 0; @@ -294,14 +297,14 @@ is( $heap->{flushes}, $heap->{flushes_expected}, "$heap->{label} flush count ($$)" ) unless $heap->{ignore_flushes}; - DEBUG and warn "$heap->{label}: _stop ($$)"; + DEBUG and warn "$heap->{label}: _stop ($$)\n"; } sub main_stdin { my $heap = $_[HEAP]; $heap->{flushes}++; timeout_poke(); - DEBUG and warn "$heap->{label}: stdin flush"; + DEBUG and warn "$heap->{label}: stdin flush\n"; } sub main_output { @@ -318,7 +321,7 @@ is($input, "$prefix: ".$heap->{expected}->[0][1][1], "$heap->{label} $state response"); - DEBUG and warn "$heap->{label}: $state $input"; + DEBUG and warn "$heap->{label}: $state $input\n"; timeout_poke(); @@ -339,7 +342,7 @@ delete $_[HEAP]->{wheel}; timeout_decref(); $kernel->sig("CHLD" => undef); - DEBUG and warn "$heap->{label}: close"; + DEBUG and warn "$heap->{label}: close\n"; } sub main_sigchld { @@ -347,7 +350,9 @@ my ($signame, $child_pid) = @_[ARG0, ARG1]; my $our_child = $heap->{wheel} ? $heap->{wheel}->PID : -1; - DEBUG and warn "$heap->{label}: sigchld $signame for $child_pid ($our_child)"; + DEBUG and warn( + "$heap->{label}: sigchld $signame for $child_pid ($our_child)\n" + ); return unless $heap->{wheel} and $our_child == $child_pid; Modified: trunk/poe-test-loops/lib/POE/Test/Loops/wheel_sf_ipv6.pm =================================================================== --- trunk/poe-test-loops/lib/POE/Test/Loops/wheel_sf_ipv6.pm 2008-03-23 01:43:22 UTC (rev 2298) +++ trunk/poe-test-loops/lib/POE/Test/Loops/wheel_sf_ipv6.pm 2008-03-24 05:11:33 UTC (rev 2299) @@ -11,7 +11,7 @@ BEGIN { my $error; - eval 'use Socket6'; + eval 'use Socket6 ()'; if ( length($@) or not exists($INC{"Socket6.pm"}) ) { $error = "Socket6 is needed for IPv6 tests"; } @@ -60,7 +60,7 @@ POE::Component::Server::TCP->new( Port => $tcp_server_port, Address => '::1', - Domain => AF_INET6, + Domain => Socket6::AF_INET6, Alias => 'server', ClientConnected => \&server_got_connect, ClientInput => \&server_got_input, @@ -109,7 +109,7 @@ POE::Component::Client::TCP->new( RemoteAddress => '::1', RemotePort => $tcp_server_port, - Domain => AF_INET6, + Domain => Socket6::AF_INET6, BindAddress => '::1', Connected => \&client_got_connect, ServerInput => \&client_got_input, Added: trunk/poe-test-loops/lib/POE/Test/Loops.pm =================================================================== --- trunk/poe-test-loops/lib/POE/Test/Loops.pm (rev 0) +++ trunk/poe-test-loops/lib/POE/Test/Loops.pm 2008-03-24 05:11:33 UTC (rev 2299) @@ -0,0 +1,37 @@ +# $Id$ + +package POE::Test::Loops; + +use strict; +use vars qw($VERSION); + +use vars qw($VERSION $REVISION); +$VERSION = '0.98'; # NOTE - Should be #.## (two decimal places) +$REVISION = do {my($r)=(q$Revision$=~/(\d+)/);sprintf"0.%04d",$r}; + +1; + +__END__ + +=head1 NAME + +POE::Test::Loops - Reusable tests for POE::Loop authors + +=head1 SYNOPSIS + +See L<poe-gen-tests>. + +=head1 DESCRIPTION + +See L<poe-gen-tests>, which is a utility to generate the actual tests +for your POE::Loop subclass. + +=head1 SEE ALSO + +L<POE::Loop> and L<poe-gen-tests>. + +=head1 AUTHOR & COPYRIGHT + +See L<poe-gen-tests>. + +=cut Property changes on: trunk/poe-test-loops/lib/POE/Test/Loops.pm ___________________________________________________________________ Name: svn:keywords + Id Revision Date Author URL Modified: trunk/poe-test-loops/t/01_no_tests.t =================================================================== --- trunk/poe-test-loops/t/01_no_tests.t 2008-03-23 01:43:22 UTC (rev 2298) +++ trunk/poe-test-loops/t/01_no_tests.t 2008-03-24 05:11:33 UTC (rev 2299) @@ -1,2 +1,6 @@ # $Id$ -print "1..0 # Skip This distribution consists of tests.\n"; + +use warnings; +use strict; +use Test::More tests => 1; +use_ok("POE::Test::Loops"); Property changes on: trunk/poe-test-loops/t/01_no_tests.t ___________________________________________________________________ Name: svn:keywords + Id Revision Date Author URL This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lo...@us...> - 2008-06-27 18:30:17
|
Revision: 2366 http://poe.svn.sourceforge.net/poe/?rev=2366&view=rev Author: lotr Date: 2008-06-27 11:30:20 -0700 (Fri, 27 Jun 2008) Log Message: ----------- rearrange code put all the logic from poe-gen-tests in POE::Test::Loops, so it can be used from other modules without needing to execute poe-gen-tests. Modified Paths: -------------- trunk/poe-test-loops/bin/poe-gen-tests trunk/poe-test-loops/lib/POE/Test/Loops.pm Modified: trunk/poe-test-loops/bin/poe-gen-tests =================================================================== --- trunk/poe-test-loops/bin/poe-gen-tests 2008-06-27 05:18:51 UTC (rev 2365) +++ trunk/poe-test-loops/bin/poe-gen-tests 2008-06-27 18:30:20 UTC (rev 2366) @@ -1,9 +1,6 @@ #!/usr/bin/perl -w use strict; -use File::Spec; -use File::Path; -use File::Find; use Getopt::Long; use POE::Test::Loops; @@ -31,152 +28,9 @@ ); } -### Find the test libraries. - -use lib qw(./lib ../lib); -use POE::Test::DondeEstan; -my $source_base = POE::Test::DondeEstan->marco(); - -### Generate loop tests. - -foreach my $loop (@loop_modules) { - my $loop_dir = lc($loop); - $loop_dir =~ s/::/_/g; - - my $fqmn = find_event_loop_file($loop); - unless ($fqmn) { - $flag_verbose and print "Couldn't find a loop for $loop ...\n"; - next; - } - - $flag_verbose and print "Found $fqmn\n"; - - my $loop_cfg = get_loop_cfg($fqmn); - unless (defined $loop_cfg and length $loop_cfg) { - $loop_cfg = ( - "sub skip_tests { return }" - ); - } - - my $source = ( - "#!/usr/bin/perl -w\n" . - "# \$Id\$\n" . - "\n" . - "use strict;\n" . - "\n" . - "use lib qw(--base_lib--);\n" . - "use Test::More;\n" . - "use POSIX qw(_exit);\n" . - "\n" . - "--loop_cfg--\n" . - "\n" . - "BEGIN {\n" . - " if (my \$why = skip_tests('--test_name--')) {\n" . - " plan skip_all => \$why\n" . - " }\n" . - "}\n" . - "\n" . - "# Run the tests themselves.\n" . - "require '--base_file--';\n" . - "\n" . - "_exit 0 if \$^O eq 'MSWin32';\n" . - "CORE::exit 0;\n" - ); - - # Full directory where source files are found. - - my $dir_src = File::Spec->catfile($source_base, "Loops"); - my $dir_dst = File::Spec->catfile($dir_base, $loop_dir); - - # Gather the list of source files. - # Each will be used to generate a real test file. - - opendir BASE, $dir_src or die $!; - my @base_files = grep /\.pm$/, readdir(BASE); - closedir BASE; - - # Initialize the destination directory. Clear or create as needed. - - $dir_dst =~ tr[/][/]s; - $dir_dst =~ s{/+$}{}; - - rmtree($dir_dst); - mkpath($dir_dst, 0, 0755); - - # For each source file, generate a corresponding one in the - # configured destination directory. Expand various bits to - # customize the test. - - foreach my $base_file (@base_files) { - my $test_name = $base_file; - $test_name =~ s/\.pm$//; - - my $full_file = File::Spec->catfile($dir_dst, $base_file); - $full_file =~ s/\.pm$/.t/; - - # These hardcoded expansions are for the base file to be required, - # and the base library directory where it'll be found. - - my $expanded_src = $source; - $expanded_src =~ s/--base_file--/$base_file/g; - $expanded_src =~ s/--base_lib--/$dir_src/g; - $expanded_src =~ s/--loop_cfg--/$loop_cfg/g; - $expanded_src =~ s/--test_name--/$test_name/g; - - # Write with lots of error checking. - - open EXPANDED, ">$full_file" or die $!; - print EXPANDED $expanded_src; - close EXPANDED or die $!; - } -} - +POE::Test::Loops::generate($dir_base, \@loop_modules, $flag_verbose); exit 0; -sub find_event_loop_file { - my $loop_name = shift; - - my $loop_module; - if ($loop_name =~ /^POE::/) { - $loop_module = File::Spec->catfile(split(/::/, $loop_name)) . ".pm"; - } - else { - $loop_name =~ s/::/_/g; - $loop_module = File::Spec->catfile("POE", "Loop", $loop_name) . ".pm"; - } - - foreach my $inc (@INC) { - my $fqmn = File::Spec->catfile($inc, $loop_module); - next unless -f $fqmn; - return $fqmn; - } - - return; -} - -sub get_loop_cfg { - my $fqmn = shift; - - my ($in_test_block, @test_source); - - open SOURCE, "<$fqmn" or die $!; - while (<SOURCE>) { - if ($in_test_block) { - $in_test_block = 0, next if /^=cut\s*$/; - push @test_source, $_; - next; - } - - next unless /^=for\s+poe_tests\s*/; - $in_test_block = 1; - } - - shift @test_source while @test_source and $test_source[0] =~ /^\s*$/; - pop @test_source while @test_source and $test_source[-1] =~ /^\s*$/; - - return join "", @test_source; -} - __END__ =head1 NAME Modified: trunk/poe-test-loops/lib/POE/Test/Loops.pm =================================================================== --- trunk/poe-test-loops/lib/POE/Test/Loops.pm 2008-06-27 05:18:51 UTC (rev 2365) +++ trunk/poe-test-loops/lib/POE/Test/Loops.pm 2008-06-27 18:30:20 UTC (rev 2366) @@ -9,6 +9,159 @@ $VERSION = '0.99'; # NOTE - Should be #.## (two decimal places) $REVISION = do {my($r)=(q$Revision$=~/(\d+)/);sprintf"0.%04d",$r}; +use File::Spec; +use File::Path; +use File::Find; + +### Find the test libraries. + +use lib qw(./lib ../lib); +use POE::Test::DondeEstan; +my $source_base = POE::Test::DondeEstan->marco(); + +### Generate loop tests. + +sub generate { + my ($dir_base, $loops, $flag_verbose) = @_; + + foreach my $loop (@$loops) { + my $loop_dir = lc($loop); + $loop_dir =~ s/::/_/g; + + my $fqmn = find_event_loop_file($loop); + unless ($fqmn) { + $flag_verbose and print "Couldn't find a loop for $loop ...\n"; + next; + } + + $flag_verbose and print "Found $fqmn\n"; + + my $loop_cfg = get_loop_cfg($fqmn); + unless (defined $loop_cfg and length $loop_cfg) { + $loop_cfg = ( + "sub skip_tests { return }" + ); + } + + my $source = ( + "#!/usr/bin/perl -w\n" . + "# \$Id\$\n" . + "\n" . + "use strict;\n" . + "\n" . + "use lib qw(--base_lib--);\n" . + "use Test::More;\n" . + "use POSIX qw(_exit);\n" . + "\n" . + "--loop_cfg--\n" . + "\n" . + "BEGIN {\n" . + " if (my \$why = skip_tests('--test_name--')) {\n" . + " plan skip_all => \$why\n" . + " }\n" . + "}\n" . + "\n" . + "# Run the tests themselves.\n" . + "require '--base_file--';\n" . + "\n" . + "_exit 0 if \$^O eq 'MSWin32';\n" . + "CORE::exit 0;\n" + ); + +# Full directory where source files are found. + + my $dir_src = File::Spec->catfile($source_base, "Loops"); + my $dir_dst = File::Spec->catfile($dir_base, $loop_dir); + +# Gather the list of source files. +# Each will be used to generate a real test file. + + opendir BASE, $dir_src or die $!; + my @base_files = grep /\.pm$/, readdir(BASE); + closedir BASE; + +# Initialize the destination directory. Clear or create as needed. + + $dir_dst =~ tr[/][/]s; + $dir_dst =~ s{/+$}{}; + + rmtree($dir_dst); + mkpath($dir_dst, 0, 0755); + +# For each source file, generate a corresponding one in the +# configured destination directory. Expand various bits to +# customize the test. + + foreach my $base_file (@base_files) { + my $test_name = $base_file; + $test_name =~ s/\.pm$//; + + my $full_file = File::Spec->catfile($dir_dst, $base_file); + $full_file =~ s/\.pm$/.t/; + +# These hardcoded expansions are for the base file to be required, +# and the base library directory where it'll be found. + + my $expanded_src = $source; + $expanded_src =~ s/--base_file--/$base_file/g; + $expanded_src =~ s/--base_lib--/$dir_src/g; + $expanded_src =~ s/--loop_cfg--/$loop_cfg/g; + $expanded_src =~ s/--test_name--/$test_name/g; + +# Write with lots of error checking. + + open EXPANDED, ">$full_file" or die $!; + print EXPANDED $expanded_src; + close EXPANDED or die $!; + } + } +} + +sub find_event_loop_file { + my $loop_name = shift; + + my $loop_module; + if ($loop_name =~ /^POE::/) { + $loop_module = File::Spec->catfile(split(/::/, $loop_name)) . ".pm"; + } + else { + $loop_name =~ s/::/_/g; + $loop_module = File::Spec->catfile("POE", "Loop", $loop_name) . ".pm"; + } + + foreach my $inc (@INC) { + my $fqmn = File::Spec->catfile($inc, $loop_module); + next unless -f $fqmn; + return $fqmn; + } + + return; +} + +sub get_loop_cfg { + my $fqmn = shift; + + my ($in_test_block, @test_source); + + open SOURCE, "<$fqmn" or die $!; + while (<SOURCE>) { + if ($in_test_block) { + $in_test_block = 0, next if /^=cut\s*$/; + push @test_source, $_; + next; + } + + next unless /^=for\s+poe_tests\s*/; + $in_test_block = 1; + } + + shift @test_source while @test_source and $test_source[0] =~ /^\s*$/; + pop @test_source while @test_source and $test_source[-1] =~ /^\s*$/; + + return join "", @test_source; +} + + 1; __END__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2008-06-28 20:18:42
|
Revision: 2368 http://poe.svn.sourceforge.net/poe/?rev=2368&view=rev Author: rcaputo Date: 2008-06-28 13:18:48 -0700 (Sat, 28 Jun 2008) Log Message: ----------- Doc cleanups. Modified Paths: -------------- trunk/poe-test-loops/bin/poe-gen-tests trunk/poe-test-loops/lib/POE/Test/Loops.pm Modified: trunk/poe-test-loops/bin/poe-gen-tests =================================================================== --- trunk/poe-test-loops/bin/poe-gen-tests 2008-06-28 09:43:21 UTC (rev 2367) +++ trunk/poe-test-loops/bin/poe-gen-tests 2008-06-28 20:18:48 UTC (rev 2368) @@ -4,16 +4,12 @@ use Getopt::Long; use POE::Test::Loops; -my $dir_base; -my $flag_help; -my @loop_modules; -my $flag_verbose; - +my ($dir_base, $flag_help, @loop_modules, $flag_verbose); my $result = GetOptions( 'dirbase=s' => \$dir_base, 'loop=s' => \@loop_modules, 'verbose' => \$flag_verbose, - help => \$flag_help, + 'help' => \$flag_help, ); if ( @@ -305,6 +301,10 @@ print "\n"; +=head1 SEE ALSO + +L<POE::Test::Loops> and L<POE::Loop>. + =head1 AUTHOR & COPYRIGHT Rocco Caputo <rc...@cp...>. Modified: trunk/poe-test-loops/lib/POE/Test/Loops.pm =================================================================== --- trunk/poe-test-loops/lib/POE/Test/Loops.pm 2008-06-28 09:43:21 UTC (rev 2367) +++ trunk/poe-test-loops/lib/POE/Test/Loops.pm 2008-06-28 20:18:48 UTC (rev 2368) @@ -39,48 +39,48 @@ my $loop_cfg = _get_loop_cfg($fqmn); unless (defined $loop_cfg and length $loop_cfg) { $loop_cfg = ( - "sub skip_tests { return }" - ); + "sub skip_tests { return }" + ); } my $source = ( - "#!/usr/bin/perl -w\n" . - "# \$Id\$\n" . - "\n" . - "use strict;\n" . - "\n" . - "use lib qw(--base_lib--);\n" . - "use Test::More;\n" . - "use POSIX qw(_exit);\n" . - "\n" . - "--loop_cfg--\n" . - "\n" . - "BEGIN {\n" . - " if (my \$why = skip_tests('--test_name--')) {\n" . - " plan skip_all => \$why\n" . - " }\n" . - "}\n" . - "\n" . - "# Run the tests themselves.\n" . - "require '--base_file--';\n" . - "\n" . - "_exit 0 if \$^O eq 'MSWin32';\n" . - "CORE::exit 0;\n" - ); + "#!/usr/bin/perl -w\n" . + "# \$Id\$\n" . + "\n" . + "use strict;\n" . + "\n" . + "use lib qw(--base_lib--);\n" . + "use Test::More;\n" . + "use POSIX qw(_exit);\n" . + "\n" . + "--loop_cfg--\n" . + "\n" . + "BEGIN {\n" . + " if (my \$why = skip_tests('--test_name--')) {\n" . + " plan skip_all => \$why\n" . + " }\n" . + "}\n" . + "\n" . + "# Run the tests themselves.\n" . + "require '--base_file--';\n" . + "\n" . + "_exit 0 if \$^O eq 'MSWin32';\n" . + "CORE::exit 0;\n" + ); -# Full directory where source files are found. + # Full directory where source files are found. my $dir_src = File::Spec->catfile($source_base, "Loops"); my $dir_dst = File::Spec->catfile($dir_base, $loop_dir); -# Gather the list of source files. -# Each will be used to generate a real test file. + # Gather the list of source files. + # Each will be used to generate a real test file. opendir BASE, $dir_src or die $!; my @base_files = grep /\.pm$/, readdir(BASE); closedir BASE; -# Initialize the destination directory. Clear or create as needed. + # Initialize the destination directory. Clear or create as needed. $dir_dst =~ tr[/][/]s; $dir_dst =~ s{/+$}{}; @@ -88,9 +88,9 @@ rmtree($dir_dst); mkpath($dir_dst, 0, 0755); -# For each source file, generate a corresponding one in the -# configured destination directory. Expand various bits to -# customize the test. + # For each source file, generate a corresponding one in the + # configured destination directory. Expand various bits to + # customize the test. foreach my $base_file (@base_files) { my $test_name = $base_file; @@ -99,8 +99,8 @@ my $full_file = File::Spec->catfile($dir_dst, $base_file); $full_file =~ s/\.pm$/.t/; -# These hardcoded expansions are for the base file to be required, -# and the base library directory where it'll be found. + # These hardcoded expansions are for the base file to be required, + # and the base library directory where it'll be found. my $expanded_src = $source; $expanded_src =~ s/--base_file--/$base_file/g; @@ -108,7 +108,7 @@ $expanded_src =~ s/--loop_cfg--/$loop_cfg/g; $expanded_src =~ s/--test_name--/$test_name/g; -# Write with lots of error checking. + # Write with lots of error checking. open EXPANDED, ">$full_file" or die $!; print EXPANDED $expanded_src; @@ -159,7 +159,6 @@ return join "", @test_source; } - 1; __END__ @@ -170,21 +169,58 @@ =head1 SYNOPSIS -See L<poe-gen-tests>. + #!/usr/bin/perl -w + use strict; + use Getopt::Long; + use POE::Test::Loops; + + my ($dir_base, $flag_help, @loop_modules, $flag_verbose); + my $result = GetOptions( + 'dirbase=s' => \$dir_base, + 'loop=s' => \@loop_modules, + 'verbose' => \$flag_verbose, + 'help' => \$flag_help, + ); + + if ( + !$result or !$dir_base or $flag_help or !@loop_modules + ) { + die( + "$0 usage:\n", + " --dirbase DIR (required) base directory for tests\n", + " --loop MODULE (required) loop modules to test\n", + " --verbose show some extra output\n", + " --help you're reading it\n", + ); + } + + POE::Test::Loops::generate($dir_base, \@loop_modules, $flag_verbose); + exit 0; + =head1 DESCRIPTION -See L<poe-gen-tests>, which is a utility to generate the actual tests -for your POE::Loop subclass. +POE::Test::Loops contains one function, generate(), which will +generate all the loop tests for one or more POE::Loop subclasses. +The L</SYNOPSIS> example is a version of L<poe-gen-tests>, which is a +stand-alone utility to generate the actual tests. L<poe-gen-tests> +also documents the POE::Test::Loops system in more detail. + =head1 FUNCTIONS =head2 generate( $DIRBASE, \@LOOPS, $VERBOSE ) -Generates the loop tests. DIRBASE is the (relative) directory in which -a subdirectory for each of the LOOPS is created. If VERBOSE is set to -a TRUE value some progress reporting is printed +Generates the loop tests. DIRBASE is the (relative) directory in +which a subdirectory for each of the LOOPS is created. If VERBOSE is +set to a TRUE value some progress reporting is printed. + POE::Test::Loops::generate( + "./t", + [ "POE::Loop::Yours" ], + 1, + ); + =head1 SEE ALSO L<POE::Loop> and L<poe-gen-tests>. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rc...@us...> - 2008-07-04 21:56:29
|
Revision: 2380 http://poe.svn.sourceforge.net/poe/?rev=2380&view=rev Author: rcaputo Date: 2008-07-04 14:56:30 -0700 (Fri, 04 Jul 2008) Log Message: ----------- Add Tony Cook's test for connect() errors. Some loops regster connect errors differently than other I/O, such as POE::XS::Loop::Poll. This covers the new condition. Resolves rt.cpan.org #37393. Modified Paths: -------------- trunk/poe-test-loops/MANIFEST Added Paths: ----------- trunk/poe-test-loops/lib/POE/Test/Loops/connect_errors.pm Modified: trunk/poe-test-loops/MANIFEST =================================================================== --- trunk/poe-test-loops/MANIFEST 2008-07-04 21:47:28 UTC (rev 2379) +++ trunk/poe-test-loops/MANIFEST 2008-07-04 21:56:30 UTC (rev 2380) @@ -9,6 +9,7 @@ lib/POE/Test/Loops/all_errors.pm lib/POE/Test/Loops/comp_tcp.pm lib/POE/Test/Loops/comp_tcp_concurrent.pm +lib/POE/Test/Loops/connect_errors.pm lib/POE/Test/Loops/k_alarms.pm lib/POE/Test/Loops/k_aliases.pm lib/POE/Test/Loops/k_detach.pm Added: trunk/poe-test-loops/lib/POE/Test/Loops/connect_errors.pm =================================================================== --- trunk/poe-test-loops/lib/POE/Test/Loops/connect_errors.pm (rev 0) +++ trunk/poe-test-loops/lib/POE/Test/Loops/connect_errors.pm 2008-07-04 21:56:30 UTC (rev 2380) @@ -0,0 +1,78 @@ +#!/usr/bin/perl -w +# $Id$ + +# POE::XS::Loop::Poll wasn't handling errors correctly, this was +# particularly noticable for connect() failures, so check connection +# failures are handled correctly + +use strict; + +BEGIN { + unless (-f "run_network_tests") { + print "1..0 # Skip Network access (and permission) required to run this test\n"; + CORE::exit(); + } +} + +use Test::More tests => 1; + +sub POE::Kernel::ASSERT_DEFAULT () { 1 } +sub POE::Kernel::TRACE_DEFAULT () { 1 } +sub POE::Kernel::TRACE_FILENAME () { "./test-output.err" } + +use POE qw( Wheel::ReadWrite Component::Client::TCP ); + +# Dynamically find an unused port for the failure-to-connect test. + +my $unused_port; +{ + use IO::Socket::INET; + my $reserved = IO::Socket::INET->new( + LocalAddr => '127.0.0.1', + LocalPort => 0, + ReuseAddr => 0, + ); + $unused_port = (sockaddr_in(getsockname($reserved)))[0]; +} + +# Timeout. + +POE::Session->create( + inline_states => { + _start => sub { + $poe_kernel->alias_set('watcher'); + $_[HEAP]{alarm} = $poe_kernel->alarm_set(timeout => time() + 10); + }, + timeout => sub { + $poe_kernel->post(client => 'shutdown'); + fail("timeout for connection"); + }, + shutdown => sub { + $poe_kernel->alarm_remove($_[HEAP]{alarm}); + }, + } +); + +# Test connection failure. + +POE::Component::Client::TCP->new( + RemotePort => $unused_port, + RemoteAddress => '127.0.0.1', + Alias => 'client', + Connected => sub { + fail("should have failed to connect"); + }, + ConnectError => sub { + $poe_kernel->post(watcher => 'shutdown'); + pass("expected connection failure occurred"); + }, + ServerInput => sub { + warn "ServerInput called unexpectedly\n"; + }, +); + +# Run the tests. + +POE::Kernel->run(); + +1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |