[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] sort: Improve sort --random-sort test.
From: |
Jim Meyering |
Subject: |
Re: [PATCH] sort: Improve sort --random-sort test. |
Date: |
Thu, 26 Jul 2007 09:39:03 +0200 |
address@hidden (Bob Proulx) wrote:
> * 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 <address@hidden>
> ---
> ChangeLog | 6 ++++++
> tests/misc/sort-rand | 13 +++++++++++++
> 2 files changed, 19 insertions(+), 0 deletions(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index d5be794..327e534 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,9 @@
> +2007-07-26 Bob Proulx <address@hidden>
> +
> + 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 <address@hidden>
>
> sort: add a test to exercise the affected code.
> diff --git a/tests/misc/sort-rand b/tests/misc/sort-rand
> index 0380af8..78f48ef 100755
> --- a/tests/misc/sort-rand
> +++ b/tests/misc/sort-rand
> @@ -49,4 +49,17 @@ # Fail if the sorted output is not the s
> 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 pseudo-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 > out || fail=1
> +
> + # Fail if the input is the same as the output.
> + cmp in out > /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; }
Thanks, Bob.
However, note that even the buggy sort -R *does* change the order.
It's just that it always does it the same way :-)
(this is on a rawhide system)
$ (export PATH=/bin:$PATH LC_ALL=fr_FR.utf8; seq 25|sort -R)
1
10
11
12
13
14
15
16
17
18
19
2
20
21
22
23
24
25
3
4
5
6
7
8
9
so if your test were to run sort -R twice, and compare *those* outputs,
then it would trigger on this bug.