On a recent MSYS2, I see 5 unit test failures:

FAIL: test-error.sh
===================

diff.exe: -: Invalid argument
FAIL test-error.sh (exit status: 1)

FAIL: test-update-copyright.sh
==============================

diff.exe: -: Invalid argument
FAIL test-update-copyright.sh (exit status: 1)

FAIL: test-verror.sh
====================

diff.exe: -: Invalid argument
FAIL test-verror.sh (exit status: 1)

FAIL: test-version-etc.sh
=========================

diff.exe: -: Invalid argument
FAIL test-version-etc.sh (exit status: 1)

FAIL: test-xalloc-die.sh
========================

diff.exe: -: Invalid argument
FAIL test-xalloc-die.sh (exit status: 1)


This patch fixes them, by using a temporary file instead of passing '-'
as argument to 'diff'.


2024-12-22  Bruno Haible  <br...@clisp.org>

        test-framework-sh: Avoid test suite failures on MSYS2.
        * tests/init.sh (compare_) [MSys]: Use a temporary file on MSYS2.
        * tests/test-update-copyright.sh: Use the test framework.
        (compare): Remove function.
        * modules/update-copyright-tests (Depends-on): Add test-framework-sh.

diff --git a/tests/init.sh b/tests/init.sh
index 80931d7c96..bf3ffc249e 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -671,7 +671,28 @@ for diff_opt_ in -u -U3 -c '' no; do
 done
 if test "$diff_opt_" != no; then
   if test -z "$diff_out_"; then
-    compare_ () { LC_ALL=C diff $diff_opt_ "$@"; }
+    # diff on msys2 does not support the '-' argument for denoting stdin.
+    case `(uname -o) 2>/dev/null` in
+      Msys)
+        compare_ ()
+        {
+          if test " $1" = " -"; then
+            cat > '(stdin)'
+            LC_ALL=C diff $diff_opt_ '(stdin)' "$2"
+          elif test " $2" = " -"; then
+            cat > '(stdin)'
+            LC_ALL=C diff $diff_opt_ "$1" '(stdin)'
+          else
+            LC_ALL=C diff $diff_opt_ "$@"
+          fi
+        }
+        ;;
+      *)
+        compare_ ()
+        {
+          LC_ALL=C diff $diff_opt_ "$@"
+        }
+    esac
   else
     compare_ ()
     {
diff --git a/tests/test-update-copyright.sh b/tests/test-update-copyright.sh
index 329b5f7381..a3af0cce0b 100755
--- a/tests/test-update-copyright.sh
+++ b/tests/test-update-copyright.sh
@@ -16,12 +16,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
-diffout=`diff -u /dev/null /dev/null 2>&1`
-if test x"$diffout" = x"" && test $? -eq 0; then
-  compare() { diff -u "$@"; }
-else
-  compare() { cmp "$@"; }
-fi
+. "${srcdir=.}/init.sh"; path_prepend_ .
 
 # Ensure the update-copyright program gets found.
 PATH=$abs_aux_dir:$PATH
diff --git a/modules/update-copyright-tests b/modules/update-copyright-tests
index 3fab6f0689..98a63406fe 100644
--- a/modules/update-copyright-tests
+++ b/modules/update-copyright-tests
@@ -2,6 +2,7 @@ Files:
 tests/test-update-copyright.sh

 Depends-on:
+test-framework-sh

 configure.ac:
 abs_aux_dir=`cd "$ac_aux_dir"; pwd`




Reply via email to