Login
Comment in P::C::Document about underscores in perl version
[gknop/Perl-Critic.git] / t / 04_optionsprocessor.t
CommitLineData
faa35de4
JRT
1#!perl
2
e68db767 3##############################################################################
faa35de4
JRT
4# $URL$
5# $Date$
6# $Author$
7# $Revision$
e68db767 8##############################################################################
faa35de4 9
df6dee2b 10use 5.006001;
faa35de4
JRT
11use strict;
12use warnings;
e424327a 13
0d63e03a 14use English qw(-no_match_vars);
e424327a 15
894d344a 16use Perl::Critic::OptionsProcessor;
faa35de4 17
ae9b3404 18use Test::More tests => 24;
e424327a 19
e68db767 20#-----------------------------------------------------------------------------
faa35de4 21
be4331b3 22our $VERSION = '1.090';
b185fa17
ES
23
24#-----------------------------------------------------------------------------
25
faa35de4 26{
894d344a
ES
27 my $processor = Perl::Critic::OptionsProcessor->new();
28 is($processor->force(), 0, 'native default force');
29 is($processor->only(), 0, 'native default only');
30 is($processor->severity(), 5, 'native default severity');
31 is($processor->theme(), q{}, 'native default theme');
32 is($processor->top(), 0, 'native default top');
33 is($processor->color(), 1, 'native default color');
34 is($processor->verbose(), 4, 'native default verbose');
35 is($processor->criticism_fatal, 0, 'native default criticism-fatal');
36 is_deeply($processor->include(), [], 'native default include');
37 is_deeply($processor->exclude(), [], 'native default exclude');
faa35de4
JRT
38}
39
40#-----------------------------------------------------------------------------
41
42{
410cf90b
JRT
43 my %user_defaults = (
44 force => 1,
410cf90b
JRT
45 only => 1,
46 severity => 4,
47 theme => 'pbp',
48 top => 50,
e424327a 49 color => 0,
410cf90b 50 verbose => 7,
badbf753 51 'criticism-fatal' => 1,
410cf90b
JRT
52 include => 'foo bar',
53 exclude => 'baz nuts',
54 );
55
894d344a
ES
56 my $processor = Perl::Critic::OptionsProcessor->new( %user_defaults );
57 is($processor->force(), 1, 'user default force');
58 is($processor->only(), 1, 'user default only');
59 is($processor->severity(), 4, 'user default severity');
60 is($processor->theme(), 'pbp', 'user default theme');
61 is($processor->top(), 50, 'user default top');
e424327a 62 is($processor->color(), 0, 'user default color');
894d344a
ES
63 is($processor->verbose(), 7, 'user default verbose');
64 is($processor->criticism_fatal(), 1, 'user default criticism_fatal');
65 is_deeply($processor->include(), [ qw(foo bar) ], 'user default include');
66 is_deeply($processor->exclude(), [ qw(baz nuts)], 'user default exclude');
410cf90b
JRT
67}
68
69#-----------------------------------------------------------------------------
ae9b3404
ES
70
71{
72 my $processor = Perl::Critic::OptionsProcessor->new( 'colour' => 1 );
73 is($processor->color(), 1, 'user default colour true');
74
75 $processor = Perl::Critic::OptionsProcessor->new( 'colour' => 0 );
76 is($processor->color(), 0, 'user default colour false');
77}
78
79#-----------------------------------------------------------------------------
0d63e03a 80# Test exception handling
410cf90b
JRT
81
82{
0d63e03a
JRT
83 my %invalid_defaults = (
84 foo => 1,
85 bar => 2,
dc93df4f
JRT
86 );
87
894d344a 88 eval { Perl::Critic::OptionsProcessor->new( %invalid_defaults ) };
369d6f3a
ES
89 like(
90 $EVAL_ERROR,
91 qr/"foo" [ ] is [ ] not [ ] a [ ] supported [ ] option/xms,
92 'First invalid default',
93 );
94 like(
95 $EVAL_ERROR,
96 qr/"bar" [ ] is [ ] not [ ] a [ ] supported [ ] option/xms,
97 'Second invalid default',
98 );
0d63e03a 99
faa35de4
JRT
100}
101
34cc6052
ES
102#-----------------------------------------------------------------------------
103
104# ensure we run true if this test is loaded by
105# t/04_defaults.t_without_optional_dependencies.t
1061;
107
0d63e03a 108##############################################################################
737d3b65
CD
109# Local Variables:
110# mode: cperl
111# cperl-indent-level: 4
112# fill-column: 78
113# indent-tabs-mode: nil
114# c-indentation-style: bsd
115# End:
96fed375 116# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :