Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in Test::Strict (with patch) #25

Open
manwar opened this issue Jul 6, 2018 · 0 comments
Open

Bug in Test::Strict (with patch) #25

manwar opened this issue Jul 6, 2018 · 0 comments

Comments

@manwar
Copy link
Owner

manwar commented Jul 6, 2018

Issue raised by email directly (chohag@jtan.com):

Actually 2 (and a bit). First the weird one.

I wanted to use Test::Strict to test that a particular module was
included. Maybe there are better ways to do this but Test::Strict was
already there. This meant I ended up parsing the same file twice, although
I'm suspicious that that's a red herring. The flip flop operator in
_strict_ok retained its state between the first and second run through the
file and in the second go around assumed it was in a pod block from the
beginning. The patch replaces the flip-flop operator with an explicit
state variable.

In addition, pod directives can't begin with whitespace (on either side of
the =) so I removed that from the regex.

The 'bit' is that this will be treated by _strict_ok as a pod block, but
not by perl:

 -----
 $x 
 =42;

 print "still perl - $x\n";
 -----

I don't know how to deal with that except by being perl, so I didn't.
People who write code like that are on their own.

Patch:

 --- /home/mking/perl5/lib/site_perl/5.26.0/Test/Strict.pm 2016-12-01 15:04:42.000000000 +0000
 +++ lib/Test/Strict.pm  2018-07-06 13:53:16.435049602 +0000
 @@ -225,9 +225,12 @@
 sub _strict_ok {
     my ($in) = @_;
     local $_;
 +    my $pod;
        while (<$in>) {
          next if (/^\s*#/); # Skip comments
 -        next if (/^\s*=.+/ .. /^\s*=(cut|back|end)/); # Skip pod
 +        $pod = 0, next if /^=(cut|back|end)/;
 +        $pod = 1, next if /^=\S+/;
 +        next if $pod; # Skip pod
           last if (/^\s*(__END__|__DATA__)/); # End of code
           foreach my $name (modules_enabling_strict()) {
             # TODO: improve this matching (e.g. see TODO test)

Cheers,

Matthew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant