File: 11default.t

package info (click to toggle)
libmoosex-simpleconfig-perl 0.09-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 236 kB
  • sloc: perl: 2,148; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,166 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl

use strict;
use warnings;

use lib 't/lib';
use lib '../t/lib';
use Test::More;
our @classes;
BEGIN {

    @classes = qw/ MXDefaultConfigTest MXDefaultMultipleConfigsTest /;

    eval "use YAML::XS()";
    if($@) {
        eval "use YAML::Syck ()";
        if($@) {
            eval "use YAML ()";
            if($@) {
                plan skip_all => "YAML::XS or YAML or YAML::Syck required for this test";
            }
        }
    }

    use_ok($_) for @classes;
}

# Can it load a simple YAML file with the options
#  based on a default in the configfile attr
{
    open(my $test_yaml, '>', 'test.yaml')
      or die "Cannot create test.yaml: $!";
    print $test_yaml "direct_attr: 123\ninherited_ro_attr: asdf\nreq_attr: foo\n";
    close($test_yaml);

}

foreach my $class (@classes) {
    my $foo = eval {
        $class->new_with_config();
    };
    ok(!$@, 'Did not die with good YAML configfile')
        or diag $@;

    is($foo->req_attr, 'foo', 'req_attr works');
    is($foo->direct_attr, 123, 'direct_attr works');
    is($foo->inherited_ro_attr, 'asdf', 'inherited_ro_attr works');
}

done_testing;

END { unlink('test.yaml') }