Can't get #17492 to work with -Uuseperlio otherwise (either
[p5sagit/p5-mst-13.2.git] / lib / sort.t
index dbbf82e..9903765 100644 (file)
@@ -3,9 +3,6 @@
 # This tests the behavior of sort() under the different 'use sort' forms.
 # Algorithm by John P. Linderman.
 
-use strict;
-use warnings;
-
 my ($BigWidth, $BigEnough, $RootWidth, $ItemFormat, @TestSizes, $WellSoaked);
 
 BEGIN {
@@ -25,6 +22,9 @@ BEGIN {
     }
 }
 
+use strict;
+use warnings;
+
 use Test::More tests => @TestSizes * 2 # sort() tests
                        * 4             # number of pragmas to test
                        + 1             # extra test for qsort instability
@@ -58,15 +58,18 @@ sub genarray {
 sub checkorder {
     my $aref = shift;
     my $status = '';                   # so far, so good
-    my $i;
+    my ($i, $disorder);
 
     for ($i = 0; $i < $#$aref; ++$i) {
-       next if ($aref->[$i] lt $aref->[$i+1]);
-       $status = (substr($aref->[$i], 0, $RootWidth) eq
-                  substr($aref->[$i+1], 0, $RootWidth)) ?
-                 "Instability" : "Disorder";
-       $status .= " at element $i between $aref->[$i] and $aref->[$i+1]";
-       last;
+       # Equality shouldn't happen, but catch it in the contents check
+       next if ($aref->[$i] le $aref->[$i+1]);
+       $disorder = (substr($aref->[$i],   0, $RootWidth) eq
+                    substr($aref->[$i+1], 0, $RootWidth)) ?
+                    "Instability" : "Disorder";
+       # Keep checking if merely unstable... disorder is much worse.
+       $status =
+           "$disorder at element $i between $aref->[$i] and $aref->[$i+1]";
+       last unless ($disorder eq "Instability");       
     }
     return $status;
 }
@@ -121,6 +124,8 @@ sub main {
        $status = checkequal(\@sorted, $unsorted);
        is($status, '', "contents ok for size $ts");
     }
+    # If the following test (#58) fails, see the comments in pp_sort.c
+    # for Perl_sortsv().
     if ($expect_unstable) {
        ok($unstable_num > 0, 'Instability ok');
     }
@@ -131,9 +136,8 @@ main(0);
 
 # XXX We're using this eval "..." trick to force recompilation,
 # to ensure that the correct pragma is enabled when main() is run.
-# Currently 'use sort' modifies $^H{SORT} at compile-time, but
-# pp_sort() fetches its value at run-time : thus the lexical scoping
-# of %^H is of no utility.
+# Currently 'use sort' modifies $sort::hints at compile-time, but
+# pp_sort() fetches its value at run-time.
 # The order of those evals is important.
 
 eval q{