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

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

Bug Information
Severity: Unimportant
Broken in: 0.80
Fixed in: (no value)



Subject: eq_array changes the magic nature of the "expected" array
When comparing an input array with magic values to a fiducial array without, eq_array transfers magic to the fiducial array. Here's an example using YAML (which creates a magic value): use YAML; use Devel::Peek; use Test::More; my $obj = [ 'snake' ]; YAML::DumpFile( 'foo', $obj ); Dump $obj; my $array = YAML::LoadFile( 'foo' ); eq_array( $array, $obj ); Dump $obj; And the result: % perl eq_array.pl SV = RV(0xe4d660) at 0xe4d650 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0xe21df0 SV = PVAV(0xe22fb0) at 0xe21df0 REFCNT = 1 FLAGS = () ARRAY = 0xe396b0 FILL = 0 MAX = 0 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = PV(0xe1eb68) at 0xe22060 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0xe35560 "snake"\0 CUR = 5 LEN = 8 SV = RV(0xe4d660) at 0xe4d650 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0xe21df0 SV = PVAV(0xe22fb0) at 0xe21df0 REFCNT = 1 FLAGS = (RMG) MAGIC = 0x1032e00 MG_VIRTUAL = &PL_vtbl_arylen_p MG_TYPE = PERL_MAGIC_arylen_p(@) MG_FLAGS = 0x02 REFCOUNTED MG_OBJ = 0x1520110 SV = PVMG(0x1124160) at 0x1520110 REFCNT = 1 FLAGS = (GMG,SMG,pIOK) IV = 0 NV = 0 PV = 0 MAGIC = 0x152bd10 MG_VIRTUAL = &PL_vtbl_arylen MG_TYPE = PERL_MAGIC_arylen(#) MG_OBJ = 0xe21df0 ARRAY = 0xe396b0 FILL = 0 MAX = 0 ARYLEN = 0x1520110 FLAGS = (REAL) Elt No. 0 SV = PV(0xe1eb68) at 0xe22060 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0xe35560 "snake"\0 CUR = 5 LEN = 8 I believe $obj should remain unchanged. The fallout from this is that Clone, which doesn't seem to be able to clone the YAML created hash, also doesn't work on $obj. Thanks, Diab
My apologies; the output was mangled in the last message. One more time: SV = RV(0x7ce660) at 0x7ce650 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x7a2df0 SV = PVAV(0x7a3fb0) at 0x7a2df0 REFCNT = 1 FLAGS = () ARRAY = 0x7ba6b0 FILL = 0 MAX = 0 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = PV(0x79fb68) at 0x7a3060 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x7b6560 "snake"\0 CUR = 5 LEN = 8 SV = RV(0x7ce660) at 0x7ce650 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x7a2df0 SV = PVAV(0x7a3fb0) at 0x7a2df0 REFCNT = 1 FLAGS = (RMG) MAGIC = 0xe1c410 MG_VIRTUAL = &PL_vtbl_arylen_p MG_TYPE = PERL_MAGIC_arylen_p(@) MG_FLAGS = 0x02 REFCOUNTED MG_OBJ = 0xea1040 SV = PVMG(0xaa50e0) at 0xea1040 REFCNT = 1 FLAGS = (GMG,SMG,pIOK) IV = 0 NV = 0 PV = 0 MAGIC = 0xe1c440 MG_VIRTUAL = &PL_vtbl_arylen MG_TYPE = PERL_MAGIC_arylen(#) MG_OBJ = 0x7a2df0 ARRAY = 0x7ba6b0 FILL = 0 MAX = 0 ARYLEN = 0xea1040 FLAGS = (REAL) Elt No. 0 SV = PV(0x79fb68) at 0x7a3060 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x7b6560 "snake"\0 CUR = 5 LEN = 8
On Fri Aug 29 14:51:00 2008, DJERIUS wrote: Show quoted text
> My apologies; the output was mangled in the last message. One more time:
Aargh. Once again mangled. Please see attached file.
Download eq_array.output
application/octet-stream 1.1k

Message body not shown because it is not plain text.

It seems that the input need not have magic. A revised example using YAML::Tiny, which doesn't create magic values is attached. It looks like both of the arrays passed to eq_array are changed. The example shows that both arrays are now incorrectly handled by Clone. I'm including that just for completeness; I'm not sure if it's Clone's problem or Test::More's.
Download eq_array.output
application/octet-stream 2.4k

Message body not shown because it is not plain text.

use YAML::Tiny qw( DumpFile LoadFile ); use Test::More; use Clone qw( clone ); use Data::Dumper; use Devel::Peek; my $obj = [ 'snake' ]; DumpFile( 'foo', $obj ); my $array = LoadFile( 'foo' ); print STDERR "Before (\$array):\n"; Dump $array; print STDERR "Before (\$obj):\n"; Dump $obj; eq_array( $array, $obj ); print STDERR "\nAfter (\$array):\n"; Dump $array; print STDERR "\nAfter (\$obj):\n"; Dump $obj; print STDERR "\nCloned \$array:\n"; print STDERR Dumper clone( $array ); print STDERR "\nCloned \$obj:\n"; print STDERR Dumper clone( $obj );
Subject: Re: [rt.cpan.org #38848] eq_array changes the magic nature of the "expected" array
Date: Sat, 06 Sep 2008 12:15:45 -0700
To: bug-Test-Simple [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
Diab Jerius via RT wrote: Show quoted text
> Queue: Test-Simple > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=38848 > > > It seems that the input need not have magic. A revised example using > YAML::Tiny, which doesn't create magic values is attached. It looks > like both of the arrays passed to eq_array are changed. The example > shows that both arrays are now incorrectly handled by Clone. I'm > including that just for completeness; I'm not sure if it's Clone's > problem or Test::More's.
Sorry, I can't reproduce this. What version of perl and all the involved modules (Test::More, Clone, YAML::Tiny) are you using? Also, eq_array() is discouraged. Use is_deeply(). -- We do what we must because we can. For the good of all of us, Except the ones who are dead. -- Jonathan Coulton, "Still Alive"
Show quoted text
> Sorry, I can't reproduce this. What version of perl and all the involved > modules (Test::More, Clone, YAML::Tiny) are you using? > > Also, eq_array() is discouraged. Use is_deeply().
Yikes!! My profuse apologies for letting this slip through the cracks. I've attached a much simpler test case & output which just uses Test::More (version 0.94). Under Perl 5.8.8 (both Linux & OS X Leopard) the arrays passed to eq_array do not acquire magic through that call. Using Perl 5.10.0 (both Linux & OS X Leopard) they do.
Subject: test2.pl
use Test::More; use Devel::Peek; select STDERR; print "Perl = $]\n"; print "Test::More = ", Test::More->VERSION, "\n\n"; my $obj = [ 'snake' ]; my $array = [ 'snake' ]; print "Before (\$array):\n"; Dump $array; print "Before (\$obj):\n"; Dump $obj; eq_array( $array, $obj ); print "\nAfter (\$array):\n"; Dump $array; print "\nAfter (\$obj):\n"; Dump $obj;
Subject: eq_array_added_magic.out
Download eq_array_added_magic.out
application/octet-stream 2.4k

Message body not shown because it is not plain text.

Subject: eq_array_no_added_magic.out
Download eq_array_no_added_magic.out
application/octet-stream 1.6k

Message body not shown because it is not plain text.

On Fri Jun 04 16:26:45 2010, DJERIUS wrote: Show quoted text
> Yikes!! My profuse apologies for letting this slip through the cracks. > > I've attached a much simpler test case & output which just uses > Test::More (version 0.94). Under Perl 5.8.8 (both Linux & OS X Leopard) > the arrays passed to eq_array do not acquire magic through that call. > Using Perl 5.10.0 (both Linux & OS X Leopard) they do.
Thanks for picking this one up. Looks like you found a bug in perl. I tracked it down and its $#array which triggers magic (oddly enough, $scalar = @array does not). 5.10.0 and 5.10.1 have this problem but 5.8.9, 5.12.0 and 5.12.1 don't. So it looks like it was fixed. $ perl -wle 'my @array = (1,2); use Devel::Peek; Dump \@array; my $idx = $#array; Dump \@array' I don't think there's a whole lot Test::More can do about this. It could eliminate all uses of $#array from the code, but its pretty likely something else will use it. So I'm going to mark this as rejected. Feel free to reopen if you want to.