X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FConfig-Any.git;a=blobdiff_plain;f=t%2F20-parse.t;h=910c80baf778208fa0015a705d9f74404bf88ad7;hp=640bb79bb3750285bec107b9909af507e28863a2;hb=c2a19f634f7a084c1e9c76142d4e7554895d454b;hpb=e967a60fa6fb5adeb6ead013b0b60289b2a92e2e diff --git a/t/20-parse.t b/t/20-parse.t index 640bb79..910c80b 100644 --- a/t/20-parse.t +++ b/t/20-parse.t @@ -1,27 +1,64 @@ -package MockApp; - -use Test::More tests => 54; -use Scalar::Util qw(blessed reftype); -use Config::Any; - -my @files = map { "t/conf/$_" } - qw(conf.conf conf.ini conf.json conf.pl conf.xml conf.yml); - -for my $f (@files) { - ok(my $c_arr = Config::Any->load_files({files=>[$f], use_ext=>1}), "load_files with use_ext works"); - ok(my $c = $c_arr->[0], "load_files returns an arrayref"); - ok(ref $c, "load_files arrayref contains a ref"); - my $ref = blessed $c ? reftype $c : ref $c; - is(substr($ref,0,4), "HASH", "hashref"); - my ($name, $cfg) = each %$c; - is($name, $f, "filename matches"); - my $cfgref = blessed $cfg ? reftype $cfg : ref $cfg; - is(substr($cfgref,0,4), "HASH", "hashref cfg"); - - is( $cfg->{name}, 'TestApp', "appname parses" ); - is( $cfg->{Component}{ "Controller::Foo" }->{ foo }, 'bar', - "component->cntrlr->foo = bar" ); - is( $cfg->{Model}{ "Model::Baz" }->{ qux }, 'xyzzy', - "model->model::baz->qux = xyzzy" ); -} - +package MockApp; +use strict; +use warnings; +no warnings 'once'; + +use Test::More tests => 6*9; +use Scalar::Util qw(blessed reftype); +use Config::Any; +use Config::Any::General; +use Config::Any::INI; +use Config::Any::JSON; +use Config::Any::Perl; +use Config::Any::XML; +use Config::Any::YAML; + +our %ext_map = ( + conf => 'Config::Any::General', + ini => 'Config::Any::INI', + json => 'Config::Any::JSON', + pl => 'Config::Any::Perl', + xml => 'Config::Any::XML', + yml => 'Config::Any::YAML' +); + +sub load_parser_for { + my $f = shift; + return unless $f; + + my ( $ext ) = $f =~ m{ \. ( [^\.]+ ) \z }xms; + my $mod = $ext_map{ $ext }; + return !$mod->is_supported ? ( 1, $mod ) : ( 0, $mod ); +} + +for my $f ( map { "t/conf/conf.$_" } keys %ext_map ) { + my ( $skip, $mod ) = load_parser_for( $f ); + SKIP: { + skip "File loading backend for $mod not found", 9 + if $skip && !$ENV{RELEASE_TESTING}; + + ok( my $c_arr + = Config::Any->load_files( + { files => [ $f ], use_ext => 1 } ), + "load_files with use_ext works [$f]" + ); + ok( my $c = $c_arr->[ 0 ], "load_files returns an arrayref" ); + + ok( ref $c, "load_files arrayref contains a ref" ); + my $ref = blessed $c ? reftype $c : ref $c; + is( substr( $ref, 0, 4 ), "HASH", "hashref" ); + + my ( $name, $cfg ) = each %$c; + is( $name, $f, "filename matches" ); + + my $cfgref = blessed $cfg ? reftype $cfg : ref $cfg; + is( substr( $cfgref, 0, 4 ), "HASH", "hashref cfg" ); + + is( $cfg->{ name }, 'TestApp', "appname parses" ); + is( $cfg->{ Component }{ "Controller::Foo" }->{ foo }, + 'bar', "component->cntrlr->foo = bar" ); + is( $cfg->{ Model }{ "Model::Baz" }->{ qux }, + 'xyzzy', "model->model::baz->qux = xyzzy" ); + } +} +