On 2010.6.18 3:22 AM, Paul LeoNerd Evans via RT wrote:
Show quoted text> On Fri, Jun 11, 2010 at 07:09:56PM -0400, Michael G Schwern via RT wrote:
>> If that doesn't work with 0.95_01 I'm not sure how it ever worked. It implies
>> an object that has eq overloaded but not stringification?
>
> It has stringification, but no eq.
>
> The original report is here
>
>
https://rt.cpan.org/Ticket/Display.html?id=57762
In that case, I don't understand how this ever tested object equality:
is( $e->string, $str, '$e->string' );
<= 0.94 that was equivalent to:
my $have = $e->string;
is( "$have", "$str", '$e->string' );
If $str or $e->string is string overloaded, that's testing the string
overloading, not object equality. So I'm a bit lost.
Show quoted text>> I really doubt it will go into Test::More. Its fairly trivial and something
>> that doesn't come up all that often. I like to keep Test::More's interface slim.
>
> Really? Given we have is(), isnt(), like(), unlike(), is_deeply(), ....
> adding one more for referential identity isn't much more.
Its always just one more.
I prefer to keep Test::More down to relatively straightforward (you'd be
surprised to find how not straightforward is() and like() can get at times)
and broadly useful functions to keep the API slim and the implementation
solid. String equality, string matching and complex structure equality all
match that.
The other criterion is that the function produce useful diagnostics that would
otherwise be annoying to get. For example, isnt() exists because ok( $have ne
$want ) doesn't tell you what $have was when it failed and there's no easy way
to negate is(). (Also it was amusing)
Finally, it has to have interesting corner cases that make it less than
trivial to write. is() handles things like undef and object overloading.
An object equality function doesn't appear to have any of these traits.
That's my superficial reading of it. I encourage you to argue otherwise.
Show quoted text>> Fortunately, you can wrap it up like so:
>>
>> use Scalar::Util qw(refaddr);
>> sub is_same {
>> my($have, $want, name) = @_;
>>
>> local $Test::Builder::Level = $Test::Builder::Level + 1;
>> return is( refaddr $have, refaddr $want );
>> }
>
> I've found the following behaves sanely:
>
> use Scalar::Util qw( refaddr );
> sub identical
> {
> my ( $got, $expected, $name ) = @_;
>
> ok( refaddr $got == refaddr $expected, $name ) or
> diag( "Expected $got and $expected to refer to the same object" );
> }
>
> It adds the diagnostic when it fails also, which might be helpful.
You want to increment $Test::Builder::Level so the ok() failure is reported at
the point where identical() is called instead of ok().
Show quoted text> I'd be quite happy to write it up properly with tests and docs as a
> patch, if you think it might be acceptable..
At this point, no, but you can write it up as a module. There is, imho, an
opportunity to write a test module which covers detailed class and object
tests better than isa_ok, can_ok and new_ok [1] serve.
--
I'm pale as Formica, social skills stunted small. But I'm accurate
like a pica, I know the capital of Nepal. I'm the nemesis of error,
dreadful diction fears my skills, more inquisitive than Jim Lehrer,
snottier than Beverly Hills.
-- I.L.O.P. Secret Rap
http://goats.com/archive/020830.html