Skip test when a hard link cannot be created.
authorBruno Haible <bruno@clisp.org>
Tue, 20 Jan 2009 00:21:30 +0000 (01:21 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 20 Jan 2009 00:27:11 +0000 (01:27 +0100)
ChangeLog
tests/test-link.c
tests/test-link.sh

index b2a59dd..f77389c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-01-19  Bruno Haible  <bruno@clisp.org>
+
+       * tests/test-link.c: Include <errno.h>.
+       (main): Exit with code 77 when a hard link cannot be created due to
+       the file system.
+       * tests/test-link.sh: Skip test when a hard link cannot be created due
+       to the file system.
+       Suggested by Eric Blake.
+
 2009-01-19  Martin Lambers  <marlam@marlam.de>
 
        * modules/link-tests: New file.
index 255a939..a358921 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <unistd.h>
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 
 int
 main (int argc, char **argv)
 {
+  int ret;
+
   ASSERT (argc == 3);
-  ASSERT (link (argv[1], argv[2]) == 0);
+
+  ret = link (argv[1], argv[2]);
+  if (ret < 0)
+    {
+      /* If the device does not support hard links, errno is
+        EPERM on Linux, EOPNOTSUPP on FreeBSD.  */
+      if (errno == EPERM || errno == EOPNOTSUPP)
+       return 77;
+      perror ("link");
+      return 1;
+    }
 
   return 0;
 }
index e18bb63..1519f9d 100755 (executable)
@@ -7,7 +7,16 @@ trap 'rm -fr $tmpfiles' 1 2 3 15
 echo "hello" > test-link-a.txt || exit 1
 
 # Use link() to create a new name for it.
-./test-link${EXEEXT} test-link-a.txt test-link-b.txt || exit 1
+./test-link${EXEEXT} test-link-a.txt test-link-b.txt
+case $? in
+  0) ;;
+  77)
+    echo "Skipping test: hard links are not supported on this file system"
+    rm -fr $tmpfiles
+    exit 77
+    ;;
+  *) exit 1 ;;
+esac
 cmp test-link-a.txt test-link-b.txt || exit 1
 
 # Modify the contents of the first file.