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: 24186
Status: resolved
Priority: 0/
Queue: Test-Simple

People
Owner: Nobody in particular
Requestors: michael [...] ndrix.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 0.62
  • 0.64_02
  • 0.66
Fixed in: (no value)



Subject: cmp_ok not using overloaded '=='
The documentation for Test::More gives the code sample: # ok( $this == $that ); cmp_ok( $this, '==', $that, 'this == that' ); However, it seems that cmp_ok really does something more like ok( $this+0 == $that+0 ); For example, if $this and $that overload '==' and '0+' in certain ways, the result of cmp_ok with '==' can be different from ok with '=='. The attached test demonstrates the problem. I've tested the problem with version 0.62, 0.64 and 0.66. This happens on Linux with Perl 5.8.8
Subject: test.pl
use strict; use warnings; use Test::More tests => 2; my $foo = Thing->new(1); my $bar = Thing->new(3); ok( $foo == $bar, '$foo == $bar' ); cmp_ok( $foo, '==', $bar, q{cmp_ok($foo, '==', $bar)} ); package Thing; use overload '==' => \&numeric_equality, '0+' => \&numeric ; sub new { my ($class, $value) = @_; bless \$value, $class; } sub numeric_equality { my ($self, $other) = @_; return 1; } sub numeric { my ($self, $other) = @_; return $$self; }
On Tue Jan 02 11:29:42 2007, MNDRIX wrote: Show quoted text
> The attached test demonstrates the problem.
Hmm, RT seems to think the test is RSS. Anyway, here it is inline: use strict; use warnings; use Test::More tests => 2; my $foo = Thing->new(1); my $bar = Thing->new(3); ok( $foo == $bar, '$foo == $bar' ); cmp_ok( $foo, '==', $bar, q{cmp_ok($foo, '==', $bar)} ); package Thing; use overload '==' => \&numeric_equality, '0+' => \&numeric ; sub new { my ($class, $value) = @_; bless \$value, $class; } sub numeric_equality { my ($self, $other) = @_; return 1; } sub numeric { my ($self, $other) = @_; return $$self; }
Yep, I just ran into this trying to compare DateTime objects. I'm going to change cmp_ok() so that it no longer tries to unoverload the objects using "" or 0+ before doing the comparison. This will give closer to the true behavior of "$foo == $bar". If the comparison causes an error, the test fails.
Fixed. Will be in 0.85_01.