Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / t / 01_policy_config.t
1 #!perl
2
3 ##############################################################################
4 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/t/01_policy_config.t $
5 #     $Date: 2008-06-06 00:48:04 -0500 (Fri, 06 Jun 2008) $
6 #   $Author: clonezone $
7 # $Revision: 2416 $
8 ##############################################################################
9
10 use 5.006001;
11 use strict;
12 use warnings;
13
14 use Carp qw< confess >;
15
16 use Test::More tests => 29;
17
18 #-----------------------------------------------------------------------------
19
20 BEGIN {
21     use_ok('Perl::Critic::PolicyConfig') or confess 'No point in continuing.';
22 }
23
24
25 {
26     my $config =
27         Perl::Critic::PolicyConfig->new('Some::Policy');
28
29     is(
30         $config->get_policy_short_name(),
31         'Some::Policy',
32         'Policy short name gets saved.',
33     );
34     is(
35         $config->get_set_themes(),
36         undef,
37         'set_themes is undef when not specified.',
38     );
39     is(
40         $config->get_add_themes(),
41         undef,
42         'add_themes is undef when not specified.',
43     );
44     is(
45         $config->get_severity(),
46         undef,
47         'severity is undef when not specified.',
48     );
49     is(
50         $config->get_maximum_violations_per_document(),
51         undef,
52         'maximum_violations_per_document is undef when not specified.',
53     );
54     ok(
55         $config->is_empty(),
56         'is_empty() is true when there were no configuration values.',
57     );
58
59     my @parameter_names = $config->get_parameter_names();
60     is(
61         scalar @parameter_names,
62         0,
63         'There are no parameter names left.',
64     );
65
66     test_standard_parameters_undef_via_get($config);
67 }
68
69 {
70     my $config =
71         Perl::Critic::PolicyConfig->new(
72             'Some::Other::Policy',
73             {
74                 custom_parameter   => 'blargh',
75
76                 # Standard parameters
77                 set_themes                      => 'thingy',
78                 add_themes                      => 'another thingy',
79                 severity                        => 'harsh',
80                 maximum_violations_per_document => '2',
81             }
82         );
83
84     is(
85         $config->get_policy_short_name(),
86         'Some::Other::Policy',
87         'Policy short name gets saved.',
88     );
89     is(
90         $config->get_set_themes(),
91         'thingy',
92         'set_themes gets saved.',
93     );
94     is(
95         $config->get_add_themes(),
96         'another thingy',
97         'add_themes gets saved.',
98     );
99     is(
100         $config->get_severity(),
101         'harsh',
102         'severity gets saved.',
103     );
104     is(
105         $config->get_maximum_violations_per_document(),
106         '2',
107         'maximum_violations_per_document gets saved.',
108     );
109     is(
110         $config->get('custom_parameter'),
111         'blargh',
112         'custom_parameter gets saved.',
113     );
114     ok(
115         ! $config->is_empty(),
116         'is_empty() is false when there were configuration values.',
117     );
118
119     my @parameter_names = $config->get_parameter_names();
120     is(
121         scalar @parameter_names,
122         1,
123         'There is one parameter name left after construction.',
124     );
125     is(
126         $parameter_names[0],
127         'custom_parameter',
128         'There parameter name is the expected value.',
129     );
130
131     test_standard_parameters_undef_via_get($config);
132
133     $config->remove('custom_parameter');
134     ok(
135         $config->is_empty(),
136         'is_empty() is true after removing "custom_parameter".',
137     );
138
139     @parameter_names = $config->get_parameter_names();
140     is(
141         scalar @parameter_names,
142         0,
143         'There are no parameter names left after removing "custom_parameter".',
144     );
145 }
146
147
148 sub test_standard_parameters_undef_via_get {
149     my ($config) = @_;
150     my $policy_short_name = $config->get_policy_short_name();
151
152     foreach my $parameter (
153         qw<
154             set_themes
155             add_themes
156             severity
157             maximum_violations_per_document
158             _non_public_data
159         >
160     ) {
161         is(
162             $config->get($parameter),
163             undef,
164             qq<"$parameter" is not defined via get() for $policy_short_name.>,
165         )
166     }
167
168     return;
169 }
170
171 #-----------------------------------------------------------------------------
172
173 # ensure we run true if this test is loaded by
174 # t/01_policy_config.t_without_optional_dependencies.t
175 1;
176
177 # Local Variables:
178 #   mode: cperl
179 #   cperl-indent-level: 4
180 #   fill-column: 78
181 #   indent-tabs-mode: nil
182 #   c-indentation-style: bsd
183 # End:
184 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :