Config-General-Hierarchical

 view release on metacpan or  search on metacpan

t/99_dump.t  view on Meta::CPAN

# testscript for Config::General::Hierarchical::Dump module
#
# needs to be invoked using the command "make test" from
# the Config::General::Hierarchical source directory.
#
# under normal circumstances every test should succeed.

my $tests;
my $skip;

BEGIN {
    $tests = 59;
}

use Test::More tests => $tests;
use Test::Differences;

require_ok Config::General::Hierarchical::Dump;
require_ok Config::General::Hierarchical::DumpTest;

`echo "#!$^X -MConfig::General::Hierarchical::Dump\nvariable value\n<node>\n key value\n keys\n</node>\ndefined" > t/dump.conf`;
`chmod 755 t/dump.conf`;

is( `t/dump.conf`, <<EOF, 'self execution' );
defined = '';
node->key = 'value';
node->keys = '';
variable = 'value';
EOF

my $cfg = Config::General::Hierarchical->new( file => 't/dump.conf' );
my $res = '';
eval { $res = $cfg->_defined; };
is( $@,   '', 'compatibility 1' );
is( $res, '', 'compatibility 2' );

like(
    Config::General::Hierarchical::Dump->do_all( 't/dump_error.conf', [] ),
qr{Parsing error: Config::General::Hierarchical: Config::General: Block "<node>" has no EndBlock statement \(level: 2, chunk 1\)\!\nin file: .+/t/dump_error.conf\n  at .+/Hierarchical/Dump.pm line \d+\n$},
    'parse error'
);

is(
    join(
        '', Config::General::Hierarchical::Dump->do_all( 't/dump.conf', [] )
    ),
    <<EOF, 'execution' );
defined = '';
node->key = 'value';
node->keys = '';
variable = 'value';
EOF

my $path = ".+/t/";
my @out = Config::General::Hierarchical::Dump->do_all( 't/dump.conf', ['-f'] );
like( $out[0], qr{Configuration files base dir: $path}, '-f 1' );
like( $out[1], qr{defined = ''; dump.conf},             '-f 2' );
like( $out[2], qr{node->key = 'value'; dump.conf},      '-f 3' );
like( $out[3], qr{node->keys = ''; dump.conf},          '-f 4' );
like( $out[4], qr{variable = 'value'; dump.conf},       '-f 5' );

@out = Config::General::Hierarchical::Dump->do_all( 't/dump.conf', ['--file'] );
like( $out[0], qr{Configuration files base dir: $path}, '--file 1' );
like( $out[1], qr{defined = ''; dump.conf},             '--file 2' );
like( $out[2], qr{node->key = 'value'; dump.conf},      '--file 3' );
like( $out[3], qr{node->keys = ''; dump.conf},          '--file 4' );
like( $out[4], qr{variable = 'value'; dump.conf},       '--file 5' );

@out = Config::General::Hierarchical::Dump->do_all( 't/dump.conf', ['-fl'] );
like( $out[0], qr{Configuration files base dir: $path}, '-fl 1 1' );
like( $out[1], qr{defined    = '';      dump.conf},     '-fl 1 2' );
like( $out[2], qr{node->key  = 'value'; dump.conf},     '-fl 1 3' );
like( $out[3], qr{node->keys = '';      dump.conf},     '-fl 1 4' );
like( $out[4], qr{variable   = 'value'; dump.conf},     '-fl 1 5' );

@out =



( run in 3.680 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )