Login
Merge changes to ProfilePrototype to take advantage the parameters
[gknop/Perl-Critic.git] / t / 16_roundtrip_defaults.t
CommitLineData
aa03ef60
ES
1#!perl
2
3##############################################################################
4# $URL$
5# $Date$
6# $Author$
7# $Revision$
8##############################################################################
9
10use strict;
11use warnings;
12
13use English qw(-no_match_vars);
14
15use Test::More;
16
17use Perl::Critic::PolicyFactory (-test => 1);
18use Perl::Critic::Config;
19use Perl::Critic::ProfilePrototype;
20use Perl::Critic::Utils qw{ :characters :severities };
21
22#-----------------------------------------------------------------------------
23
24plan skip_all =>
25 q<This test won't work until the core Policies have been converted to use parameter objects.>;
26
27eval 'use Test::Deep'; ## no critic (
28plan( skip_all => 'Test::Deep requried to test round-trip of default values')
29 if $EVAL_ERROR;
30
31#-----------------------------------------------------------------------------
32
33my $default_configuration =
34 Perl::Critic::Config->new(
35 -profile => $EMPTY,
36 -severity => 1,
37 );
38my @default_policies = $default_configuration->policies();
39
40my $policy_test_count;
41
42$policy_test_count = 3 * @default_policies;
43foreach my $policy (@default_policies) {
44 if (
45 $policy->parameter_metadata_available()
46 and not $policy->isa('Perl::Critic::Policy::CodeLayout::RequireTidyCode')
47 ) {
48 $policy_test_count += scalar @{$policy->get_parameters()};
49 }
50}
51my $test_count = 12 + $policy_test_count;
52plan tests => $test_count;
53
54#-----------------------------------------------------------------------------
55
56my $profile_generator =
57 Perl::Critic::ProfilePrototype->new(
58 -policies => \@default_policies,
59 '-comment-out-parameters' => 0,
60 -config => $default_configuration,
61 );
62my $profile = $profile_generator->to_string();
63
64my $derived_configuration =
65 Perl::Critic::Config->new( -profile => \$profile );
66
67#-----------------------------------------------------------------------------
68
69my @derived_include = $derived_configuration->include();
70my @default_include = $default_configuration->include();
71cmp_deeply(
72 \@derived_include,
73 \@default_include,
74 'include',
75);
76
77#-----------------------------------------------------------------------------
78
79my @derived_exclude = $derived_configuration->exclude();
80my @default_exclude = $default_configuration->exclude();
81cmp_deeply(
82 \@derived_exclude,
83 \@default_exclude,
84 'exclude',
85);
86
87#-----------------------------------------------------------------------------
88
89my @derived_single_policy = $derived_configuration->single_policy();
90my @default_single_policy = $default_configuration->single_policy();
91cmp_deeply(
92 \@derived_single_policy,
93 \@default_single_policy,
94 'single_policy',
95);
96
97#-----------------------------------------------------------------------------
98
99is(
100 $derived_configuration->force(),
101 $default_configuration->force(),
102 'force',
103);
104
105#-----------------------------------------------------------------------------
106
107is(
108 $derived_configuration->only(),
109 $default_configuration->only(),
110 'only',
111);
112
113#-----------------------------------------------------------------------------
114
115is(
116 $derived_configuration->profile_strictness(),
117 $default_configuration->profile_strictness(),
118 'force',
119);
120
121#-----------------------------------------------------------------------------
122
123is(
124 $derived_configuration->color(),
125 $default_configuration->color(),
126 'color',
127);
128
129#-----------------------------------------------------------------------------
130
131cmp_ok(
132 $derived_configuration->severity(),
133 '==',
134 $default_configuration->severity(),
135 'severity',
136);
137
138#-----------------------------------------------------------------------------
139
140cmp_ok(
141 $derived_configuration->top(),
142 '==',
143 $default_configuration->top(),
144 'top',
145);
146
147#-----------------------------------------------------------------------------
148
149cmp_ok(
150 $derived_configuration->verbose(),
151 '==',
152 $default_configuration->verbose(),
153 'verbose',
154);
155
156#-----------------------------------------------------------------------------
157
158cmp_deeply(
159 $derived_configuration->theme(),
160 $default_configuration->theme(),
161 'theme',
162);
163
164#-----------------------------------------------------------------------------
165
166my @derived_policies = $derived_configuration->policies();
167
168my $policy_counts_match =
169 is(
170 scalar @derived_policies,
171 scalar @default_policies,
172 'same policy count'
173 );
174
175SKIP: {
176 skip
177 q{because there weren't the same number of policies},
178 $policy_test_count
179 if not $policy_counts_match;
180
181 for (my $x = 0; $x < @default_policies; $x++) {
182 my $derived_policy = $derived_policies[$x];
183 my $default_policy = $default_policies[$x];
184
185 is(
186 $derived_policy->get_short_name(),
187 $default_policy->get_short_name(),
188 'policy names match',
189 );
190 is(
191 $derived_policy->get_severity(),
192 $default_policy->get_severity(),
193 $default_policy->get_short_name() . ' severities match',
194 );
195 is(
196 $derived_policy->get_themes(),
197 $default_policy->get_themes(),
198 $default_policy->get_short_name() . ' themes match',
199 );
200
201 if (
202 $default_policy->parameter_metadata_available()
203 and not $default_policy->isa('Perl::Critic::Policy::CodeLayout::RequireTidyCode')
204 ) {
205 # Encapsulation violation alert!
206 foreach my $parameter ( @{$default_policy->get_parameters()} ) {
207 my $parameter_name =
208 $default_policy->__get_parameter_name( $parameter );
209
210 cmp_deeply(
211 $derived_policy->{$parameter_name},
212 $default_policy->{$parameter_name},
213 $default_policy->get_short_name()
214 . $SPACE
215 . $parameter_name
216 . ' match',
217 );
218 }
219 }
220 }
221}
222
223
224#-----------------------------------------------------------------------------
225# Local Variables:
226# mode: cperl
227# cperl-indent-level: 4
228# fill-column: 78
229# indent-tabs-mode: nil
230# c-indentation-style: bsd
231# End:
232# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab :