I’m trying to write a test for this bug. I’ve already found a solution to the bug; what I can’t understand is why my tests didn’t catch the bug before release.
The problem boils down to this command line printing Ver: 0 when it’s supposed to print Ver: 1.00:
perl -Mversion -e 'printf "Ver: %s\n", ("v1.00" =~ /v(.+)/ ? version->parse($1) : "no");'
However, if you insert -MTest::More before -Mversion, then it prints Ver: 1.00.
So my question is why does loading Test::More change the behavior of my code? (For bonus points, why does using "$1" instead of $1 eliminate the bug?)
I’m using Perl 5.14.2, Test::More 0.98, and version 0.88.
It’s a bug in version.
$1is magical var, and version fails to process magic before checking if the arg is defined. It thinks$1is undefined if no one ever read from$1. If someone has read from$1(e.g. Test::More), then it appears defined to version.I have filed a bug report: Perl RT#115660