X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FConfig-Any.git;a=blobdiff_plain;f=t%2F54-xml.t;h=d3aa3d48b26cc487408689e70216befc64ca4351;hp=41376aca7254e025ff4769e94330fb4f8c50bfdc;hb=3a4895023ae6455d2fdef716214e94c3e3ddfdcc;hpb=9d569cf0c9b945399035ced825ff7059692786c7 diff --git a/t/54-xml.t b/t/54-xml.t index 41376ac..d3aa3d4 100644 --- a/t/54-xml.t +++ b/t/54-xml.t @@ -2,30 +2,74 @@ use strict; use warnings; use Test::More; +use Config::Any; use Config::Any::XML; -if ( !Config::Any::XML->is_supported ) { +if ( !Config::Any::XML->is_supported && !$ENV{RELEASE_TESTING} ) { plan skip_all => 'XML format not supported'; } else { - plan tests => 4; + plan tests => 7; } { my $config = Config::Any::XML->load( 't/conf/conf.xml' ); - ok( $config ); - is( $config->{ name }, 'TestApp' ); + is_deeply $config, { + 'Component' => { + 'Controller::Foo' => { + 'foo' => 'bar' + }, + }, + 'name' => 'TestApp', + 'Model' => { + 'Model::Baz' => { + 'qux' => 'xyzzy', + }, + }, + }, 'config loaded'; } # test invalid config SKIP: { - my $broken_libxml = eval { require XML::LibXML; XML::LibXML->VERSION lt '1.59'; }; + my $broken_libxml + = eval { require XML::LibXML; XML::LibXML->VERSION lt '1.59'; }; skip 'XML::LibXML < 1.58 has issues', 2 if $broken_libxml; - local $SIG{__WARN__} = sub {}; # squash warnings from XML::Simple + local $SIG{ __WARN__ } = sub { }; # squash warnings from XML::Simple my $file = 't/invalid/conf.xml'; my $config = eval { Config::Any::XML->load( $file ) }; - ok( !$config, 'config load failed' ); - ok( $@, "error thrown ($@)" ); + is $config, undef, 'config load failed'; + isnt $@, '', 'error thrown'; } + +# test conf file with array ref +{ + my $file = 't/conf/conf_arrayref.xml'; + my $config = eval { Config::Any::XML->load( $file ) }; + + is_deeply $config, { + 'indicator' => 'submit', + 'elements' => [ + { + 'label' => 'Label1', + 'type' => 'Text', + }, + { + 'label' => 'Label2', + 'type' => 'Text', + }, + ], + }, 'config loaded'; + is $@, '', 'no error thrown'; +} + +# parse error generated on invalid config +{ + my $file = 't/invalid/conf.xml'; + my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) }; + + is $config, undef, 'config load failed'; + isnt $@, '', 'error thrown'; +} +