Testsuite: better sorting for exim_dumpdb output
[exim.git] / test / runtest
index 4d9468d90ad6d1ce958839c46dc4fac8a34ea819..e8a3e8e8504516fe1a3415208e656c559e88a88e 100755 (executable)
@@ -1630,17 +1630,17 @@ if (-e $sf_current)
 
   if ($sortfile)
     {
-    my ($i, $j);
 
     my @munged = do {
       open(my $fh, '<', $mf) or tests_exit(-1, "Failed to open $mf: $!");
       <$fh>;
     };
 
-    for ($i = 0; $i < @munged; $i++)
+    for (my $i = 0; $i < @munged; $i++)
       {
       if ($munged[$i] =~ /^[-\d]{10}\s[:\d]{8}\s[-A-Za-z\d]{16}\s[-=*]>/)
         {
+        my $j;
         for ($j = $i + 1; $j < @munged; $j++)
           {
           last if $munged[$j] !~
@@ -2168,16 +2168,15 @@ if (/^dump\s+(\S+)/)
 
   if ($which eq "retry")
     {
-    $/ = "\n  ";
-    @temp = <IN>;
-    $/ = "\n";
-
-    @temp = sort {
-                   my($aa) = split(' ', $a);
-                   my($bb) = split(' ', $b);
-                   return $aa cmp $bb;
-                 } @temp;
-
+    # the sort key is the first part of the retry db dump line, but for
+    # sorting we (temporarly) replace the own hosts ipv4 with a munged
+    # version, which matches the munging that is done later
+    # Why? We must ensure sure, that 127.0.0.1 always sorts first
+    # map-sort-map: Schwartz's transformation
+    my @temp = map  { $_->[1] }
+               sort { $a->[0] cmp $b->[0] }
+               map  { [ (split)[0] =~ s/\Q$parm_ipv4/ip4.ip4.ip4.ip4/gr, $_ ] }
+               do { local $/ = "\n  "; <$in> };
     foreach $item (@temp)
       {
       $item =~ s/^\s*(.*)\n(.*)\n?\s*$/$1\n$2/m;