1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
#!perl
##############################################################################
# $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/t/07_perlcritic.t $
# $Date: 2008-06-06 00:48:04 -0500 (Fri, 06 Jun 2008) $
# $Author: clonezone $
# $Revision: 2416 $
##############################################################################
use 5.006001;
use strict;
use warnings;
use File::Spec;
use English qw(-no_match_vars);
use Test::More tests => 36;
#-----------------------------------------------------------------------------
# Load perlcritic like a library so we can test its subroutines. If it is not
# found in blib, then use the one in bin (for example, when using 'prove')
my $perlcritic = File::Spec->catfile( qw(blib script perlcritic) );
$perlcritic = File::Spec->catfile( qw(bin perlcritic) ) if ! -e $perlcritic;
require $perlcritic; ## no critic
# Because bin/perlcritic does not declare a package, it has functions
# in main, just like this test file, so we can use its functions
# without a prefix.
#-----------------------------------------------------------------------------
local @ARGV = ();
my %options = ();
#-----------------------------------------------------------------------------
@ARGV = qw(-1 -2 -3 -4 -5);
%options = get_options();
is( $options{-severity}, 1);
@ARGV = qw(-5 -3 -4 -1 -2);
%options = get_options();
is( $options{-severity}, 1);
@ARGV = qw();
%options = get_options();
is( $options{-severity}, undef);
@ARGV = qw(-2 -3 -severity 4);
%options = get_options();
is( $options{-severity}, 4);
@ARGV = qw(-severity 2 -3 -4);
%options = get_options();
is( $options{-severity}, 2);
@ARGV = qw(--severity=2 -3 -4);
%options = get_options();
is( $options{-severity}, 2);
@ARGV = qw(-cruel);
%options = get_options();
is( $options{-severity}, 'cruel');
@ARGV = qw(-cruel --severity=1);
%options = get_options();
is( $options{-severity}, 1);
@ARGV = qw(-stern --severity=1 -2);
%options = get_options();
is( $options{-severity}, 1);
@ARGV = qw(-stern -severity 1 -2);
%options = get_options();
is( $options{-severity}, 1);
#-----------------------------------------------------------------------------
@ARGV = qw(-top);
%options = get_options();
is( $options{-severity}, 1);
is( $options{-top}, 20);
@ARGV = qw(-top 10);
%options = get_options();
is( $options{-severity}, 1);
is( $options{-top}, 10);
@ARGV = qw(-severity 4 -top);
%options = get_options();
is( $options{-severity}, 4);
is( $options{-top}, 20);
@ARGV = qw(-severity 4 -top 10);
%options = get_options();
is( $options{-severity}, 4);
is( $options{-top}, 10);
@ARGV = qw(-severity 5 -2 -top 5);
%options = get_options();
is( $options{-severity}, 5);
is( $options{-top}, 5);
#-----------------------------------------------------------------------------
@ARGV = qw(-noprofile);
%options = get_options();
is( $options{-profile}, q{});
@ARGV = qw(-profile foo);
%options = get_options();
is( $options{-profile}, 'foo');
#-----------------------------------------------------------------------------
@ARGV = qw(-single-policy nowarnings);
%options = get_options();
is( $options{'-single-policy'}, 'nowarnings');
#-----------------------------------------------------------------------------
@ARGV = qw(-verbose 2);
%options = get_options();
is( $options{-verbose}, 2);
@ARGV = qw(-verbose %l:%c:%m);
%options = get_options();
is( $options{-verbose}, '%l:%c:%m');
#-----------------------------------------------------------------------------
@ARGV = qw(-statistics);
%options = get_options();
is( $options{-statistics}, 1);
#-----------------------------------------------------------------------------
@ARGV = qw(-statistics-only);
%options = get_options();
is( $options{'-statistics-only'}, 1);
#-----------------------------------------------------------------------------
@ARGV = qw(-quiet);
%options = get_options();
is( $options{-quiet}, 1);
#-----------------------------------------------------------------------------
# Intercept pod2usage so we can test invalid options and special switches
{
no warnings qw(redefine once);
local *main::pod2usage = sub { my %args = @_; die $args{-message} || q{} };
eval { @ARGV = qw( -help ); get_options() };
ok( $EVAL_ERROR, '-help option' );
eval { @ARGV = qw( -options ); get_options() };
ok( $EVAL_ERROR, '-options option' );
eval { @ARGV = qw( -man ); get_options() };
ok( $EVAL_ERROR, '-man option' );
eval { @ARGV = qw( -noprofile -profile foo ); get_options() };
like( $EVAL_ERROR, qr/-noprofile with -profile/, '-noprofile with -profile');
eval { @ARGV = qw( -verbose bogus ); get_options() };
like( $EVAL_ERROR, qr/looks odd/, 'Invalid -verbose option' );
eval { @ARGV = qw( -top -9 ); get_options() };
like( $EVAL_ERROR, qr/is negative/, 'Negative -verbose option' );
eval { @ARGV = qw( -severity 0 ); get_options() };
like( $EVAL_ERROR, qr/out of range/, '-severity too small' );
eval { @ARGV = qw( -severity 6 ); get_options() };
like( $EVAL_ERROR, qr/out of range/, '-severity too large' );
}
#-----------------------------------------------------------------------------
# ensure we run true if this test is loaded by
# t/07_perlcritic.t_without_optional_dependencies.t
1;
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 78
# indent-tabs-mode: nil
# c-indentation-style: bsd
# End:
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
|