new dist: MooseX::SimpleConfig
[gitmo/MooseX-SimpleConfig.git] / t / 10simple.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 6;
7
8 use lib 't/lib';
9 use lib '../t/lib';
10
11 BEGIN {
12     use_ok('MXSimpleConfigTest');
13 }
14
15 # Does it work with no configfile and not barf?
16 {
17     eval { MXSimpleConfigTest->new(req_attr => 'foo') };
18     ok(!$@, 'Did not die with no configfile specified')
19         or diag $@;
20 }
21
22 # Can it load a simple YAML file with the options
23 {
24     open(my $test_yaml, '>', 'test.yaml')
25       or die "Cannot create test.yaml: $!";
26     print $test_yaml "direct_attr: 123\ninherited_ro_attr: asdf\nreq_attr: foo\n";
27     close($test_yaml);
28
29     my $foo = eval {
30         MXSimpleConfigTest->new_with_config(configfile => 'test.yaml');
31     };
32     ok(!$@, 'Did not die with good YAML configfile')
33         or diag $@;
34
35     is($foo->req_attr, 'foo', 'req_attr works');
36     is($foo->direct_attr, 123, 'direct_attr works');
37     is($foo->inherited_ro_attr, 'asdf', 'inherited_ro_attr works');
38 }
39
40 END { unlink('test.yaml') }