improve diagnostics in yaml test
[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{
77f14cda 34 my $file = 't/invalid/conf.yml';
5770ffc0 35 my $config = eval { Config::Any::YAML->load( $file ) };
36
3a489502 37
38 is _dump($config), undef, 'config load failed';
e0186698 39 isnt $@, '', 'error thrown';
5770ffc0 40}
67a1cd50 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
3a489502 47 is _dump($config), undef, 'config load failed';
e0186698 48 isnt $@, '', 'error thrown';
67a1cd50 49}