Login
Added PHILOSOPHY section to documentation. Thanks Chris.
[gknop/Perl-Critic.git] / t / 20_policies_classhierarchies.t
CommitLineData
bf159007 1##################################################################
fc1186f9
CD
2# $URL$
3# $Date$
bf159007
JRT
4# $Author$
5# $Revision$
6##################################################################
7
8use strict;
9use warnings;
fc1186f9 10use Test::More tests => 4;
bf159007
JRT
11use Perl::Critic::Config;
12use Perl::Critic;
13
14# common P::C testing tools
15use lib qw(t/tlib);
16use PerlCriticTestUtils qw(pcritique);
17PerlCriticTestUtils::block_perlcriticrc();
18
19my $code ;
20my $policy;
21my %config;
22
23#-----------------------------------------------------------------------------
24
25$code = <<'END_PERL';
26my $self = bless {};
27my $self = bless [];
28
29#Critic doesn't catch these,
30#cuz they parse funny
31#my $self = bless( {} );
32#my $self = bless( [] );
33
34END_PERL
35
36$policy = 'ClassHierarchies::ProhibitOneArgBless';
37is( pcritique($policy, \$code), 2, $policy );
38
39#-----------------------------------------------------------------------------
40
41$code = <<'END_PERL';
42my $self = bless {}, 'foo';
43my $self = bless( {}, 'foo' );
44my $self = bless [], 'foo';
45my $self = bless( [], 'foo' );
46END_PERL
47
48$policy = 'ClassHierarchies::ProhibitOneArgBless';
49is( pcritique($policy, \$code), 0, $policy );
fc1186f9
CD
50
51#-----------------------------------------------------------------------------
52
53$code = <<'END_PERL';
54our @ISA = qw(Foo);
55push @ISA, 'Foo';
56@ISA = ('Foo');
57END_PERL
58
59$policy = 'ClassHierarchies::ProhibitExplicitISA';
60is( pcritique($policy, \$code), 3, $policy );
61#-----------------------------------------------------------------------------
62
63$code = <<'END_PERL';
64print @Foo::ISA;
65use base 'Foo';
66END_PERL
67
68$policy = 'ClassHierarchies::ProhibitExplicitISA';
69is( pcritique($policy, \$code), 0, $policy );