openat-tests: ensure unlinkat behaves like rmdir
[gnulib.git] / tests / test-rmdir.c
index b6805e1..6d55ea9 100644 (file)
 
 #define BASE "test-rmdir.t"
 
+#include "test-rmdir.h"
+
 int
 main ()
 {
-  /* Remove any leftovers from a previous partial run.  */
-  ASSERT (system ("rm -rf " BASE "*") == 0);
-
-  /* Setup.  */
-  ASSERT (mkdir (BASE "dir", 0700) == 0);
-  ASSERT (close (creat (BASE "dir/file", 0600)) == 0);
-
-  /* Basic error conditions.  */
-  errno = 0;
-  ASSERT (rmdir ("") == -1);
-  ASSERT (errno == ENOENT);
-  errno = 0;
-  ASSERT (rmdir (BASE "nosuch") == -1);
-  ASSERT (errno == ENOENT);
-  errno = 0;
-  ASSERT (rmdir (BASE "nosuch/") == -1);
-  ASSERT (errno == ENOENT);
-  errno = 0;
-  ASSERT (rmdir (".") == -1);
-  ASSERT (errno == EINVAL || errno == EBUSY);
-  /* Resulting errno after ".." or "/" is too varied to test; it is
-     reasonable to see any of EINVAL, EBUSY, EEXIST, ENOTEMPTY,
-     EACCES, EPERM.  */
-  ASSERT (rmdir ("..") == -1);
-  ASSERT (rmdir ("/") == -1);
-  ASSERT (rmdir ("///") == -1);
-  errno = 0;
-  ASSERT (rmdir (BASE "dir/file/") == -1);
-  ASSERT (errno == ENOTDIR);
-
-  /* Non-empty directory.  */
-  errno = 0;
-  ASSERT (rmdir (BASE "dir") == -1);
-  ASSERT (errno == EEXIST || errno == ENOTEMPTY);
-
-  /* Non-directory.  */
-  errno = 0;
-  ASSERT (rmdir (BASE "dir/file") == -1);
-  ASSERT (errno == ENOTDIR);
-
-  /* Empty directory.  */
-  ASSERT (unlink (BASE "dir/file") == 0);
-  errno = 0;
-  ASSERT (rmdir (BASE "dir/./") == -1);
-  ASSERT (errno == EINVAL || errno == EBUSY);
-  ASSERT (rmdir (BASE "dir") == 0);
-
-  /* Test symlink behavior.  Specifying trailing slash should remove
-     referent directory (POSIX), or cause ENOTDIR failure (Linux), but
-     not touch symlink.  We prefer the Linux behavior for its
-     intuitiveness (especially compared to rmdir("symlink-to-file/")),
-     but not enough to penalize POSIX systems with an rpl_rmdir.  */
-  if (symlink (BASE "dir", BASE "link") != 0)
-    {
-      fputs ("skipping test: symlinks not supported on this filesystem\n",
-             stderr);
-      return 77;
-    }
-  ASSERT (mkdir (BASE "dir", 0700) == 0);
-  errno = 0;
-  if (rmdir (BASE "link/") == 0)
-    {
-      struct stat st;
-      errno = 0;
-      ASSERT (stat (BASE "link", &st) == -1);
-      ASSERT (errno == ENOENT);
-    }
-  else
-    {
-      ASSERT (errno == ENOTDIR);
-      ASSERT (rmdir (BASE "dir") == 0);
-    }
-  ASSERT (unlink (BASE "link") == 0);
-
-  return 0;
+  return test_rmdir_func (rmdir);
 }