Subject: bug#8263: closed (Re: bug#8263: [PATCH] Allow == as synonym for = in test)

From: [email-masked] (GNU bug Tracking System)
Date: Tue, 22 Mar 2011 06:16:01 +0000

Your bug report

#8263: [PATCH] Allow == as synonym for = in test

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
8263: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8263
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#8263: [PATCH] Allow == as synonym for = in test
From: Jim Meyering <[email-masked]>
To: Eric Blake <[email-masked]>
Cc: [email-masked], Pádraig Brady <[email-masked]>, [email-masked]
Date: Tue, 22 Mar 2011 07:15:16 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Eric Blake wrote:
> On 03/21/2011 06:25 AM, Pádraig Brady wrote:
>> On 15/03/11 23:39, David A. Wheeler wrote:
>>> The following trivial patch makes GNU coreutils' test recognize "=="
>>> as a synonym for "=".  This is already the case in GNU coreutils' expr,
>>> bash, ksh, busybox ash, FreeBSD-current /bin/sh and /bin/test, and
>>> OpenBSD's /bin/sh.  These are only a few lines, so I don't think
>>> any paperwork is needed.  The following implements "==" and documents it.
>>
>> Related http://austingroupbugs.net/view.php?id=375
>> I'm leaning towards accepting this.
>>
>> Note dash does not support ==, nor does older busybox ash.
>> dash seem to be waiting for the POSIX acceptance before changing?
>
> Yes, that's my read of the similar thread on the dash list - dash is
> waiting for the Austin Group ruling to take place first.  But coreutils
> already has several extensions not in dash (it's closer to bash), so we
> might as well go with it now.  I'm in favor of this patch.

I agree.
Here are three c-sets I expect to push later today:
  - David's patch with an adjusted log message
  - NEWS+test
  - gnulib update (unrelated)

I'm closing this ticket, too.

>From 3f31ec950b78309a0d12d92d87a735b8870a2289 Mon Sep 17 00:00:00 2001
From: David A. Wheeler <[email-masked]>
Date: Tue, 22 Mar 2011 06:03:55 +0100
Subject: [PATCH 1/3] test: accept "==" as a synonym for "="

Make GNU coreutils' test recognize "==" as a synonym for "=".
This is already the case in GNU coreutils' expr, bash, ksh,
busybox ash, FreeBSD-current /bin/sh and /bin/test, and
OpenBSD's /bin/sh.

Before, env test a '==' a would fail with this diagnostic:
"test: ==: binary operator expected".  Now, it succeeds.
* src/test.c: Accept "==" as a synonym for "=".
* doc/coreutils.texi (String tests): Document it.
Reported as http://debbugs.gnu.org/8263
Also see http://austingroupbugs.net/view.php?id=375
---
 doc/coreutils.texi |    7 ++++++-
 src/test.c         |    6 ++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 8dd1ed8..46deeed 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -11535,7 +11535,7 @@ test invocation
 * File type tests::             -[bcdfhLpSt]
 * Access permission tests::     -[gkruwxOG]
 * File characteristic tests::   -e -s -nt -ot -ef
-* String tests::                -z -n = !=
+* String tests::                -z -n = == !=
 * Numeric tests::               -eq -ne -lt -le -gt -ge
 * Connectives for test::        ! -a -o
 @end menu
@@ -11726,6 +11726,11 @@ String tests
 @cindex equal string check
 True if the strings are equal.

+@item @var{string1} == @var{string2}
+@opindex ==
+@cindex equal string check
+True if the strings are equal (synonym for =).
+
 @item @var{string1} != @var{string2}
 @opindex !=
 @cindex not-equal string check
diff --git a/src/test.c b/src/test.c
index 2d7aa67..362df65 100644
--- a/src/test.c
+++ b/src/test.c
@@ -173,7 +173,8 @@ get_mtime (char const *filename, struct timespec *mtime)
 static bool
 binop (char const *s)
 {
-  return ((STREQ (s,   "=")) || (STREQ (s,  "!=")) || (STREQ (s, "-nt")) ||
+  return ((STREQ (s,   "=")) || (STREQ (s,  "!=")) || (STREQ (s, "==")) ||
+          (STREQ (s,   "-nt")) ||
           (STREQ (s, "-ot")) || (STREQ (s, "-ef")) || (STREQ (s, "-eq")) ||
           (STREQ (s, "-ne")) || (STREQ (s, "-lt")) || (STREQ (s, "-le")) ||
           (STREQ (s, "-gt")) || (STREQ (s, "-ge")));
@@ -360,7 +361,8 @@ binary_operator (bool l_is_l)
       test_syntax_error (_("unknown binary operator"), argv[op]);
     }

-  if (argv[op][0] == '=' && !argv[op][1])
+  if (argv[op][0] == '=' && (!argv[op][1] ||
+       ((argv[op][1] == '=') && !argv[op][2])))
     {
       bool value = STREQ (argv[pos], argv[pos + 2]);
       pos += 3;
--
1.7.4.1.514.ga171c

>From b3f6b33e4b31667b9b43708730f6f75f25e8ff57 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email-masked]>
Date: Tue, 22 Mar 2011 06:07:35 +0100
Subject: [PATCH 2/3] tests: exercise tests new "==" operator

* tests/misc/test: Exercise the new operator.
* NEWS (Changes in behavior): Mention it.
---
 NEWS            |    4 ++++
 tests/misc/test |    2 ++
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/NEWS b/NEWS
index 9ceaa06..b2674c0 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   which will discard any cache associated with the files, or
   processed portion thereof.

+** Changes in behavior
+
+  test now accepts "==" as a synonym for "="
+

 * Noteworthy changes in release 8.10 (2011-02-04) [stable]

diff --git a/tests/misc/test b/tests/misc/test
index 396660b..f515b7f 100755
--- a/tests/misc/test
+++ b/tests/misc/test
@@ -132,6 +132,8 @@ my @Tests =

   ['streq-1', qw(t = t)],
   ['streq-2', qw(t = f), {EXIT=>1}],
+  ['streqeq-1', qw(t == t)],
+  ['streqeq-2', qw(t == f), {EXIT=>1}],
   ['streq-3', qw(! = !)],
   ['streq-4', qw(= = =)],
   ['streq-5', "'(' = '('"],
--
1.7.4.1.514.ga171c

>From 437fcf713c237f45f9504bb8bdc6041f65663b36 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email-masked]>
Date: Tue, 22 Mar 2011 06:09:06 +0100
Subject: [PATCH 3/3] build: update gnulib submodule to latest

---
 gnulib |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/gnulib b/gnulib
index 0baae9c..1a22d91 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit 0baae9cadd08c9704e3c704dd69fb75640293e9d
+Subproject commit 1a22d910adea20751cc5649b224574d07ba72815
--
1.7.4.1.514.ga171c

Subject: [PATCH] Allow == as synonym for = in test
From: "David A. Wheeler" <[email-masked]>
To: [email-masked]
Date: Tue, 15 Mar 2011 19:39:09 -0400 (EDT)
List-Id: <debbugs-submit.debbugs.gnu.org>

The following trivial patch makes GNU coreutils' test recognize "=="
as a synonym for "=".  This is already the case in GNU coreutils' expr,
bash, ksh, busybox ash, FreeBSD-current /bin/sh and /bin/test, and
OpenBSD's /bin/sh.  These are only a few lines, so I don't think
any paperwork is needed.  The following implements "==" and documents it.

  --- David A. Wheeler

--- ./src/test.c.orig	2011-03-15 00:49:11.000000000 -0400
+++ ./src/test.c	2011-03-15 09:11:04.000000000 -0400
@@ -173,7 +173,8 @@
 static bool
 binop (char const *s)
 {
-  return ((STREQ (s,   "=")) || (STREQ (s,  "!=")) || (STREQ (s, "-nt")) ||
+  return ((STREQ (s,   "=")) || (STREQ (s,  "!=")) || (STREQ (s, "==")) ||
+          (STREQ (s,   "-nt")) ||
           (STREQ (s, "-ot")) || (STREQ (s, "-ef")) || (STREQ (s, "-eq")) ||
           (STREQ (s, "-ne")) || (STREQ (s, "-lt")) || (STREQ (s, "-le")) ||
           (STREQ (s, "-gt")) || (STREQ (s, "-ge")));
@@ -360,7 +361,8 @@
       test_syntax_error (_("unknown binary operator"), argv[op]);
     }
 
-  if (argv[op][0] == '=' && !argv[op][1])
+  if (argv[op][0] == '=' && (!argv[op][1] ||
+       ((argv[op][1] == '=') && !argv[op][2])))
     {
       bool value = STREQ (argv[pos], argv[pos + 2]);
       pos += 3;

--- ./doc/coreutils.texi.orig	2011-03-15 00:49:10.000000000 -0400
+++ ./doc/coreutils.texi	2011-03-15 20:10:44.000000000 -0400
@@ -11535,7 +11535,7 @@
 * File type tests::             -[bcdfhLpSt]
 * Access permission tests::     -[gkruwxOG]
 * File characteristic tests::   -e -s -nt -ot -ef
-* String tests::                -z -n = !=
+* String tests::                -z -n = == !=
 * Numeric tests::               -eq -ne -lt -le -gt -ge
 * Connectives for test::        ! -a -o
 @end menu
@@ -11726,6 +11726,11 @@
 @cindex equal string check
 True if the strings are equal.
 
+@item @var{string1} == @var{string2}
+@opindex ==
+@cindex equal string check
+True if the strings are equal (synonym for =).
+
 @item @var{string1} != @var{string2}
 @opindex !=
 @cindex not-equal string check