Version 0.09
[gitmo/MooseX-SimpleConfig.git] / t / multiple.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use lib 't/lib';
7 use lib '../t/lib';
8
9 BEGIN {
10     use Test::More;
11
12     eval "use YAML::Syck ()";
13     if($@) {
14         eval "use YAML ()";
15         if($@) {
16             plan skip_all => "YAML or YAML::Syck required for this test";
17         }
18     }
19     
20     plan tests => 5;
21
22     use_ok('MXSimpleConfigTest');
23 }
24
25 # Can it load a multiple YAML files with options
26 {
27     my $test_yaml; # generic filehandle
28     open $test_yaml, '>', 'test.yaml' or die "Cannot create test.yaml: $!";
29     print {$test_yaml} "direct_attr: 123\ninherited_ro_attr: asdf\n";
30     close $test_yaml or die "Cannot close test.yaml: $!";
31
32     open $test_yaml, '>', 'test2.yaml' or die "Cannot create test2.yaml: $!";
33     print {$test_yaml} "req_attr: foo\n";
34     close $test_yaml or die "Cannot close test.yaml: $!";
35
36     my $foo = eval {
37         MXSimpleConfigTest->new_with_config(
38             configfile => [ 'test.yaml', 'test2.yaml' ]
39         );
40     };
41     ok(!$@, 'Did not die with two YAML config files')
42         or diag $@;
43
44     is($foo->req_attr, 'foo', 'req_attr works');
45     is($foo->direct_attr, 123, 'direct_attr works');
46     is($foo->inherited_ro_attr, 'asdf', 'inherited_ro_attr works');
47 }
48
49 END {
50     unlink('test.yaml');
51     unlink('test2.yaml');
52 }