Login
Apply the unmodified patch from Schwern (modulo dealing with
[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
89b50090 18use Test::More tests => 27;
e424327a 19
e68db767 20#-----------------------------------------------------------------------------
faa35de4 21
be4331b3 22our $VERSION = '1.090';
b185fa17
ES
23
24#-----------------------------------------------------------------------------
25
faa35de4 26{
89b50090
ES
27 my $color = -t *STDOUT ? 1 : 0;
28
894d344a
ES
29 my $processor = Perl::Critic::OptionsProcessor->new();
30 is($processor->force(), 0, 'native default force');
31 is($processor->only(), 0, 'native default only');
32 is($processor->severity(), 5, 'native default severity');
33 is($processor->theme(), q{}, 'native default theme');
34 is($processor->top(), 0, 'native default top');
89b50090
ES
35 is($processor->color(), $color, 'native default color');
36 is($processor->pager(), q{}, 'native default pager');
894d344a
ES
37 is($processor->verbose(), 4, 'native default verbose');
38 is($processor->criticism_fatal, 0, 'native default criticism-fatal');
39 is_deeply($processor->include(), [], 'native default include');
40 is_deeply($processor->exclude(), [], 'native default exclude');
faa35de4
JRT
41}
42
43#-----------------------------------------------------------------------------
44
45{
410cf90b
JRT
46 my %user_defaults = (
47 force => 1,
410cf90b
JRT
48 only => 1,
49 severity => 4,
50 theme => 'pbp',
51 top => 50,
e424327a 52 color => 0,
89b50090 53 pager => 'less',
410cf90b 54 verbose => 7,
badbf753 55 'criticism-fatal' => 1,
410cf90b
JRT
56 include => 'foo bar',
57 exclude => 'baz nuts',
58 );
59
894d344a
ES
60 my $processor = Perl::Critic::OptionsProcessor->new( %user_defaults );
61 is($processor->force(), 1, 'user default force');
62 is($processor->only(), 1, 'user default only');
63 is($processor->severity(), 4, 'user default severity');
64 is($processor->theme(), 'pbp', 'user default theme');
65 is($processor->top(), 50, 'user default top');
e424327a 66 is($processor->color(), 0, 'user default color');
89b50090 67 is($processor->pager(), 'less', 'user default pager');
894d344a
ES
68 is($processor->verbose(), 7, 'user default verbose');
69 is($processor->criticism_fatal(), 1, 'user default criticism_fatal');
70 is_deeply($processor->include(), [ qw(foo bar) ], 'user default include');
71 is_deeply($processor->exclude(), [ qw(baz nuts)], 'user default exclude');
410cf90b
JRT
72}
73
74#-----------------------------------------------------------------------------
ae9b3404
ES
75
76{
77 my $processor = Perl::Critic::OptionsProcessor->new( 'colour' => 1 );
78 is($processor->color(), 1, 'user default colour true');
79
80 $processor = Perl::Critic::OptionsProcessor->new( 'colour' => 0 );
81 is($processor->color(), 0, 'user default colour false');
82}
83
84#-----------------------------------------------------------------------------
89b50090
ES
85
86{
87 my $processor = Perl::Critic::OptionsProcessor->new(
88 pager => "foo"
89 );
90 is($processor->color(), 0, 'pager set turns off color');
91}
92
93#-----------------------------------------------------------------------------
0d63e03a 94# Test exception handling
410cf90b
JRT
95
96{
0d63e03a
JRT
97 my %invalid_defaults = (
98 foo => 1,
99 bar => 2,
dc93df4f
JRT
100 );
101
894d344a 102 eval { Perl::Critic::OptionsProcessor->new( %invalid_defaults ) };
369d6f3a
ES
103 like(
104 $EVAL_ERROR,
105 qr/"foo" [ ] is [ ] not [ ] a [ ] supported [ ] option/xms,
106 'First invalid default',
107 );
108 like(
109 $EVAL_ERROR,
110 qr/"bar" [ ] is [ ] not [ ] a [ ] supported [ ] option/xms,
111 'Second invalid default',
112 );
0d63e03a 113
faa35de4
JRT
114}
115
34cc6052
ES
116#-----------------------------------------------------------------------------
117
118# ensure we run true if this test is loaded by
119# t/04_defaults.t_without_optional_dependencies.t
1201;
121
0d63e03a 122##############################################################################
737d3b65
CD
123# Local Variables:
124# mode: cperl
125# cperl-indent-level: 4
126# fill-column: 78
127# indent-tabs-mode: nil
128# c-indentation-style: bsd
129# End:
96fed375 130# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :