Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / t / 02_policy.t
1 #!perl
2
3 ##############################################################################
4 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/t/02_policy.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 English qw<-no_match_vars>;
15
16 use Test::More tests => 26;
17
18
19 #-----------------------------------------------------------------------------
20 # Perl::Critic::Policy is an abstract class, so it can't be instantiated
21 # directly.  So we test it by declaring test classes that inherit from it.
22
23 package PolicyTest;
24 use base 'Perl::Critic::Policy';
25
26 package PolicyTestOverriddenDefaultMaximumViolations;
27 use base 'Perl::Critic::Policy';
28
29 sub default_maximum_violations_per_document { return 31; }
30
31 #-----------------------------------------------------------------------------
32
33 package main;
34
35 my $p = PolicyTest->new();
36 isa_ok($p, 'PolicyTest');
37
38
39 eval { $p->violates(); };
40 ok($EVAL_ERROR, 'abstract violates() throws exception');
41
42
43 # Test default application...
44 is($p->applies_to(), 'PPI::Element', 'applies_to()');
45
46
47 # Test default maximum violations per document...
48 is(
49     $p->default_maximum_violations_per_document(),
50     undef,
51     'default_maximum_violations_per_document()',
52 );
53 is(
54     $p->get_maximum_violations_per_document(),
55     undef,
56     'get_maximum_violations_per_document()',
57 );
58
59 # Change maximum violations level...
60 $p->set_maximum_violations_per_document(3);
61
62 # Test maximum violations again...
63 is(
64     $p->default_maximum_violations_per_document(),
65     undef,
66     q<default_maximum_violations_per_document() hasn't changed>,
67 );
68 is(
69     $p->get_maximum_violations_per_document(),
70     3,
71     q<get_maximum_violations_per_document() returns new value>,
72 );
73
74
75 my $overridden_default = PolicyTestOverriddenDefaultMaximumViolations->new();
76 isa_ok($overridden_default, 'PolicyTestOverriddenDefaultMaximumViolations');
77
78 # Test default maximum violations per document...
79 is(
80     $overridden_default->default_maximum_violations_per_document(),
81     31,
82     'default_maximum_violations_per_document() overridden',
83 );
84 is(
85     $overridden_default->get_maximum_violations_per_document(),
86     31,
87     'get_maximum_violations_per_document() overridden',
88 );
89
90 # Change maximum violations level...
91 $overridden_default->set_maximum_violations_per_document(undef);
92
93 # Test maximum violations again...
94 is(
95     $overridden_default->default_maximum_violations_per_document(),
96     31,
97     q<default_maximum_violations_per_document() overridden hasn't changed>,
98 );
99 is(
100     $overridden_default->get_maximum_violations_per_document(),
101     undef,
102     q<get_maximum_violations_per_document() overridden returns new undefined value>,
103 );
104
105
106 # Test default severity...
107 is( $p->default_severity(), 1, 'default_severity()');
108 is( $p->get_severity(), 1, 'get_severity()' );
109
110 # Change severity level...
111 $p->set_severity(3);
112
113 # Test severity again...
114 is( $p->default_severity(), 1 ); #Still the same
115 is( $p->get_severity(), 3 );     #Should have new value
116
117
118 # Test default theme...
119 is_deeply( [$p->default_themes()], [], 'default_themes()');
120 is_deeply( [$p->get_themes()], [], 'get_themes()');
121
122 # Change theme
123 $p->set_themes( qw(c b a) ); #unsorted
124
125 # Test theme again...
126 is_deeply( [$p->default_themes()], [] ); #Still the same
127 is_deeply( [$p->get_themes()], [qw(a b c)] );  #Should have new value, sorted
128
129 # Append theme
130 $p->add_themes( qw(f e d) ); #unsorted
131
132 # Test theme again...
133 is_deeply( [$p->default_themes()], [] ); #Still the same
134 is_deeply( [$p->get_themes()], [ qw(a b c d e f) ] );  #Should have new value, sorted
135
136
137 # Test format getter/setters
138 is( Perl::Critic::Policy::get_format, "%p\n", 'Default policy format');
139
140 my $new_format = '%p %s [%t]';
141 Perl::Critic::Policy::set_format( $new_format ); #Set format
142 is( Perl::Critic::Policy::get_format, $new_format, 'Changed policy format');
143
144 my $expected_string = 'PolicyTest 3 [a b c d e f]';
145 is( $p->to_string(), $expected_string, 'Stringification by to_string()');
146 is( "$p", $expected_string, 'Stringification by overloading');
147
148
149 #-----------------------------------------------------------------------------
150
151 # ensure we run true if this test is loaded by
152 # t/02_policy.t_without_optional_dependencies.t
153 1;
154
155
156 ##############################################################################
157 # Local Variables:
158 #   mode: cperl
159 #   cperl-indent-level: 4
160 #   fill-column: 78
161 #   indent-tabs-mode: nil
162 #   c-indentation-style: bsd
163 # End:
164 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :