Subject: bug#10441: The testsuite assumes that ln -s really creates a symlink

From: Stefano Lattarini <[email-masked]>
Date: Sun, 08 Jan 2012 13:56:36 +0100

On 01/05/2012 11:13 PM, Peter Rosin wrote:
> Hi!
Hi Peter, thanks for the report.

> "ln -s" on MSYS does not create a symlink, instead it makes a
> regular copy.  Lots of test cases (on master) FAIL due to this.
> 
> "test -h foo" will simply not return success on MSYS, ever.
> 
> Affected tests (that I have noticed):
> add-missing.tap (lots of failing test cases)
> copy.test
> 
The attached patch should take care of the problem.  Tested using
this script in PATH as the `ln' program:

  #!/bin/bash
  declare -a args=()
  for i in "$@"; do
    test x"$i" = x"-s" && continue
    args=("${args[@]}" "$i")
  done
  exec /bin/ln "${args[@]}"

I will push after your ACK or in 48 hours, whichever comes first.

Regards,
  Stefano
>From 7fe475b6ef6dd3e55f609e80f4c203d99c3890c5 Mon Sep 17 00:00:00 2001
Message-Id: <7fe475b6e[email-masked]>
From: Stefano Lattarini <[email-masked]>
Date: Sun, 8 Jan 2012 13:36:46 +0100
Subject: [PATCH] tests: avoid many spurious failures on MSYS due to lack of
 symlinks

Fixes automake bug#10441.

* tests/add-missing.tap: Do not assume the system supports real
symlinks, as this is not the case for MinGW/MSYS.  Skip checks
that would spuriously fail in that situation.
* tests/copy.test: Likewise.

Reported by Peter Rosin.
---
 tests/add-missing.tap |   39 ++++++++++++++++++++++++++++-----------
 tests/copy.test       |   29 +++++++++++++++++++++--------
 2 files changed, 49 insertions(+), 19 deletions(-)

diff --git a/tests/add-missing.tap b/tests/add-missing.tap
index 36f7676..4f5d682 100755
--- a/tests/add-missing.tap
+++ b/tests/add-missing.tap
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2011 Free Software Foundation, Inc.
+# Copyright (C) 2011, 2012 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -36,6 +36,16 @@ else
   am_diff=diff
 fi
 
+# MinGW/MSYS lacks real symlinks, so we'll have to skip some checks
+# on that system.  More details below.
+echo dummy > foo
+if ln -s foo bar && test -h bar; then
+  have_true_symlinks=yes
+else
+  have_true_symlinks=no
+fi
+rm -f foo bar
+
 cat > configure.stub << END
 AC_INIT([$me], [1.0])
 AC_CONFIG_AUX_DIR([$build_aux])
@@ -195,19 +205,26 @@ check_ ()
       "$pfx all and only expected files installed" \
       $am_diff files.exp files.got
     # The files should be copied by `--copy' and symlinked otherwise.
+    # But these checks make no sense on systems like MSYS/MinGW where
+    # there are no true symlinks ('ln -s' behaves like 'cp -p'), so be
+    # ready to skip the checks in that case.  See automake bug#10441.
     for f in $files; do
-      if test -h $build_aux/$f; then
-        is_symlink=yes
+      if test $have_true_symlinks = no; then
+        skip_ -r "system lacks true symlinks" "$pfx $f is a symlink or not"
       else
-        is_symlink=no
+        if test -h $build_aux/$f; then
+          is_symlink=yes
+        else
+          is_symlink=no
+        fi
+        case $action,$is_symlink in
+          link,yes)     ok_ "$pfx $f has been symlinked"     ;;
+           link,no) not_ok_ "$pfx $f has not been symlinked" ;;
+          copy,yes) not_ok_ "$pfx $f has been symlinked"     ;;
+           copy,no)     ok_ "$pfx $f has not been symlinked" ;;
+                 *)  fatal_ "invalid condition in case"      ;;
+        esac
       fi
-      case $action,$is_symlink in
-        link,yes)     ok_ "$pfx $f has been symlinked"     ;;
-         link,no) not_ok_ "$pfx $f has not been symlinked" ;;
-        copy,yes) not_ok_ "$pfx $f has been symlinked"     ;;
-         copy,no)     ok_ "$pfx $f has not been symlinked" ;;
-               *)  fatal_ "invalid condition in case"      ;;
-      esac
     done
     # Now that the required auxiliary files have been installed, automake
     # should not complain anymore even if the `--add-missing' option is
diff --git a/tests/copy.test b/tests/copy.test
index 8ad3f2a..d8aa090 100755
--- a/tests/copy.test
+++ b/tests/copy.test
@@ -1,6 +1,6 @@
 #! /bin/sh
-# Copyright (C) 1999, 2001, 2002, 2010, 2011 Free Software Foundation,
-# Inc.
+# Copyright (C) 1999, 2001, 2002, 2010, 2011, 2012 Free Software
+# Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -20,6 +20,19 @@
 
 . ./defs || Exit 1
 
+# We'll have to cater to systems like MSYS/MinGW where there are no
+# true symlinks ('ln -s' behaves like 'cp -p'); see automake bug#10441.
+
+echo dummy > foo
+if ln -s foo bar && test -h bar; then
+  is_symlink () { test -h "$1"; }
+  is_not_symlink () { test ! -h "$1"; }
+else
+  is_symlink () { return 0; } # Avoid spurious failures.
+  is_not_symlink () { return 0; }
+fi
+rm -f foo bar
+
 # First a simple test, where the auxdir is automatically determined
 # by automake.
 
@@ -31,7 +44,7 @@ $AUTOMAKE -c -a
 ls -l # For debugging.
 
 test -f install-sh
-test ! -h install-sh
+is_not_symlink install-sh
 
 # Let's do a couple of more elaborated tests, this time with the auxdir
 # explicitly defined in configure.in.
@@ -62,9 +75,9 @@ echo FAKE-DEPCOMP > auxdir/depcomp
 $AUTOMAKE -a
 ls -l auxdir # For debugging.
 test -f auxdir/install-sh
-test -h auxdir/install-sh
+is_symlink auxdir/install-sh
 test -f auxdir/depcomp
-test ! -h auxdir/depcomp
+is_not_symlink auxdir/depcomp
 test FAKE-DEPCOMP = `cat auxdir/depcomp`
 
 # `automake -a -c' should not create symlinks, even when there are
@@ -79,11 +92,11 @@ cd ..
 $AUTOMAKE -a -c
 ls -l auxdir # For debugging.
 test -f auxdir/install-sh
-test -h auxdir/install-sh
+is_symlink auxdir/install-sh
 test -f auxdir/missing
-test -h auxdir/missing
+is_symlink auxdir/missing
 test -f auxdir/depcomp
-test ! -h auxdir/depcomp
+is_not_symlink auxdir/depcomp
 diff "$am_scriptdir"/depcomp auxdir/depcomp
 
 :
-- 
1.7.7.3