update git repo url
[p5sagit/Config-Any.git] / t / 55-yaml.t
CommitLineData
5a2e0210 1use strict;
2use warnings;
e7be073a 3no warnings 'once';
f0e3c221 4
5a2e0210 5use Test::More;
67a1cd50 6use Config::Any;
f0e3c221 7use Config::Any::YAML;
3a489502 8use Data::Dumper;
9
10sub _dump {
11 local $Data::Dumper::Terse = 1;
12 local $Data::Dumper::Sortkeys = 1;
13 local $Data::Dumper::Indent = 1;
14 my $out = Data::Dumper::Dumper(@_);
15 $out =~ s/\s*\z//;
16 $out eq 'undef' ? undef : $out;
17}
f0e3c221 18
c2a19f63 19if ( !Config::Any::YAML->is_supported && !$ENV{RELEASE_TESTING} ) {
5a2e0210 20 plan skip_all => 'YAML format not supported';
21}
22else {
67a1cd50 23 plan tests => 6;
5a2e0210 24}
f0e3c221 25
5a2e0210 26{
27 my $config = Config::Any::YAML->load( 't/conf/conf.yml' );
f0e3c221 28 ok( $config );
29 is( $config->{ name }, 'TestApp' );
30}
5770ffc0 31
32# test invalid config
33{
53ae8e59 34 local $TODO = 'YAML::Syck parses invalid files'
35 if $INC{'YAML/Syck.pm'};
77f14cda 36 my $file = 't/invalid/conf.yml';
5770ffc0 37 my $config = eval { Config::Any::YAML->load( $file ) };
38
3a489502 39
40 is _dump($config), undef, 'config load failed';
e0186698 41 isnt $@, '', 'error thrown';
5770ffc0 42}
67a1cd50 43
44# parse error generated on invalid config
45{
53ae8e59 46 local $TODO = 'YAML::Syck parses invalid files'
47 if $INC{'YAML/Syck.pm'};
67a1cd50 48 my $file = 't/invalid/conf.yml';
49 my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) };
50
3a489502 51 is _dump($config), undef, 'config load failed';
e0186698 52 isnt $@, '', 'error thrown';
67a1cd50 53}