coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] sort: fix a contradictory --debug warning


From: Jim Meyering
Subject: Re: [PATCH] sort: fix a contradictory --debug warning
Date: Fri, 06 May 2011 16:35:11 +0200

Pádraig Brady wrote:
> Author: Pádraig Brady <address@hidden>
> Date:   Fri May 6 08:07:46 2011 +0100
>
>     sort: fix a contradictory --debug warning
>
>     * src/sort.c (key_warn): `sort -k2,1n --debug` would output
>     warnings about being both "zero width" and "spanning multiple fields".
>     Suppress the latter one.
>     * tests/misc/sort-debug-warn: Add a couple of test cases.
>
> diff --git a/src/sort.c b/src/sort.c
> index 07d6765..e10159a 100644
> --- a/src/sort.c
> +++ b/src/sort.c
> @@ -2385,7 +2385,7 @@ key_warnings (struct keyfield const *gkey, bool 
> gkey_only)
>            size_t eword = key->eword + 1;
>            if (!sword)
>              sword++;
> -          if (sword != eword)
> +          if (!eword || sword < eword)
>              error (0, 0, _("key %lu is numeric and spans multiple fields"),
>                     keynum);
>          }
> diff --git a/tests/misc/sort-debug-warn b/tests/misc/sort-debug-warn
> index def2571..5ae0002 100755
> --- a/tests/misc/sort-debug-warn
> +++ b/tests/misc/sort-debug-warn
> @@ -23,6 +23,10 @@ cat <<\EOF > exp
>  sort: using simple byte comparison
>  sort: key 1 has zero width and will be ignored
>  sort: using simple byte comparison
> +sort: key 1 has zero width and will be ignored
> +sort: using simple byte comparison
> +sort: key 1 is numeric and spans multiple fields
> +sort: using simple byte comparison
>  sort: options `-bghMRrV' are ignored
>  sort: using simple byte comparison
>  sort: options `-bghMRV' are ignored
> @@ -50,6 +54,8 @@ sort: using simple byte comparison
>  EOF
>
>  sort -s -k2,1 --debug /dev/null 2>>out
> +sort -s -k2,1n --debug /dev/null 2>>out
> +sort -s -k1,2n --debug /dev/null 2>>out
>  sort -s -rRVMhgb -k1,1n --debug /dev/null 2>>out
>  sort -rRVMhgb -k1,1n --debug /dev/null 2>>out
>  sort -r -k1,1n --debug /dev/null 2>>out

Looks fine.  Thanks!

FYI, I prefer to avoid that style of test, where the expected output
from multiple commands is all lumped together and relatively distant
from the associated command.
It's easier to read and to maintain when you can keep
command/output pairs together, as in tests/misc/sort.
It's also easier to interpret test failure.

  ["05a", '-k1,2', {IN=>"A B\nA A\n"}, {OUT=>"A A\nA B\n"}],
  ["05b", '-k1,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
  ["05c", '-k1 -k2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
  ["05d", '-k2,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
  ["05e", '-k2,2', {IN=>"A B Z\nA A A\n"}, {OUT=>"A A A\nA B Z\n"}],
  ["05f", '-k2,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
  #
  ["06a", '-k 1,2', {IN=>"A B\nA A\n"}, {OUT=>"A A\nA B\n"}],
  ["06b", '-k 1,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
  ["06c", '-k 1 -k 2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
  ["06d", '-k 2,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
  ["06e", '-k 2,2', {IN=>"A B Z\nA A A\n"}, {OUT=>"A A A\nA B Z\n"}],
  ["06f", '-k 2,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],

Entries for your new tests might look like these (untested):

  ["dbg-01", '-s -k2,1n --debug', {IN=>''}, {OUT=>''},
    {ERR=> "$prog: key 1 has zero width and will be ignored\n"
         . "$prog: using simple byte comparison\n" ],

  ["dbg-02", '-s -k1,2n --debug', {IN=>''}, {OUT=>''},
    {ERR=> "$prog: key 1 is numeric and spans multiple fields\n"
         . "$prog: using simple byte comparison\n" ],

Maybe I'll convert that test some day...



reply via email to

[Prev in Thread] Current Thread [Next in Thread]