Config-General-Hierarchical

 view release on metacpan or  search on metacpan

t/04_constraint.t  view on Meta::CPAN

# 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 => 73;
use Test::Differences;

my $cfg = TestConfig->new( file => 't/constraint.conf' );
isa_ok( $cfg, 'Config::General::Hierarchical', 'class inheritance' );

eval { TestConfig->import };
is( $@, '', 'syntax' );

eval { TestConfig3->import };
is( $@, "TestConfig3: syntax method musts return an HASH reference\n",
    'wrong syntax' );

eval { TestConfig4->import };
is(
    $@,
"TestConfig4: wrong use of ARRAY reference as syntax for variable 'WrongR'\n",
    'wrong syntax ref'
);

eval { TestConfig5->import };
is(
    $@,
    "TestConfig5: wrong 'test' syntax for variable 'WrongV'\n",
    'wrong syntax value'
);

eval { TestConfig6->import };
is(
    $@,
"TestConfig6: wrong use of 'm' flag for not string nor array variable 'WrongM->NotMerge'\n",
    'wrong syntax value'
);

eval { $cfg->_Undefined };
like(
    $@,
qr{Config::General::Hierarchical: request for undefined variable 'Undefined'\nin file: .+/t/constraint.conf at t/04_constraint.t line \d+.\n},
    'undefined without constraint'
);

eval { $cfg->_Node->_Undefined };
like(
    $@,
qr{Config::General::Hierarchical: request for undefined variable 'Node->Undefined'\nin file: .+/t/constraint.conf at t/04_constraint.t line \d+.\n},
    'undefined without constraint 2'
);

eval { $cfg->_Array };
like(
    $@,
qr{Config::General::Hierarchical: variable 'Array' is an array: should be a string or a node\nin file: .+/t/constraint.conf at t/04_constraint.t line \d+.\n},
    'array without constraint'
);

eval { $cfg->_Integer };
like(
    $@,
qr{Config::General::Hierarchical: variable 'Integer' is an array but should be a integer value\nin file: .+/t/constraint.conf at t/04_constraint.t line \d+.\n},
    'array but ...'
);



( run in 1.912 second using v1.01-cache-2.11-cpan-f56aa216473 )