]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort: Improve sort --random-sort test.
authorBob Proulx <bob@proulx.com>
Thu, 26 Jul 2007 08:26:13 +0000 (02:26 -0600)
committerJim Meyering <jim@meyering.net>
Thu, 26 Jul 2007 08:32:21 +0000 (10:32 +0200)
Jim Meyering wrote:
> so if your test were to run sort -R twice, and compare *those* outputs,
> then it would trigger on this bug.

Thanks.  I don't have a system with the failure so I was working
blind.  Here is a rework of the patch.

Bob

>From 76dafb0dde4f8d685eb2b4b43fbf3c1cf9f0ff4b Mon Sep 17 00:00:00 2001
From: Bob Proulx <bob@proulx.com>
Date: Thu, 26 Jul 2007 02:19:49 -0600
Subject: [PATCH] sort: Improve sort --random-sort test.
* tests/misc/sort-rand: If "locale" is available pick a random
non-C locale and check "sort --random-sort" behavior using it.

Signed-off-by: Bob Proulx <bob@proulx.com>
ChangeLog
tests/misc/sort-rand

index d5be794f0fa1193ab0907e0272a0476de809bbec..327e5342e05927daefb3737576f27a98b6ba5fcc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-07-26  Bob Proulx  <bob@proulx.com>
+
+       sort: Improve sort --random-sort test.
+       * tests/misc/sort-rand: If "locale" is available pick a random
+       non-C locale and check "sort --random-sort" behavior using it.
+
 2007-07-24  Jim Meyering  <jim@meyering.net>
 
        sort: add a test to exercise the affected code.
index 0380af8c25e6c76d76caf9e2c3a2573845041b17..c6dd597e3b152c250b9163785cb4edb24295e08b 100755 (executable)
@@ -49,4 +49,18 @@ cmp in out > /dev/null && { fail=1; echo "not random?" 1>&2; }
 sort -n out > out1
 cmp in out1 || { fail=1; echo "not a permutation" 1>&2; }
 
+# If locale is available then use it to find a random non-C locale.
+if (locale --version) > /dev/null 2>&1; then
+  locale=`locale -a | sort --random-sort | awk '/^.._/{print;exit}'`
+  LC_ALL=$locale sort --random-sort in > out1 || fail=1
+  LC_ALL=$locale sort --random-sort in > out2 || fail=1
+
+  # Fail if the output "randomly" is the same twice in a row.
+  cmp out1 out2 > /dev/null && { fail=1; echo "not random with LC_ALL=$locale" 1>&2; }
+
+  # Fail if the sorted output is not the same as the input.
+  sort -n out > out1
+  cmp in out1 || { fail=1; echo "not a permutation with LC_ALL=$locale" 1>&2; }
+fi
+
 (exit $fail); exit $fail