X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-rmdir.c;h=7b1ef37d5bb8242cbfb427524fbc4d207d709a23;hb=aae58b6f7bd0f7c2f38e05eb005b76c164c5c1f7;hp=b6805e148a768f671225435069d808d055872510;hpb=b433e6454b40de02a3f208a52a4a3813d26a14e8;p=gnulib.git diff --git a/tests/test-rmdir.c b/tests/test-rmdir.c index b6805e148..7b1ef37d5 100644 --- a/tests/test-rmdir.c +++ b/tests/test-rmdir.c @@ -1,5 +1,5 @@ /* Tests of rmdir. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2010 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,106 +20,28 @@ #include +#include "signature.h" +SIGNATURE_CHECK (rmdir, int, (char const *)); + #include #include +#include #include #include #include -#if !HAVE_SYMLINK -# define symlink(a,b) (-1) -#endif - -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ - while (0) +#include "ignore-value.h" +#include "macros.h" #define BASE "test-rmdir.t" +#include "test-rmdir.h" + int -main () +main (void) { /* 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); + ignore_value (system ("rm -rf " BASE "*")); - return 0; + return test_rmdir_func (rmdir, true); }