Config-General-Hierarchical
view release on metacpan or search on metacpan
# testscript for Config::General::Hierarchical module
#
# needs to be invoked using the command "make test" from
# the Config::General::Hierarchical source directory.
#
# under normal circumstances every test should succeed.
use Config::General::Hierarchical;
use Test::More tests => 35;
use Test::Differences;
my $cfg = Config::General::Hierarchical->new( file => 't/get.conf' );
is( $cfg->get('a'), 'b', 'get call' );
is( $cfg->_a, 'b', 'AUTOLOAD call' );
isa_ok( $cfg->_e, 'Config::General::Hierarchical', 'AUTOLOAD call (no cache)' );
eval { $cfg->unknown };
like(
$@,
qr{Can't locate object method "unknown" via package "Config::General::Hierarchical" at t/03_get.t line \d+.\n},
'AUTOLOAD error'
);
eval { $cfg->get( 'd', 'a' ) };
like(
$@,
qr{Config::General::Hierarchical: can't get subkey 'a' value for not node variable 'd' at t/03_get.t line \d+.\n},
'wrong get params'
);
$cfg->_d;
eval { $cfg->get( 'd', 'a' ) };
like(
$@,
qr{Config::General::Hierarchical: can't get subkey 'a' value for not node variable 'd' at t/03_get.t line \d+.\n},
'wrong cached get params'
);
is( $cfg->get( 'b', 'a' ), 'c', 'get params (2)' );
isa_ok( $cfg->get('b'), 'Config::General::Hierarchical', 'get node (2)' );
is( $cfg->get('b')->get('a'), 'c', 'get subcall (2)' );
is( $cfg->get( 'c', 'b', 'a' ), 'd', 'get params (3)' );
isa_ok(
my $node = $cfg->get( 'c', 'b' ),
'Config::General::Hierarchical',
'get node (3)'
);
is( $cfg->_c->_b->_a, 'd', 'get subcall (3)' );
is( $cfg->_c->_b, $node, 'get cache' );
is( $cfg->_c('b'), $node, 'get params cache' );
eval { $cfg->_c->_b->_a('e') };
like(
$@,
qr{Config::General::Hierarchical: can't get subkey 'e' value for not node variable 'c->b->a' at t/03_get.t line \d+.\n},
'cached names'
);
is( $cfg->_f, 'b', 'inherits order' );
eval { $cfg->_error };
like(
$@,
qr{Config::General::Hierarchical: systax error in inline variable substitution for value 'ab\$\{ab' for variable 'error' at t/03_get.t line \d+.\n},
'inline error'
);
eval { $cfg->_unfind };
( run in 0.917 second using v1.01-cache-2.11-cpan-6aa56a78535 )