houseabsolute / p5-Test-Vars

Detects unused variables in unit tests
https://metacpan.org/pod/Test::Vars
Other
6 stars 10 forks source link

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

Open gnustavo opened 6 years ago

gnustavo commented 6 years ago

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 commented 6 years ago

Yes, this is definitely a bug.