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=0d546cb98e3d19c48f877ecb8a793af1d83f864c;hp=4ddba3cf82d70823328e30cfa802c92edd9ce053;hb=1afb249c67eda203b13fef661fd046bff0ee26cc;hpb=f0e3c2214342d0d8a8839009b8b9c7e6bfbc7ab2 diff --git a/t/54-xml.t b/t/54-xml.t index 4ddba3c..0d546cb 100644 --- a/t/54-xml.t +++ b/t/54-xml.t @@ -1,11 +1,52 @@ -use Test::More tests => 2; +use strict; +use warnings; +use Test::More; +use Config::Any; use Config::Any::XML; -my $config = eval { Config::Any::XML->load( 't/conf/conf.xml' ) }; +if ( !Config::Any::XML->is_supported ) { + plan skip_all => 'XML format not supported'; +} +else { + plan tests => 8; +} -SKIP: { - skip "Couldn't Load XML plugin", 2 if $@; +{ + my $config = Config::Any::XML->load( 't/conf/conf.xml' ); ok( $config ); is( $config->{ name }, 'TestApp' ); } + +# test invalid config +SKIP: { + 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 + my $file = 't/invalid/conf.xml'; + my $config = eval { Config::Any::XML->load( $file ) }; + + ok( !$config, 'config load failed' ); + ok( $@, "error thrown ($@)" ); +} + +# test conf file with array ref +{ + my $file = 't/conf/conf_arrayref.xml'; + my $config = eval { Config::Any::XML->load( $file ) }; + + ok( $config, 'config loaded' ); + ok( !$@, '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} ) }; + + ok( !$config, 'config load failed' ); + ok( $@, "error thrown ($@)" ); +} +