Blame t/02_main.t

Packit 549706
#!/usr/bin/perl
Packit 549706
Packit 549706
# Load testing for prefork.pm
Packit 549706
Packit 549706
use strict;
Packit 549706
BEGIN {
Packit 549706
	$|  = 1;
Packit 549706
	$^W = 1;
Packit 549706
}
Packit 549706
use Test::More tests => 18;
Packit 549706
Packit 549706
# Try to prefork-load a module
Packit 549706
use prefork;
Packit 549706
is( prefork::prefork('File::Spec::Functions'), 1, 'prefork returns true' );
Packit 549706
is( $prefork::MODULES{'File::Spec::Functions'}, 'File/Spec/Functions.pm', 'Module is added to queue' );
Packit 549706
ok( ! $INC{'File/Spec/Functions.pm'}, 'Module is not loaded' );
Packit 549706
Packit 549706
# Load outstanding modules
Packit 549706
is( $prefork::FORKING, '', 'The $FORKING variable is false' );
Packit 549706
is( prefork::enable(), 1, 'prefork::enable returns true' );
Packit 549706
is( scalar(keys %prefork::MODULES), 0, 'All modules are loaded by enable' );
Packit 549706
is( $prefork::FORKING, 1, 'The $FORKING variable is set' );
Packit 549706
ok( $INC{'File/Spec/Functions.pm'}, 'Module is now loaded' );
Packit 549706
Packit 549706
# use in pragma form after enabling, using stringification
Packit 549706
my $Foo = Foo->new;
Packit 549706
isa_ok( $Foo, 'Foo' );
Packit 549706
ok( ! $INC{'Test/Simple.pm'}, 'Test::Simple is not loaded' );
Packit 549706
is( prefork::prefork($Foo), 1, 'prefork(Object) returns true' );
Packit 549706
is( scalar(keys %prefork::MODULES), 0, 'The %MODULES hash is still empty' );
Packit 549706
ok( $INC{'Test/Simple.pm'}, 'Test::Simple is loaded' );
Packit 549706
Packit 549706
Packit 549706
Packit 549706
Packit 549706
Packit 549706
#####################################################################
Packit 549706
# Additional error-detection tests
Packit 549706
Packit 549706
eval { prefork::prefork(undef); };
Packit 549706
ok( $@ =~ /You did not pass a module name to prefork/, 'bad prefork returns correct error' );
Packit 549706
ok( $@ =~ /02_main/, 'bad prefork error returns from correct module' );
Packit 549706
eval { prefork::prefork(''); };
Packit 549706
ok( $@ =~ /You did not pass a module name to prefork/, 'bad prefork returns correct error' );
Packit 549706
eval { prefork::prefork('Foo Bar') };
Packit 549706
ok( $@ =~ /is not a module name/, 'bad prefork returns correct error' );
Packit 549706
ok( $@ =~ /02_main/, 'bad prefork error returns from correct module' );
Packit 549706
Packit 549706
exit(0);
Packit 549706
Packit 549706
Packit 549706
Packit 549706
# Test class
Packit 549706
Packit 549706
package Foo;
Packit 549706
Packit 549706
use overload '""', 'string';
Packit 549706
Packit 549706
sub new { bless {}, 'Foo' };
Packit 549706
sub string { 'Test::Simple' };
Packit 549706
Packit 549706
1;