make all warnings fatal in tests
[gitmo/MooseX-ConfigFromFile.git] / t / 05_default_sub.t
CommitLineData
7acf2fe9 1use strict;
bd567467 2use warnings FATAL => 'all';
7acf2fe9 3
0864e862 4use Test::Requires 'MooseX::SimpleConfig'; # skip all if not reuqired
7acf2fe9 5use Test::More tests => 10;
6use Test::Fatal;
7use Test::Deep '!blessed';
8use Test::NoWarnings 1.04 ':early';
9use Scalar::Util 'blessed';
10
11my %loaded_file;
12my %default_sub;
13
14
15# nothing special going on here
16{
17 package Generic;
18 use Moose;
19 with 'MooseX::SimpleConfig';
20 sub get_config_from_file { }
21}
22
23is(
24 exception {
25 my $obj = Generic->new_with_config;
26 is($obj->configfile, undef, 'no configfile set');
27 },
28 undef,
29 'no exceptions',
30);
31
32
33# this is a classic legacy usecase from old documentation that we must
34# continue to support
35{
36 package OverriddenDefault;
37 use Moose;
38 with 'MooseX::SimpleConfig';
39 sub get_config_from_file
40 {
41 my ($class, $file) = @_;
42 $loaded_file{$file}++;
43 +{}
44 }
45 has '+configfile' => (
46 default => 'OverriddenDefault file',
47 );
48}
49
50is(
51 exception {
52 my $obj = OverriddenDefault->new_with_config;
53 is($obj->configfile, blessed($obj) . ' file', 'configfile set via overridden default');
54 is($loaded_file{blessed($obj) . ' file'}, 1, 'correct file was loaded from');
55 },
56 undef,
57 'no exceptions',
58);
59
60
61# "reader" method is overridden to provide for configfile default
62{
63 package OverriddenMethod;
64 use Moose;
65 with 'MooseX::SimpleConfig';
66 sub get_config_from_file {
67 my ($class, $file) = @_;
68 $loaded_file{$file}++;
69 +{}
70 }
71
72 around configfile => sub {
73 my $class = blessed($_[1]) || $_[1];
74 $default_sub{$class}++;
75 $class . ' file'
76 };
77}
78
79is(
80 exception {
81 my $obj = OverriddenMethod->new_with_config;
82 is($obj->configfile, blessed($obj) . ' file', 'configfile set via overridden sub');
83 ok($default_sub{blessed($obj)}, 'default sub was called');
84 is($loaded_file{blessed($obj) . ' file'}, 1, 'correct file was loaded from');
85 },
86 undef,
87 'no exceptions',
88);
89
90