X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-unlink.c;h=90de10cfb2fcee6de0aaf335cd679b5a31e7fe79;hb=fa1db0dd22768f09a507674a30beb5b8a87bb35f;hp=5aaa5956cccb8a30c2e219714220a146d21a727c;hpb=4a60ba548bf42233384fa86fd97cf0091514c553;p=gnulib.git diff --git a/tests/test-unlink.c b/tests/test-unlink.c index 5aaa5956c..90de10cfb 100644 --- a/tests/test-unlink.c +++ b/tests/test-unlink.c @@ -1,5 +1,5 @@ /* Tests of unlink. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2013 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,91 +20,30 @@ #include +#include "signature.h" +SIGNATURE_CHECK (unlink, int, (char const *)); + #include #include +#include #include #include #include #include #include "unlinkdir.h" - -#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-unlink.t" +#include "test-unlink.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 (unlink ("") == -1); - ASSERT (errno == ENOENT); - errno = 0; - ASSERT (unlink (BASE "nosuch") == -1); - ASSERT (errno == ENOENT); - errno = 0; - ASSERT (unlink (BASE "nosuch/") == -1); - ASSERT (errno == ENOENT); - /* Resulting errno after directories is rather varied across - implementations (EPERM, EINVAL, EACCES, EBUSY, EISDIR, ENOTSUP); - however, we must be careful to not attempt unlink on a directory - unless we know it must fail. */ - if (cannot_unlink_dir ()) - { - ASSERT (unlink (".") == -1); - ASSERT (unlink ("..") == -1); - ASSERT (unlink ("/") == -1); - ASSERT (unlink (BASE "dir") == -1); - ASSERT (mkdir (BASE "dir1", 0700) == 0); - ASSERT (unlink (BASE "dir1") == -1); - ASSERT (rmdir (BASE "dir1") == 0); - } - errno = 0; - ASSERT (unlink (BASE "dir/file/") == -1); - ASSERT (errno == ENOTDIR); - - /* Test symlink behavior. Specifying trailing slash will attempt - unlink of a directory, so only attempt it if we know it must - fail. */ - if (symlink (BASE "dir", BASE "link") != 0) - { - ASSERT (unlink (BASE "dir/file") == 0); - ASSERT (rmdir (BASE "dir") == 0); - fputs ("skipping test: symlinks not supported on this filesystem\n", - stderr); - return 77; - } - if (cannot_unlink_dir ()) - ASSERT (unlink (BASE "link/") == -1); - ASSERT (unlink (BASE "link") == 0); - ASSERT (symlink (BASE "dir/file", BASE "link") == 0); - /* Order here proves unlink of a symlink does not follow through to - the file. */ - ASSERT (unlink (BASE "link") == 0); - ASSERT (unlink (BASE "dir/file") == 0); - ASSERT (rmdir (BASE "dir") == 0); + ignore_value (system ("rm -rf " BASE "*")); - return 0; + return test_unlink_func (unlink, true); }