3 ##############################################################################
4 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/t/01_config_bad_perlcriticrc.t $
5 # $Date: 2008-06-21 19:57:54 -0700 (Sat, 21 Jun 2008) $
8 ##############################################################################
11 # Test that all the problems in an rc file get reported and not just the first
19 use English qw< -no_match_vars >;
24 use Perl::Critic::PolicyFactory (-test => 1);
29 Readonly::Scalar my $PROFILE => 't/01_bad_perlcriticrc';
30 Readonly::Scalar my $NO_ENABLED_POLICIES_MESSAGE =>
31 q<There are no enabled policies.>;
32 Readonly::Scalar my $INVALID_PARAMETER_MESSAGE =>
33 q<The BuiltinFunctions::RequireBlockGrep policy doesn't take a "no_such_parameter" option.>;
34 Readonly::Scalar my $REQUIRE_POD_SECTIONS_SOURCE_MESSAGE_PREFIX =>
35 q<The value for the Documentation::RequirePodSections "source" option ("Zen_and_the_Art_of_Motorcycle_Maintenance") is not one of the allowed values: >;
38 my $critic = Perl::Critic->new( '-profile' => $PROFILE );
42 my $eval_result = $EVAL_ERROR;
45 ok( $eval_result, 'should get an exception when using a bad rc file' );
47 die "No point in continuing.\n" if not $test_passed;
52 'Perl::Critic::Exception::AggregateConfiguration',
56 if ( not $test_passed ) {
58 die "No point in continuing.\n";
61 my @exceptions = @{ $eval_result->exceptions() };
74 my %expected_regexes =
76 { $_ => generate_global_message_regex( $_, $PROFILE ) }
79 my $expected_exceptions = 2 + scalar @parameters;
83 'should have received the correct number of exceptions'
85 if (@exceptions != $expected_exceptions) {
86 diag "Exception: $_" foreach @exceptions;
89 while (my ($parameter, $regex) = each %expected_regexes) {
91 ( scalar grep { m/$regex/ } @exceptions ),
93 "should have received one and only one exception for $parameter",
98 ( scalar grep { $INVALID_PARAMETER_MESSAGE eq $_ } @exceptions ),
100 "should have received an extra-parameter exception",
103 # Test that we get an exception for bad individual policy configuration.
104 # The selection of RequirePodSections is arbitrary.
106 ( scalar grep { is_require_pod_sections_source_exception($_) } @exceptions ),
108 "should have received an invalid source exception for RequirePodSections",
111 sub generate_global_message_regex {
112 my ($parameter, $file) = @_;
117 The [ ] value [ ] for [ ] the [ ] global [ ]
120 found [ ] in [ ] "$file"
124 sub is_require_pod_sections_source_exception {
125 my ($exception) = @_;
131 length $REQUIRE_POD_SECTIONS_SOURCE_MESSAGE_PREFIX;
133 return $prefix eq $REQUIRE_POD_SECTIONS_SOURCE_MESSAGE_PREFIX;
136 #-----------------------------------------------------------------------------
138 # ensure we run true if this test is loaded by
139 # t/01_config_bad_perlcriticrc.t_without_optional_dependencies.t
143 ##############################################################################
146 # cperl-indent-level: 4
148 # indent-tabs-mode: nil
149 # c-indentation-style: bsd
151 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :