Commit | Line | Data |
a96520dd |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use lib 't/lib'; |
7 | use lib '../t/lib'; |
5b519d9c |
8 | use Test::More; |
9 | our @classes; |
a96520dd |
10 | BEGIN { |
5b519d9c |
11 | |
12 | @classes = qw/ MXDefaultConfigTest MXDefaultMultipleConfigsTest /; |
a96520dd |
13 | |
14 | eval "use YAML::Syck ()"; |
15 | if($@) { |
16 | eval "use YAML ()"; |
17 | if($@) { |
18 | plan skip_all => "YAML or YAML::Syck required for this test"; |
19 | } |
20 | } |
a96520dd |
21 | |
5b519d9c |
22 | use_ok($_) for @classes; |
a96520dd |
23 | } |
24 | |
25 | # Can it load a simple YAML file with the options |
26 | # based on a default in the configfile attr |
27 | { |
28 | open(my $test_yaml, '>', 'test.yaml') |
29 | or die "Cannot create test.yaml: $!"; |
30 | print $test_yaml "direct_attr: 123\ninherited_ro_attr: asdf\nreq_attr: foo\n"; |
31 | close($test_yaml); |
32 | |
5b519d9c |
33 | } |
34 | |
35 | foreach my $class (@classes) { |
a96520dd |
36 | my $foo = eval { |
5b519d9c |
37 | $class->new_with_config(); |
a96520dd |
38 | }; |
39 | ok(!$@, 'Did not die with good YAML configfile') |
40 | or diag $@; |
41 | |
42 | is($foo->req_attr, 'foo', 'req_attr works'); |
43 | is($foo->direct_attr, 123, 'direct_attr works'); |
44 | is($foo->inherited_ro_attr, 'asdf', 'inherited_ro_attr works'); |
45 | } |
46 | |
5b519d9c |
47 | done_testing; |
48 | |
a96520dd |
49 | END { unlink('test.yaml') } |