forked from Perl-Critic/Perl-Critic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This test checks a problems with the line tracking for violations. * It doesn't seem to fail on 5.22.1, but it does on 5.18.2. * If you have the policy 'CodeLayout::ProhibitHashBarewords', it will use that for the test. * If you don't, it won't do anything.
- Loading branch information
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Perl::Critic::TestUtils qw(pcritique_with_violations); | ||
use Readonly; | ||
|
||
use Test::More; | ||
|
||
Readonly::Scalar my $NUMBER_OF_TESTS => 5; | ||
|
||
plan( tests => $NUMBER_OF_TESTS ); | ||
|
||
#----------------------------------------------------------------------------- | ||
|
||
our $VERSION = '1.126'; | ||
|
||
#----------------------------------------------------------------------------- | ||
|
||
Perl::Critic::TestUtils::block_perlcriticrc(); | ||
|
||
sub has_policy { | ||
return eval { | ||
require Perl::Critic::Policy::CodeLayout::ProhibitHashBarewords; | ||
1; | ||
}; | ||
} | ||
|
||
my $policy = 'CodeLayout::ProhibitHashBarewords'; | ||
my $code; | ||
|
||
#----------------------------------------------------------------------------- | ||
SKIP: { | ||
|
||
has_policy() | ||
or skip 'You need CodeLayout::ProhibitHashBarewords policy for this test', | ||
$NUMBER_OF_TESTS; | ||
|
||
$code = <<'END_PERL'; | ||
my %hash = ( | ||
foo => 1, | ||
bar => 2, | ||
baz => 3, | ||
quux => 4, | ||
); | ||
END_PERL | ||
|
||
my @violations_re = ( | ||
qr{^ \s* foo \s =>}xms, | ||
qr{^ \s* bar \s =>}xms, | ||
qr{^ \s* baz \s =>}xms, | ||
qr{^ \s* quux \s =>}xms, | ||
); | ||
|
||
my @violations; | ||
eval { @violations = pcritique_with_violations( $policy, \$code ); 1; }; | ||
is( scalar @violations, 4, 'Found 4 violations' ); | ||
|
||
foreach my $violation (@violations) { | ||
my $violation_re = shift @violations_re || qr{^NOPE$}xms; | ||
like( $violation->source, $violation_re, 'Correct line for violation' ); | ||
} | ||
|
||
} # end skip | ||
|
||
#----------------------------------------------------------------------------- | ||
|
||
# ensure we return true if this test is loaded by | ||
# t/20_policy_pod_spelling.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 : |