|
Packit |
37d9e7 |
#!/usr/bin/perl
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
use strict;
|
|
Packit |
37d9e7 |
BEGIN {
|
|
Packit |
37d9e7 |
$| = 1;
|
|
Packit |
37d9e7 |
$^W = 1;
|
|
Packit |
37d9e7 |
$ENV{PERL_PARAMS_UTIL_PP} ||= 1;
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
use Test::More tests => 91;
|
|
Packit |
37d9e7 |
use File::Spec::Functions ':ALL';
|
|
Packit |
37d9e7 |
BEGIN {
|
|
Packit |
37d9e7 |
ok( ! defined &_CLASSISA, '_CLASSISA does not exist' );
|
|
Packit |
37d9e7 |
ok( ! defined &_SUBCLASS, '_SUBCLASS does not exist' );
|
|
Packit |
37d9e7 |
ok( ! defined &_DRIVER, '_DRIVER does not exist' );
|
|
Packit |
37d9e7 |
use_ok('Params::Util', qw(_CLASSISA _SUBCLASS _DRIVER));
|
|
Packit |
37d9e7 |
ok( defined &_CLASSISA, '_CLASSISA imported ok' );
|
|
Packit |
37d9e7 |
ok( defined &_SUBCLASS, '_SUBCLASS imported ok' );
|
|
Packit |
37d9e7 |
ok( defined &_DRIVER, '_DRIVER imported ok' );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import refaddr to make certain we have it
|
|
Packit |
37d9e7 |
use Scalar::Util 'refaddr';
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Preparing
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
my $A = catfile( 't', 'driver', 'A.pm' );
|
|
Packit |
37d9e7 |
ok( -f $A, 'A exists' );
|
|
Packit |
37d9e7 |
my $B = catfile( 't', 'driver', 'My_B.pm' );
|
|
Packit |
37d9e7 |
ok( -f $B, 'My_B exists' );
|
|
Packit |
37d9e7 |
my $C = catfile( 't', 'driver', 'C.pm' );
|
|
Packit |
37d9e7 |
ok( ! -f $C, 'C does not exist' );
|
|
Packit |
37d9e7 |
my $D = catfile( 't', 'driver', 'D.pm' );
|
|
Packit |
37d9e7 |
ok( -f $D, 'D does not exist' );
|
|
Packit |
37d9e7 |
my $E = catfile( 't', 'driver', 'E.pm' );
|
|
Packit |
37d9e7 |
ok( -f $E, 'E does not exist' );
|
|
Packit |
37d9e7 |
my $F = catfile( 't', 'driver', 'F.pm' );
|
|
Packit |
37d9e7 |
ok( -f $F, 'F does not exist' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
unshift @INC, catdir( 't', 'driver' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Things that are not file handles
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
foreach (
|
|
Packit |
37d9e7 |
undef, '', ' ', 'foo bar', 1, 0, -1, 1.23,
|
|
Packit |
37d9e7 |
[], {}, \'', bless( {}, "foo" )
|
|
Packit |
37d9e7 |
) {
|
|
Packit |
37d9e7 |
is( _CLASSISA($_, 'A'), undef, 'Non-classisa returns undef' );
|
|
Packit |
37d9e7 |
is( _SUBCLASS($_, 'A'), undef, 'Non-subclass returns undef' );
|
|
Packit |
37d9e7 |
is( _DRIVER($_, 'A'), undef, 'Non-driver returns undef' );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Sample Classes
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# classisa should not load classes
|
|
Packit |
37d9e7 |
is( _CLASSISA('A', 'A'), 'A', 'A: Driver base class is undef' );
|
|
Packit |
37d9e7 |
is( _CLASSISA('My_B', 'A'), undef, 'B: Good driver returns ok' );
|
|
Packit |
37d9e7 |
is( _CLASSISA('My_B', 'H'), undef, 'B: Good driver return undef for incorrect base' );
|
|
Packit |
37d9e7 |
is( _CLASSISA('C', 'A'), undef, 'C: Non-existant driver is undef' );
|
|
Packit |
37d9e7 |
is( _CLASSISA('D', 'A'), undef, 'D: Broken driver is undef' );
|
|
Packit |
37d9e7 |
is( _CLASSISA('E', 'A'), undef, 'E: Not a driver returns undef' );
|
|
Packit |
37d9e7 |
is( _CLASSISA('F', 'A'), undef, 'F: Faked isa returns ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# classisa should not load classes
|
|
Packit |
37d9e7 |
is( _SUBCLASS('A', 'A'), undef, 'A: Driver base class is undef' );
|
|
Packit |
37d9e7 |
is( _SUBCLASS('My_B', 'A'), undef, 'B: Good driver returns ok' );
|
|
Packit |
37d9e7 |
is( _SUBCLASS('My_B', 'H'), undef, 'B: Good driver return undef for incorrect base' );
|
|
Packit |
37d9e7 |
is( _SUBCLASS('C', 'A'), undef, 'C: Non-existant driver is undef' );
|
|
Packit |
37d9e7 |
is( _SUBCLASS('D', 'A'), undef, 'D: Broken driver is undef' );
|
|
Packit |
37d9e7 |
is( _SUBCLASS('E', 'A'), undef, 'E: Not a driver returns undef' );
|
|
Packit |
37d9e7 |
is( _SUBCLASS('F', 'A'), undef, 'F: Faked isa returns ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# The base class itself is not a driver
|
|
Packit |
37d9e7 |
is( _DRIVER('A', 'A'), undef, 'A: Driver base class is undef' );
|
|
Packit |
37d9e7 |
ok( $A::VERSION, 'A: Class is loaded ok' );
|
|
Packit |
37d9e7 |
is( _DRIVER('My_B', 'A'), 'My_B', 'B: Good driver returns ok' );
|
|
Packit |
37d9e7 |
is( _DRIVER('My_B', 'H'), undef, 'B: Good driver return undef for incorrect base' );
|
|
Packit |
37d9e7 |
ok( $My_B::VERSION, 'B: Class is loaded ok' );
|
|
Packit |
37d9e7 |
is( _DRIVER('C', 'A'), undef, 'C: Non-existant driver is undef' );
|
|
Packit |
37d9e7 |
is( _DRIVER('D', 'A'), undef, 'D: Broken driver is undef' );
|
|
Packit |
37d9e7 |
is( _DRIVER('E', 'A'), undef, 'E: Not a driver returns undef' );
|
|
Packit |
37d9e7 |
is( _DRIVER('F', 'A'), 'F', 'F: Faked isa returns ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Repeat for classisa
|
|
Packit |
37d9e7 |
is( _CLASSISA('A', 'A'), 'A', 'A: Driver base class is undef' );
|
|
Packit |
37d9e7 |
is( _CLASSISA('My_B', 'A'), 'My_B', 'B: Good driver returns ok' );
|
|
Packit |
37d9e7 |
is( _CLASSISA('My_B', 'H'), undef, 'B: Good driver return undef for incorrect base' );
|
|
Packit |
37d9e7 |
is( _CLASSISA('C', 'A'), undef, 'C: Non-existant driver is undef' );
|
|
Packit |
37d9e7 |
is( _CLASSISA('D', 'A'), 'D', 'D: Broken driver is undef' );
|
|
Packit |
37d9e7 |
is( _CLASSISA('E', 'A'), undef, 'E: Not a driver returns undef' );
|
|
Packit |
37d9e7 |
is( _CLASSISA('F', 'A'), 'F', 'F: Faked isa returns ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Repeat for subclasses
|
|
Packit |
37d9e7 |
is( _SUBCLASS('A', 'A'), undef, 'A: Driver base class is undef' );
|
|
Packit |
37d9e7 |
is( _SUBCLASS('My_B', 'A'), 'My_B', 'B: Good driver returns ok' );
|
|
Packit |
37d9e7 |
is( _SUBCLASS('My_B', 'H'), undef, 'B: Good driver return undef for incorrect base' );
|
|
Packit |
37d9e7 |
is( _SUBCLASS('C', 'A'), undef, 'C: Non-existant driver is undef' );
|
|
Packit |
37d9e7 |
is( _SUBCLASS('D', 'A'), 'D', 'D: Broken driver is undef' );
|
|
Packit |
37d9e7 |
is( _SUBCLASS('E', 'A'), undef, 'E: Not a driver returns undef' );
|
|
Packit |
37d9e7 |
is( _SUBCLASS('F', 'A'), 'F', 'F: Faked isa returns ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
SKIP: {
|
|
Packit |
37d9e7 |
use_ok('Params::Util', qw(_CLASSDOES));
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
skip "DOES tests do not make sense on perls before 5.10", 4
|
|
Packit |
37d9e7 |
unless $] >= 5.010;
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
is( _CLASSDOES('A', 'A'), 'A', 'A: DOES A' );
|
|
Packit |
37d9e7 |
is( _CLASSDOES('My_B', 'A'), 'My_B', 'My_B: DOES A' );
|
|
Packit |
37d9e7 |
is( _CLASSDOES('E', 'A'), undef, 'E: DOES not A' );
|
|
Packit |
37d9e7 |
is( _CLASSDOES('F', 'A'), 'F', 'F: DOES A' );
|
|
Packit |
37d9e7 |
}
|