Login
Added test for legit-but-falsely-identified-as-bad form of bless, with a fat comma
[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;
e2ec15ae 10use Test::More tests => 7;
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' );
a0bad2d7 46my $self = bless {} => 'foo';
bf159007
JRT
47END_PERL
48
49$policy = 'ClassHierarchies::ProhibitOneArgBless';
50is( pcritique($policy, \$code), 0, $policy );
fc1186f9
CD
51
52#-----------------------------------------------------------------------------
53
54$code = <<'END_PERL';
55our @ISA = qw(Foo);
56push @ISA, 'Foo';
57@ISA = ('Foo');
58END_PERL
59
60$policy = 'ClassHierarchies::ProhibitExplicitISA';
61is( pcritique($policy, \$code), 3, $policy );
e2ec15ae 62
fc1186f9
CD
63#-----------------------------------------------------------------------------
64
65$code = <<'END_PERL';
66print @Foo::ISA;
67use base 'Foo';
68END_PERL
69
70$policy = 'ClassHierarchies::ProhibitExplicitISA';
71is( pcritique($policy, \$code), 0, $policy );
e2ec15ae
JRT
72
73#-----------------------------------------------------------------------------
74
75$code = <<'END_PERL';
76sub AUTOLOAD {}
77END_PERL
78
79$policy = 'ClassHierarchies::ProhibitAutoloading';
80is( pcritique($policy, \$code), 1, $policy );
81
82#-----------------------------------------------------------------------------
83
84$code = <<'END_PERL';
85sub AUTOLOAD {
86 $foo, $bar = @_;
87 return $baz;
88}
89END_PERL
90
91$policy = 'ClassHierarchies::ProhibitAutoloading';
92is( pcritique($policy, \$code), 1, $policy );
93
94#-----------------------------------------------------------------------------
95
96$code = <<'END_PERL';
97sub autoload {}
98my $AUTOLOAD = 'foo';
99our @AUTOLOAD = qw(nuts);
100END_PERL
101
102$policy = 'ClassHierarchies::ProhibitAutoloading';
103is( pcritique($policy, \$code), 0, $policy );