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

($var =~ tr///) doesn't count as a variable use #36

Open
gnustavo opened this issue May 6, 2018 · 1 comment
Open

($var =~ tr///) doesn't count as a variable use #36

gnustavo opened this issue May 6, 2018 · 1 comment
Labels

Comments

@gnustavo
Copy link

gnustavo commented May 6, 2018

This is the smallest test case I was able to come up with:

package foo;

sub func {
    my $false_positive = 'anything';

    return $false_positive =~ tr/,/,/;
}

1;

And this is how it triggers a false positive:

$ TEST_VERBOSE=1 perl -I. -MTest::Vars -E 'vars_ok(shift)' foo.pm
not ok 1 - foo.pm
#   Failed test 'foo.pm'
#   at -e line 1.
# checking foo in foo.pm ...
# $false_positive is used once in &foo::func at foo.pm line 4
# Tests were run but no plan was declared and done_testing() was not seen.

Shouldn't $false_positive =~ tr/,/,/ count as the variable being used?

@autarch
Copy link
Member

autarch commented May 6, 2018

Yes, this is definitely a bug.

gnustavo added a commit to gnustavo/Git-Hooks that referenced this issue May 7, 2018
It tests if there are unused variables.

It found a few of them which were fixed.

The $decoration variable, in PrepareLog.pm, wasn't really unused, but
the tests warned as if it were. I opened a issue on the Test::Vars
module [0] reporting a possible false positive. I changed the code to
avoid this problem. Fortunately, the result is shorter and simpler
than before.

Ref: houseabsolute/p5-Test-Vars#36
@jkeenan jkeenan added the Bug label Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants