allow YAML::Syck to fail the error tests
[p5sagit/Config-Any.git] / t / 55-yaml.t
1 use strict;
2 use warnings;
3 no warnings 'once';
4
5 use Test::More;
6 use Config::Any;
7 use Config::Any::YAML;
8 use Data::Dumper;
9
10 sub _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 }
18
19 if ( !Config::Any::YAML->is_supported && !$ENV{RELEASE_TESTING} ) {
20     plan skip_all => 'YAML format not supported';
21 }
22 else {
23     plan tests => 6;
24 }
25
26 {
27     my $config = Config::Any::YAML->load( 't/conf/conf.yml' );
28     ok( $config );
29     is( $config->{ name }, 'TestApp' );
30 }
31
32 # test invalid config
33 {
34     local $TODO = 'YAML::Syck parses invalid files'
35         if $INC{'YAML/Syck.pm'};
36     my $file = 't/invalid/conf.yml';
37     my $config = eval { Config::Any::YAML->load( $file ) };
38
39
40     is _dump($config), undef, 'config load failed';
41     isnt $@, '', 'error thrown';
42 }
43
44 # parse error generated on invalid config
45 {
46     local $TODO = 'YAML::Syck parses invalid files'
47         if $INC{'YAML/Syck.pm'};
48     my $file = 't/invalid/conf.yml';
49     my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) };
50
51     is _dump($config), undef, 'config load failed';
52     isnt $@, '', 'error thrown';
53 }