X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-remove.c;h=48641321c0b24662931b1fd53be4f08940f48b0c;hb=23eecb48e39afd0d267d64d40ba6bf97aa865e13;hp=787cde26351f6bbd6d80e288fbc18f8649d15bb7;hpb=6ca71ffe395184749d849f5bba4771d6b2fbb7d6;p=gnulib.git diff --git a/tests/test-remove.c b/tests/test-remove.c index 787cde263..48641321c 100644 --- a/tests/test-remove.c +++ b/tests/test-remove.c @@ -1,5 +1,5 @@ /* Tests of remove. - 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,6 +20,9 @@ #include +#include "signature.h" +SIGNATURE_CHECK (remove, int, (char const *)); + #include #include #include @@ -27,29 +30,16 @@ #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-remove.t" int -main () +main (void) { /* Remove any leftovers from a previous partial run. */ - ASSERT (system ("rm -rf " BASE "*") == 0); + ignore_value (system ("rm -rf " BASE "*")); /* Setup. */ ASSERT (mkdir (BASE "dir", 0700) == 0); @@ -87,8 +77,8 @@ main () /* Empty directory. */ errno = 0; - ASSERT (remove (BASE "dir/./") == -1); - ASSERT (errno == EINVAL || errno == EBUSY); + ASSERT (remove (BASE "dir/.//") == -1); + ASSERT (errno == EINVAL || errno == EBUSY || errno == EEXIST); ASSERT (remove (BASE "dir") == 0); /* Test symlink behavior. Specifying trailing slash should remove @@ -96,7 +86,7 @@ main () symlink. */ if (symlink (BASE "dir", BASE "link") != 0) { - fputs ("skipping test: symlinks not supported on this filesystem\n", + fputs ("skipping test: symlinks not supported on this file system\n", stderr); return 77; } @@ -117,6 +107,19 @@ main () ASSERT (S_ISLNK (st.st_mode)); } ASSERT (remove (BASE "link") == 0); + /* Trailing slash on symlink to non-directory is an error. */ + ASSERT (symlink (BASE "loop", BASE "loop") == 0); + errno = 0; + ASSERT (remove (BASE "loop/") == -1); + ASSERT (errno == ELOOP || errno == ENOTDIR); + ASSERT (remove (BASE "loop") == 0); + ASSERT (close (creat (BASE "file", 0600)) == 0); + ASSERT (symlink (BASE "file", BASE "link") == 0); + errno = 0; + ASSERT (remove (BASE "link/") == -1); + ASSERT (errno == ENOTDIR); + ASSERT (remove (BASE "link") == 0); + ASSERT (remove (BASE "file") == 0); return 0; }