X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FConfig-Any.git;a=blobdiff_plain;f=t%2F61-features.t;h=62bd59e1d792ca1793d92858fd3823d60ee8f71d;hp=b2d84676f310c9ed043f91df49f21299526bae43;hb=aa7bd7c30e544ebbb418c2a0508523800e790836;hpb=41f47406cfe9dae0851eec4976ffcb7f4c368f22 diff --git a/t/61-features.t b/t/61-features.t index b2d8467..62bd59e 100644 --- a/t/61-features.t +++ b/t/61-features.t @@ -1,51 +1,83 @@ -package MockApp; -use strict; -use warnings; - -$|++; - -use Test::More tests => 10; -use Scalar::Util qw(blessed reftype); - -use Config::Any; -use Config::Any::INI; - -our $cfg_file = 't/conf/conf.foo'; - -eval { Config::Any::INI->load($cfg_file); }; -SKIP: { - skip "File loading backend for INI not found", 9 if $@; - - ok( my $c_arr = Config::Any->load_files({ - files => [ $cfg_file ], - force_plugins => [qw(Config::Any::INI)] - }), "load file with parser forced" ); - - 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, $cfg_file, "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" ); - - - ok( my $c_arr_2 = Config::Any->load_files({ - files => [ $cfg_file ], - force_plugins => [qw(Config::Any::INI)], - use_ext => 1 - }), "load file with parser forced" ); -} - - - +package MockApp; +use strict; +use warnings; + +$|++; + +use Test::More tests => 14; +use Scalar::Util qw(blessed reftype); + +use Config::Any; +use Config::Any::INI; + +our $cfg_file = 't/conf/conf.foo'; + +eval { Config::Any::INI->load( $cfg_file ); }; + +SKIP: { + skip "File loading backend for INI not found", 14 if $@; + + my $struct; # used to make sure parsing works for arrays and hashes + + # force_plugins + { + my $result = Config::Any->load_files( + { files => [ $cfg_file ], + force_plugins => [ qw(Config::Any::INI) ] + } + ); + + ok( $result, 'load file with parser forced' ); + + ok( my $first = $result->[ 0 ], 'load_files returns an arrayref' ); + ok( ref $first, 'load_files arrayref contains a ref' ); + + my $ref = blessed $first ? reftype $first : ref $first; + is( substr( $ref, 0, 4 ), 'HASH', 'hashref' ); + + $struct = $first; + + my ( $name, $cfg ) = %$first; + is( $name, $cfg_file, 'filenames match' ); + + 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' ); + } + + # flatten_to_hash + { + my $result = Config::Any->load_files( + { files => [ $cfg_file ], + force_plugins => [ qw(Config::Any::INI) ], + flatten_to_hash => 1 + } + ); + + ok( $result, 'load file with parser forced, flatten to hash' ); + ok( ref $result, 'load_files hashref contains a ref' ); + + my $ref = blessed $result ? reftype $result : ref $result; + is( substr( $ref, 0, 4 ), 'HASH', 'hashref' ); + + is_deeply( $result, $struct, 'load_files return an hashref (flatten_to_hash)' ); + } + + # use_ext + { + ok( my $result = Config::Any->load_files( + { files => [ $cfg_file ], + force_plugins => [ qw(Config::Any::INI) ], + use_ext => 1 + } + ), + "load file with parser forced" + ); + } +} +