better diagnostics on test failures
[p5sagit/Config-Any.git] / t / 53-perl.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 12;
5 use Config::Any;
6 use Config::Any::Perl;
7
8 {
9     my $file   = 't/conf/conf.pl';
10     my $config = Config::Any::Perl->load( $file );
11
12     ok( $config );
13     is( $config->{ name }, 'TestApp' );
14
15     my $config_load2 = Config::Any::Perl->load( $file );
16     is_deeply( $config_load2, $config, 'multiple loads of the same file' );
17 }
18
19 # test invalid config
20 {
21     my $file = 't/invalid/conf.pl';
22     my $config;
23     my $loaded = eval {
24         $config = Config::Any::Perl->load( $file );
25         1;
26     };
27
28     ok !$loaded, 'config load failed';
29     is $config, undef, 'config load failed';
30     like $@, qr/syntax error/, 'error thrown';
31 }
32
33 # parse error generated on invalid config
34 {
35     my $file = 't/invalid/conf.pl';
36     my $config;
37     my $loaded = eval {
38         $config = Config::Any::Perl->load( $file );
39         Config::Any->load_files( { files => [$file], use_ext => 1} );
40         1;
41     };
42
43     ok !$loaded, 'config load failed';
44     is $config, undef, 'config load failed';
45     like $@, qr/syntax error/, 'error thrown';
46 }
47
48 # test missing config
49 {
50     my $file = 't/invalid/missing.pl';
51     my $config;
52     my $loaded = eval {
53         $config = Config::Any::Perl->load( $file );
54         1;
55     };
56
57     ok !$loaded, 'config load failed';
58     is $config, undef, 'config load failed';
59     like $@, qr/No such file or directory/, 'error thrown';
60 }