These two patches fix the last remaining test failures in the
gnulib-tool test suite.

The first patch addresses this:

$ env GNULIB_TOOL_IMPL=py ./test-extract-tests-module-3.sh 
cmp: EOF on ./test-extract-tests-module-3.output which is empty
--- ./test-extract-tests-module-3.output        2024-03-31 23:53:29.037177133 
-0700
+++ tmp605976-out       2024-04-01 01:44:05.294358174 -0700
@@ -0,0 +1 @@
+string-tests
FAIL: gnulib-tool's output has unexpected differences.

This fails because when given a test module gnulib-tool.sh and
gnulib-tool.py disagree on what to look up.

This:

    gnulib-tool.sh --extract-tests-module string-tests

looks up 'string-tests-tests'. In other words the test of the test of
the string module. :)

But this:

    gnulib-tool.py --extract-tests-module string-tests

looks up the 'string-tests' and prints it back to the user. This diff
should fix it:

diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index 0d791fb664..ba92d8a933 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -308,10 +308,7 @@ class GLModule(object):
 
     def getTestsName(self) -> str:
         '''Return -tests version of the module name.'''
-        result = self.getName()
-        if not result.endswith('-tests'):
-            result += '-tests'
-        return result
+        return f'{self.name}-tests'

The only other place this is used is
GLModuleTable.transitive_closure() and it doesn't seem like this
change breaks anything there.

After this change, the test fails for the same reason as the other
failing test:

$ env GNULIB_TOOL_IMPL=py ./test-extract-tests-module-2.sh 
gnulib-tool: warning: file savewd-tests does not exist
FAIL: gnulib-tool succeeded but printed warnings.

$ env GNULIB_TOOL_IMPL=py ./test-extract-tests-module-3.sh 
gnulib-tool: warning: file string-tests-tests does not exist
FAIL: gnulib-tool succeeded but printed warnings.

When given "$module" gnulib-tool.sh looksup $module, applying any
diff's in the process. Then it only verifies the "$module-tests"
description exists. This differs from gnulib-tool.py which performs
the lookup and patching process to both "$module" and "$module-tests".
Consequently, errors and/or warnings occur when a test module is not
found, as seen in those test cases.

This diff fixes it:

diff --git a/pygnulib/main.py b/pygnulib/main.py
index 688ab249f3..55d635d074 100644
--- a/pygnulib/main.py
+++ b/pygnulib/main.py
@@ -1268,9 +1268,8 @@ def main() -> None:
         modulesystem = classes.GLModuleSystem(config)
         for name in modules:
             module = modulesystem.find(name)
-            if module:
-                if module.getTestsModule():
-                    print(module.getTestsName())
+            if module and modulesystem.exists(module.getTestsName()):
+                print(module.getTestsName())
 
     elif mode == 'copy-file':
         srcpath = files[0]

Also, notice that "module != None" would break another test case
there (see GLModule.__ne__):

$ env GNULIB_TOOL_IMPL=py ./test-extract-tests-module-1.sh 
cmp: EOF on tmp608964-out which is empty
--- ./test-extract-tests-module-1.output        2024-03-31 23:53:29.037177133 
-0700
+++ tmp608964-out       2024-04-01 02:07:11.192876681 -0700
@@ -1 +0,0 @@
-string-tests
FAIL: gnulib-tool's output has unexpected differences.

Collin
From e60b3061664938559ae7ef561d3b11f87130c21a Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Mon, 1 Apr 2024 01:18:17 -0700
Subject: [PATCH 1/2] gnulib-tool.py: Fix --extract-tests-module with a test
 module.

* pygnulib/GLModuleSystem.py (GLModule.getTestsName): Return the module
name with '-tests' appended to it unconditionally.
---
 ChangeLog                  | 6 ++++++
 pygnulib/GLModuleSystem.py | 5 +----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5381e276c6..056f8827dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-04-01  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Fix --extract-tests-module with a test module.
+	* pygnulib/GLModuleSystem.py (GLModule.getTestsName): Return the module
+	name with '-tests' appended to it unconditionally.
+
 2024-03-31  Collin Funk  <collin.fu...@gmail.com>
 
 	gnulib-tool.py: Use case-sensitive sorting for files.
diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index 0d791fb664..ba92d8a933 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -308,10 +308,7 @@ class GLModule(object):
 
     def getTestsName(self) -> str:
         '''Return -tests version of the module name.'''
-        result = self.getName()
-        if not result.endswith('-tests'):
-            result += '-tests'
-        return result
+        return f'{self.name}-tests'
 
     def getTestsModule(self) -> GLModule | None:
         '''Return -tests version of the module as GLModule.'''
-- 
2.44.0

From ed6d4e855f1e06fc81ac31060be6cb61f23ba965 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Mon, 1 Apr 2024 01:40:01 -0700
Subject: [PATCH 2/2] gnulib-tool.py: Only check existence for
 --extract-tests-module.

* pygnulib/main.py (main): Check that the test module exists instead of
looking it up and patching it if diff's are found.
---
 ChangeLog        | 6 ++++++
 pygnulib/main.py | 5 ++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 056f8827dc..95b034ca21 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-04-01  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Only check existence for --extract-tests-module.
+	* pygnulib/main.py (main): Check that the test module exists instead of
+	looking it up and patching it if diff's are found.
+
 2024-04-01  Collin Funk  <collin.fu...@gmail.com>
 
 	gnulib-tool.py: Fix --extract-tests-module with a test module.
diff --git a/pygnulib/main.py b/pygnulib/main.py
index 688ab249f3..55d635d074 100644
--- a/pygnulib/main.py
+++ b/pygnulib/main.py
@@ -1268,9 +1268,8 @@ def main() -> None:
         modulesystem = classes.GLModuleSystem(config)
         for name in modules:
             module = modulesystem.find(name)
-            if module:
-                if module.getTestsModule():
-                    print(module.getTestsName())
+            if module and modulesystem.exists(module.getTestsName()):
+                print(module.getTestsName())
 
     elif mode == 'copy-file':
         srcpath = files[0]
-- 
2.44.0

Reply via email to