Release commit for 0.30
[p5sagit/Config-Any.git] / t / 54-xml.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Config::Any;
6 use Config::Any::XML;
7
8 if ( !Config::Any::XML->is_supported ) {
9     plan skip_all => 'XML format not supported';
10 }
11 else {
12     plan tests => 8;
13 }
14
15 {
16     my $config = Config::Any::XML->load( 't/conf/conf.xml' );
17     ok( $config );
18     is( $config->{ name }, 'TestApp' );
19 }
20
21 # test invalid config
22 SKIP: {
23     my $broken_libxml
24         = eval { require XML::LibXML; XML::LibXML->VERSION lt '1.59'; };
25     skip 'XML::LibXML < 1.58 has issues', 2 if $broken_libxml;
26
27     local $SIG{ __WARN__ } = sub { };    # squash warnings from XML::Simple
28     my $file = 't/invalid/conf.xml';
29     my $config = eval { Config::Any::XML->load( $file ) };
30
31     ok( !$config, 'config load failed' );
32     ok( $@,       "error thrown ($@)" );
33 }
34
35 # test conf file with array ref
36 {
37     my $file = 't/conf/conf_arrayref.xml';
38     my $config = eval { Config::Any::XML->load( $file ) };
39
40     ok( $config, 'config loaded' );
41     ok( !$@,     'no error thrown' );
42 }
43
44 # parse error generated on invalid config
45 {
46     my $file = 't/invalid/conf.xml';
47     my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) };
48
49     ok( !$config, 'config load failed' );
50     ok( $@,       "error thrown ($@)" );
51 }
52