907d576bdd1229bba5ff03851fd0f649d961a775
[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     my $file = 't/invalid/conf.yml';
35     my $config = eval { Config::Any::YAML->load( $file ) };
36
37
38     is _dump($config), undef, 'config load failed';
39     isnt $@, '', 'error thrown';
40 }
41
42 # parse error generated on invalid config
43 {
44     my $file = 't/invalid/conf.yml';
45     my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) };
46
47     is _dump($config), undef, 'config load failed';
48     isnt $@, '', 'error thrown';
49 }