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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
#!perl
use 5.010001;
use strict;
use warnings;
use English qw(-no_match_vars);
use Perl::Critic::OptionsProcessor;
use Perl::Critic::Utils qw< :booleans >;
use Perl::Critic::Utils::Constants qw< :color_severity >;
use Test::More tests => 54;
our $VERSION = '1.156';
use Perl::Critic::TestUtils;
Perl::Critic::TestUtils::assert_version( $VERSION );
{
# Can't use IO::Interactive here because we /don't/ want to check STDIN.
my $color = -t *STDOUT ? $TRUE : $FALSE; ## no critic (ProhibitInteractiveTest)
my $processor = Perl::Critic::OptionsProcessor->new();
is($processor->force(), 0, 'native default force');
is($processor->only(), 0, 'native default only');
is($processor->severity(), 5, 'native default severity');
is($processor->theme(), q{}, 'native default theme');
is($processor->top(), 0, 'native default top');
is($processor->color(), $color, 'native default color');
is($processor->pager(), q{}, 'native default pager');
is($processor->verbose(), 4, 'native default verbose');
is($processor->criticism_fatal, 0, 'native default criticism-fatal');
is_deeply($processor->include(), [], 'native default include');
is_deeply($processor->exclude(), [], 'native default exclude');
is($processor->color_severity_highest(),
$PROFILE_COLOR_SEVERITY_HIGHEST_DEFAULT,
'native default color-severity-highest');
is($processor->color_severity_high(),
$PROFILE_COLOR_SEVERITY_HIGH_DEFAULT,
'native default color-severity-high');
is($processor->color_severity_medium(),
$PROFILE_COLOR_SEVERITY_MEDIUM_DEFAULT,
'native default color-severity-medium');
is($processor->color_severity_low(),
$PROFILE_COLOR_SEVERITY_LOW_DEFAULT,
'native default color-severity-low');
is($processor->color_severity_lowest(),
$PROFILE_COLOR_SEVERITY_LOWEST_DEFAULT,
'native default color-severity-lowest');
is_deeply($processor->program_extensions(), [],
'native default program extensions');
}
#-----------------------------------------------------------------------------
{
my %user_defaults = (
force => 1,
only => 1,
severity => 4,
theme => 'pbp',
top => 50,
color => $FALSE,
pager => 'less',
verbose => 7,
'criticism-fatal' => 1,
include => 'foo bar',
exclude => 'baz nuts',
'color-severity-highest' => 'chartreuse',
'color-severity-high' => 'fuschia',
'color-severity-medium' => 'blue',
'color-severity-low' => 'gray',
'color-severity-lowest' => 'scots tartan',
'program-extensions' => '.PL .pl .t',
);
my $processor = Perl::Critic::OptionsProcessor->new( %user_defaults );
is($processor->force(), 1, 'user default force');
is($processor->only(), 1, 'user default only');
is($processor->severity(), 4, 'user default severity');
is($processor->theme(), 'pbp', 'user default theme');
is($processor->top(), 50, 'user default top');
is($processor->color(), $FALSE, 'user default color');
is($processor->pager(), 'less', 'user default pager');
is($processor->verbose(), 7, 'user default verbose');
is($processor->criticism_fatal(), 1, 'user default criticism_fatal');
is_deeply($processor->include(), [ qw(foo bar) ], 'user default include');
is_deeply($processor->exclude(), [ qw(baz nuts)], 'user default exclude');
is($processor->color_severity_highest(),
'chartreuse', 'user default color_severity_highest');
is($processor->color_severity_high(),
'fuschia', 'user default color_severity_high');
is($processor->color_severity_medium(),
'blue', 'user default color_severity_medium');
is($processor->color_severity_low(),
'gray', 'user default color_severity_low');
is($processor->color_severity_lowest(),
'scots tartan', 'user default color_severity_lowest');
is_deeply($processor->program_extensions(), [ qw(.PL .pl .t) ],
'user default program-extensions');
}
#-----------------------------------------------------------------------------
{
my $processor = Perl::Critic::OptionsProcessor->new( 'colour' => 1 );
is($processor->color(), $TRUE, 'user default colour true');
$processor = Perl::Critic::OptionsProcessor->new( 'colour' => 0 );
is($processor->color(), $FALSE, 'user default colour false');
$processor = Perl::Critic::OptionsProcessor->new(
'colour-severity-highest' => 'chartreuse',
'colour-severity-high' => 'fuschia',
'colour-severity-medium' => 'blue',
'colour-severity-low' => 'gray',
'colour-severity-lowest' => 'scots tartan',
);
is( $processor->color_severity_highest(),
'chartreuse', 'user default colour-severity-highest' );
is( $processor->color_severity_high(),
'fuschia', 'user default colour-severity-high' );
is( $processor->color_severity_medium(),
'blue', 'user default colour-severity-medium' );
is( $processor->color_severity_low(),
'gray', 'user default colour-severity-low' );
is( $processor->color_severity_lowest(),
'scots tartan', 'user default colour-severity-lowest' );
$processor = Perl::Critic::OptionsProcessor->new(
'color-severity-5' => 'chartreuse',
'color-severity-4' => 'fuschia',
'color-severity-3' => 'blue',
'color-severity-2' => 'gray',
'color-severity-1' => 'scots tartan',
);
is( $processor->color_severity_highest(),
'chartreuse', 'user default color-severity-5' );
is( $processor->color_severity_high(),
'fuschia', 'user default color-severity-4' );
is( $processor->color_severity_medium(),
'blue', 'user default color-severity-3' );
is( $processor->color_severity_low(),
'gray', 'user default color-severity-2' );
is( $processor->color_severity_lowest(),
'scots tartan', 'user default color-severity-1' );
$processor = Perl::Critic::OptionsProcessor->new(
'colour-severity-5' => 'chartreuse',
'colour-severity-4' => 'fuschia',
'colour-severity-3' => 'blue',
'colour-severity-2' => 'gray',
'colour-severity-1' => 'scots tartan',
);
is( $processor->color_severity_highest(),
'chartreuse', 'user default colour-severity-5' );
is( $processor->color_severity_high(),
'fuschia', 'user default colour-severity-4' );
is( $processor->color_severity_medium(),
'blue', 'user default colour-severity-3' );
is( $processor->color_severity_low(),
'gray', 'user default colour-severity-2' );
is( $processor->color_severity_lowest(),
'scots tartan', 'user default colour-severity-1' );
}
#-----------------------------------------------------------------------------
{
my $processor = Perl::Critic::OptionsProcessor->new( pager => 'foo' );
is($processor->color(), $FALSE, 'pager set turns off color');
}
#-----------------------------------------------------------------------------
# Test exception handling
{
my %invalid_defaults = (
foo => 1,
bar => 2,
);
eval { Perl::Critic::OptionsProcessor->new( %invalid_defaults ) };
like(
$EVAL_ERROR,
qr/"foo" [ ] is [ ] not [ ] a [ ] supported [ ] option/xms,
'First invalid default',
);
like(
$EVAL_ERROR,
qr/"bar" [ ] is [ ] not [ ] a [ ] supported [ ] option/xms,
'Second invalid default',
);
}
##############################################################################
# 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 :
|