Slightly OT - why 04/*.t sometimes fails

[prev] [thread] [next] [Date index for 2005/06/22]

From: merlyn (Randal L. Schwartz)
Subject: Slightly OT - why 04/*.t sometimes fails
Date: 12:31 on 22 Jun 2005
--=-=-=


Just submitted this bug to P5P.  It explains why eq_set is broken,
but only sometimes. :)


--=-=-=
Content-Type: message/rfc822
Content-Disposition: inline

To: bugs-bitbucket@xx.xxxx.xxx
Reply-To: perl5-porters@xxxx.xxx
Subject: [perl #36354] Test::More [0.60]: eq_set has a broken sort logic 
From: perlbug-followup@xxxx.xxx (Randal L. Schwartz) (via RT)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

# New Ticket Created by  (Randal L. Schwartz) 
# Please include the string:  [perl #36354]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=36354 >



eq_set (I know, deprecated, but it's still broken) does this:

  sort { ref $a ? -1 : ref $b ? 1 : $a cmp $b } @$a1

I think the intent was to put all references at the beginning, and
then compare everything else directly.  Maybe not.  Hard to tell.

However, if the entire list is references (as it is with Class::DBI's
t/04-*.t test), then the sort routine gets "-1" for every pairwise
comparison.  As this is undefined, the result is random, and apparently
different on different machines, and different versions, and
different compilers, as I've spent the last few hours diagnosing.

If the purpose is merely to provide a *consistent* sorting, this will
suffice:

  sort { (ref $a) cmp (ref $b)   or    $a cmp $b } @$a1

This puts all the references after all the non-references, then sorts
all the items according to their stringification.  I *think* that
gets you 95% of the way there, if not 100%.

Anyway... classic example of how *not* to write a sort sub. :)

        -- 
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@xxxxxxxxxx.xxx> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


--=-=-=



-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@xxxxxxxxxx.xxx> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

--=-=-=--

Slightly OT - why 04/*.t sometimes fails
merlyn (Randal L. Schwartz) 12:31 on 22 Jun 2005

Generated at 16:38 on 28 Jul 2005 by mariachi v0.52