Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Simple CPAN distribution.

Report information
The Basics
Id: 20940
Status: resolved
Priority: 0/
Queue: Test-Simple

People
Owner: Nobody in particular
Requestors: ROBN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Test::Builder::is_eq() doesn't handle stringification overload edge case
Perl 5.8.8 Test-Simple 0.62 Linux 2.6.16 According to the overload.pm doc: 'The table of methods for all operations is cached in magic for the symbol table hash for the package. The cache is invalidated during processing of "use overload", "no overload", new function definitions, and changes in @ISA. However, this invalidation remains unprocessed until the next bless"ing into the package. Hence if you want to change overloading structure dynamically, you'll need an additional (fake) "bless"ing to update the table.' Test::Build::is_eq digs into the internal overload table (via overload::Method) to get the stringification method and calls it directly. In the rare case that the package symbol table has not been updated (as described above), this can cause a test to pass even when stringification is not working correctly. The attached files demonstrate this. Admittedly this is a rare case, but its not hypothetical - Class-Constant-0.03 needs to work around this in t/values.t to make the tests pass (indeed, earlier versions were actually broken due to this).
Subject: thunk.pl
#!/usr/bin/perl use warnings; use strict; use lib '.'; use thunk; use Test::More "no_plan"; is(thunk::object::value, "thunk! thats an object!"); my $x = "".$thunk::object::value; is($x, "thunk! thats an object!");
Subject: thunk.pm
package thunk; use warnings; use strict; sub import { my $value = bless \do { my $x }, "thunk::object"; *thunk::object::value = sub { $value }; unshift @thunk::object::ISA, "thunk::value"; } package thunk::value; use overload q{""} => sub { "thunk! thats an object!" }; 1;
thunk.pl has a minor typo; new version attached. Output: $ ./thunk.pl ok 1 not ok 2 # Failed test in ./thunk.pl at line 15. # got: 'thunk::object=SCALAR(0x8189a54)' # expected: 'thunk! thats an object!' 1..2 # Looks like you failed 1 test of 2.
#!/usr/bin/perl use warnings; use strict; use lib '.'; use thunk; use Test::More "no_plan"; is(thunk::object::value, "thunk! thats an object!"); my $x = "".thunk::object::value; is($x, "thunk! thats an object!");
do you have a suggestion for a solution? I don't think having Test::Builder do that dummy bless is a good idea.
I agree with hdp. Test::More is doing the right thing, exposing a stringification edge case in the code. If Test::More tried to hide this, by doing the bless, the problem would be hidden.