Commit | Line | Data |
---|---|---|
5a2e0210 | 1 | use strict; |
2 | use warnings; | |
f0e3c221 | 3 | |
5a2e0210 | 4 | use Test::More; |
67a1cd50 | 5 | use Config::Any; |
f0e3c221 | 6 | use Config::Any::General; |
7 | ||
5a2e0210 | 8 | if ( !Config::Any::General->is_supported ) { |
9 | plan skip_all => 'Config::General format not supported'; | |
10 | } | |
11 | else { | |
67a1cd50 | 12 | plan tests => 9; |
5a2e0210 | 13 | } |
f0e3c221 | 14 | |
5a2e0210 | 15 | { |
16 | my $config = Config::Any::General->load( 't/conf/conf.conf' ); | |
f0e3c221 | 17 | ok( $config ); |
18 | is( $config->{ name }, 'TestApp' ); | |
9ac432c2 | 19 | ok( exists $config->{ Component } ); |
5a2e0210 | 20 | } |
9ac432c2 | 21 | |
5a2e0210 | 22 | { |
23 | my $config = Config::Any::General->load( 't/conf/conf.conf', | |
24 | { -LowerCaseNames => 1 } ); | |
9ac432c2 | 25 | ok( exists $config->{ component } ); |
f0e3c221 | 26 | } |
5770ffc0 | 27 | |
7adf5673 | 28 | { |
766100bd | 29 | my $config |
30 | = Config::Any::General->load( 't/conf/single_element_arrayref.conf' ); | |
31 | is_deeply $config->{ foo }, [ 'bar' ], 'single element arrayref'; | |
7adf5673 | 32 | } |
33 | ||
5770ffc0 | 34 | # test invalid config |
35 | { | |
77f14cda | 36 | my $file = 't/invalid/conf.conf'; |
5770ffc0 | 37 | my $config = eval { Config::Any::General->load( $file ) }; |
38 | ||
39 | ok( !$config, 'config load failed' ); | |
dcfb1d1d | 40 | ok( $@, "error thrown ($@)" ); |
5770ffc0 | 41 | } |
67a1cd50 | 42 | |
43 | # parse error generated on invalid config | |
44 | { | |
45 | my $file = 't/invalid/conf.conf'; | |
46 | my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) }; | |
47 | ||
48 | ok( !$config, 'config load failed' ); | |
49 | ok( $@, "error thrown ($@)" ); | |
50 | } |