Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / t / 20_policy_requiretidycode.t
1 #!perl
2
3 ##############################################################################
4 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/t/20_policy_requiretidycode.t $
5 #     $Date: 2008-06-21 19:57:54 -0700 (Sat, 21 Jun 2008) $
6 #   $Author: clonezone $
7 # $Revision: 2464 $
8 ##############################################################################
9
10 use 5.006001;
11 use strict;
12 use warnings;
13
14 use Test::More tests => 6;
15
16 # common P::C testing tools
17 use Perl::Critic::TestUtils qw(pcritique);
18 Perl::Critic::TestUtils::block_perlcriticrc();
19
20 my $code;
21 my $policy = 'CodeLayout::RequireTidyCode';
22 my %config;
23
24 #-----------------------------------------------------------------------------
25
26 $code = <<'END_PERL';
27 $foo= 42;
28 $bar   =56;
29 $baz   =   67;
30 END_PERL
31
32 my $has_perltidy = eval {require Perl::Tidy};
33 %config = (perltidyrc => q{});
34 is(
35     eval { pcritique($policy, \$code, \%config) },
36     $has_perltidy ? 1 : undef,
37     'Untidy code',
38 );
39
40 #-----------------------------------------------------------------------------
41
42 $code = <<'END_PERL';
43 #Only one trailing newline
44 $foo = 42;
45 $bar = 56;
46 END_PERL
47
48 %config = (perltidyrc => q{});
49 is(
50     eval { pcritique($policy, \$code, \%config) },
51     $has_perltidy ? 0 : undef,
52     'Tidy with one trailing newline',
53 );
54
55 #-----------------------------------------------------------------------------
56
57 $code = <<'END_PERL';
58 #Two trailing newlines
59 $foo = 42;
60 $bar = 56;
61
62 END_PERL
63
64 %config = (perltidyrc => q{});
65 is(
66     eval { pcritique($policy, \$code, \%config) },
67     $has_perltidy ? 0 : undef,
68     'Tidy with two trailing newlines',
69 );
70
71 #-----------------------------------------------------------------------------
72
73 $code = <<'END_PERL';
74 #Several trailing newlines
75 $foo = 42;
76 $bar = 56;
77
78    
79
80
81     
82   
83 END_PERL
84
85
86
87 %config = (perltidyrc => q{});
88 is(
89     eval { pcritique($policy, \$code, \%config) },
90     $has_perltidy ? 0 : undef,
91     'Tidy with several trailing newlines',
92 );
93
94 #-----------------------------------------------------------------------------
95
96 $code = <<'END_PERL';
97 sub foo {
98     my $code = <<'TEST';
99  foo bar baz
100 TEST
101     $code;
102 }  
103 END_PERL
104
105 %config = (perltidyrc => q{});
106 is(
107     eval { pcritique($policy, \$code, \%config) },
108     $has_perltidy ? 0 : undef,
109     'Tidy with heredoc',
110 );
111
112 #-----------------------------------------------------------------------------
113
114 $code = <<'END_PERL';
115 #!perl
116
117 eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
118         if 0; # not running under some shell
119
120 package main;
121 END_PERL
122
123 %config = (perltidyrc => q{});
124 is(
125     eval { pcritique($policy, \$code, \%config) },
126     $has_perltidy ? 0 : undef,
127     'Tidy with shell escape',
128 );
129
130 #-----------------------------------------------------------------------------
131
132 # ensure we run true if this test is loaded by
133 # t/20_policy_requiretidycode.t_without_optional_dependencies.t
134 1;
135
136 # Local Variables:
137 #   mode: cperl
138 #   cperl-indent-level: 4
139 #   fill-column: 78
140 #   indent-tabs-mode: nil
141 #   c-indentation-style: bsd
142 # End:
143 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :