update git repo url
[p5sagit/Config-Any.git] / t / 53-perl.t
CommitLineData
5a2e0210 1use strict;
2use warnings;
3
c6341999 4use Test::More tests => 12;
67a1cd50 5use Config::Any;
f0e3c221 6use Config::Any::Perl;
7
5a2e0210 8{
9 my $file = 't/conf/conf.pl';
10 my $config = Config::Any::Perl->load( $file );
83020fbd 11
f0e3c221 12 ok( $config );
13 is( $config->{ name }, 'TestApp' );
83020fbd 14
5a2e0210 15 my $config_load2 = Config::Any::Perl->load( $file );
16 is_deeply( $config_load2, $config, 'multiple loads of the same file' );
f0e3c221 17}
5a2e0210 18
5770ffc0 19# test invalid config
20{
77f14cda 21 my $file = 't/invalid/conf.pl';
0354f86a 22 my $config;
23 my $loaded = eval {
24 $config = Config::Any::Perl->load( $file );
25 1;
26 };
5770ffc0 27
e0186698 28 ok !$loaded, 'config load failed';
29 is $config, undef, 'config load failed';
30 like $@, qr/syntax error/, 'error thrown';
5770ffc0 31}
67a1cd50 32
33# parse error generated on invalid config
34{
35 my $file = 't/invalid/conf.pl';
0354f86a 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
e0186698 43 ok !$loaded, 'config load failed';
44 is $config, undef, 'config load failed';
45 like $@, qr/syntax error/, 'error thrown';
67a1cd50 46}
c6341999 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
e0186698 57 ok !$loaded, 'config load failed';
58 is $config, undef, 'config load failed';
3f84b216 59 isnt $@, '', 'error thrown';
c6341999 60}