Commit | Line | Data |
33defd43 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
33defd43 |
6 | use lib 't/lib'; |
7 | use lib '../t/lib'; |
8 | |
9 | BEGIN { |
a61b087b |
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 => 6; |
21 | |
33defd43 |
22 | use_ok('MXSimpleConfigTest'); |
23 | } |
24 | |
25 | # Does it work with no configfile and not barf? |
26 | { |
27 | eval { MXSimpleConfigTest->new(req_attr => 'foo') }; |
28 | ok(!$@, 'Did not die with no configfile specified') |
29 | or diag $@; |
30 | } |
31 | |
32 | # Can it load a simple YAML file with the options |
33 | { |
34 | open(my $test_yaml, '>', 'test.yaml') |
35 | or die "Cannot create test.yaml: $!"; |
36 | print $test_yaml "direct_attr: 123\ninherited_ro_attr: asdf\nreq_attr: foo\n"; |
37 | close($test_yaml); |
38 | |
39 | my $foo = eval { |
40 | MXSimpleConfigTest->new_with_config(configfile => 'test.yaml'); |
41 | }; |
42 | ok(!$@, 'Did not die with good YAML configfile') |
43 | or diag $@; |
44 | |
45 | is($foo->req_attr, 'foo', 'req_attr works'); |
46 | is($foo->direct_attr, 123, 'direct_attr works'); |
47 | is($foo->inherited_ro_attr, 'asdf', 'inherited_ro_attr works'); |
48 | } |
49 | |
50 | END { unlink('test.yaml') } |