X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FConfig-Any.git;a=blobdiff_plain;f=t%2F51-ini.t;h=5cee996ca5642bf6c3ac5b08b4d32f4093c68045;hp=dbeadc5fe1d85645696746690241e363b0c3aa3c;hb=3a4895023ae6455d2fdef716214e94c3e3ddfdcc;hpb=41f47406cfe9dae0851eec4976ffcb7f4c368f22 diff --git a/t/51-ini.t b/t/51-ini.t index dbeadc5..5cee996 100644 --- a/t/51-ini.t +++ b/t/51-ini.t @@ -1,26 +1,67 @@ -use Test::More tests => 9; +use strict; +use warnings; +use Test::More; +use Config::Any; use Config::Any::INI; -my $config = eval { Config::Any::INI->load( 't/conf/conf.ini' ) }; -my $simpleconfig = eval { Config::Any::INI->load( 't/conf/conf2.ini' ) }; +if ( !Config::Any::INI->is_supported && !$ENV{RELEASE_TESTING} ) { + plan skip_all => 'INI format not supported'; +} +else { + plan tests => 15; +} + +{ + my $config = Config::Any::INI->load( 't/conf/conf.ini' ); + ok( $config, 'config loaded' ); + is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" ); + is( $config->{ Component }->{ 'Controller::Foo' }->{ foo }, + 'bar', "nested hashref hack lookup succeeded" ); +} -SKIP: { - skip "Couldn't Load INI plugin", 6 if $@; - ok( $config, "loaded INI config #1" ); +{ + my $config = Config::Any::INI->load( 't/conf/conf2.ini' ); + ok( $config, 'config loaded' ); is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" ); - is( $config->{Component}->{Controller::Foo}->{foo}, 'bar', "nested hashref hack lookup succeeded"); - - ok( $simpleconfig, "loaded INI config #1" ); - is( $simpleconfig->{ name }, 'TestApp', "toplevel key lookup succeeded" ); - is( $simpleconfig->{Controller::Foo}->{foo}, 'bar', "nested hashref hack lookup succeeded" ); -} - -$Config::Any::INI::MAP_SECTION_SPACE_TO_NESTED_KEY = 0; -my $unspaced_config = eval { Config::Any::INI->load( 't/conf/conf.ini' ); }; -SKIP: { - skip "Couldn't load INI plugin", 3 if $@; - ok( $unspaced_config, "loaded INI config #1 in no-map-space mode" ); - is( $unspaced_config->{name}, 'TestApp', "toplevel key lookup succeeded" ); - is( $unspaced_config->{'Component Controller::Foo'}->{foo}, 'bar', "unnested key lookup succeeded"); + is( $config->{ 'Controller::Foo' }->{ foo }, + 'bar', "nested hashref hack lookup succeeded" ); +} + +{ + local $Config::Any::INI::MAP_SECTION_SPACE_TO_NESTED_KEY = 0; + my $config = Config::Any::INI->load( 't/conf/conf.ini' ); + ok( $config, 'config loaded (no-map-space mode)' ); + is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" ); + is( $config->{ 'Component Controller::Foo' }->{ foo }, + 'bar', "unnested key lookup succeeded" ); +} + +{ + my $config = Config::Any::INI->load( 't/conf/subsections.ini' ); + + my %expected + = ( section1 => + { a => 1, subsection1 => { b => 2 }, subsection2 => { c => 3 } } + ); + ok( $config, 'config loaded' ); + is_deeply( $config, \%expected, 'subsections parsed properly' ); +} + +# test invalid config +{ + my $file = 't/invalid/conf.ini'; + my $config = eval { Config::Any::INI->load( $file ) }; + + is $config, undef, 'config load failed'; + isnt $@, '', 'error thrown'; +} + +# parse error generated on invalid config +{ + my $file = 't/invalid/conf.ini'; + my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) }; + + is $config, undef, 'config load failed'; + isnt $@, '', 'error thrown'; }