On Tue, Oct 18, 2016 at 6:07 AM, Daiki Ueno <u...@gnu.org> wrote:
> Hello,
>
> Jim Meyering <j...@meyering.net> writes:
>
>> On Sun, Oct 16, 2016 at 5:15 AM, Pádraig Brady <p...@draigbrady.com> wrote:
>>> On 16/10/16 12:55, Bruno Haible wrote:
>>>> Hi,
>>>>
>>>> The 'getprogname' module test fails on Cygwin 2.6, because the returned
>>>> value is "test-getprogname", not "test-getprogname.exe". (On mingw, on the
>>>> other hand, it really is "test-getprogname.exe".)
>
> On a related note, this new test also fails when it is invoked as a
> libtool wrapper script, because of the "lt-" prefix.
>
> $ ./gnulib-tool --create-testdir --dir t --libtool getprogname
> $ cd t && ./configure
> $ sed -i 's/^noinst_LTLIBRARIES +=/lib_LTLIBRARIES =/' gllib/Makefile.am
> $ make && make check
>
> FAIL: test-getprogname
> ======================
>
> lt-test-getprogname: test-getprogname.c:29: main: Assertion `STREQ (p, 
> "test-getprogname" EXEEXT)' failed.
> FAIL test-getprogname (exit status: 134)
>
> Sorry for not providing a patch.  I have no idea how to conditionalize
> this in the test program itself.

Thank you both.
Here is a proposed patch:
From d2ff675b454b75c3901b8ffe01720925df4a54d4 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyer...@fb.com>
Date: Tue, 18 Oct 2016 11:16:01 -0700
Subject: [PATCH] getprogname-tests: handle lt- prefix and .exe suffixes

* modules/getprogname-tests: Depend on c-strcase.
* tests/test-getprogname.c: Include "c-strcase.h".
Remove any "lt-" prefix, and if EXEEXT is nonempty,
remove any case-insensitive-matched suffix.
Reported by Bruno Haible and Daiki Ueno.
---
 ChangeLog                 |  8 ++++++++
 modules/getprogname-tests |  1 +
 tests/test-getprogname.c  | 26 ++++++++++++++++++++++++--
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f28bbb6..c5f3b1f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2016-10-18  Jim Meyering  <meyer...@fb.com>
+
+       getprogname-tests: handle lt- prefix and .exe suffixes
+       * modules/getprogname-tests: Depend on c-strcase.
+       * tests/test-getprogname.c: Include "c-strcase.h".
+       Remove any "lt-" prefix, and if EXEEXT is nonempty,
+       remove any case-insensitive-matched suffix.
+
 2016-10-16  Bruno Haible  <br...@clisp.org>

        Make sure the libunistring detection rejects older versions with a
diff --git a/modules/getprogname-tests b/modules/getprogname-tests
index cbfda75..7340259 100644
--- a/modules/getprogname-tests
+++ b/modules/getprogname-tests
@@ -3,6 +3,7 @@ tests/test-getprogname.c

 Depends-on:
 string
+c-strcase

 configure.ac:

diff --git a/tests/test-getprogname.c b/tests/test-getprogname.c
index 6e3f694..a91b248 100644
--- a/tests/test-getprogname.c
+++ b/tests/test-getprogname.c
@@ -19,13 +19,35 @@
 #include "getprogname.h"
 #include <string.h>
 #include <assert.h>
+#include "c-strcase.h"

 #define STREQ(a, b) (strcmp (a, b) == 0)

 int
 main (void)
 {
-  char const *p = getprogname ();
-  assert (STREQ (p, "test-getprogname" EXEEXT));
+  char const *q = getprogname ();
+  char *p;
+  assert (q);
+  p = strdup (q);
+  assert (p);
+
+  /* Remove any "lt-" prefix.  */
+  size_t p_len = strlen (p);
+  if (3 < p_len && memcmp (p, "lt-", 3) == 0)
+    {
+      p += 3;
+      p_len -= 3;
+    }
+
+  {
+    /* Remove any case-insensitive-matched EXEEXT suffix.  */
+    const size_t exeext_len = sizeof (EXEEXT) - sizeof ("");
+    if (exeext_len && exeext_len < p_len
+        && c_strncasecmp (p + p_len - exeext_len, EXEEXT, exeext_len) == 0)
+      p[p_len - exeext_len] = 0;
+  }
+
+  assert (STREQ (p, "test-getprogname"));
   return 0;
 }
-- 
2.7.4

Reply via email to