X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-remove.c;h=870878e751fd72ef09db3659ea382ccc30a67b41;hb=41d7de2bc881ddb3ce8a8a40552724ebb893108a;hp=c084d8c656616d6c55d6052ee2f99859f3fbb812;hpb=0f4fd7f4782907e0a308a077118c6578fff4e49f;p=gnulib.git diff --git a/tests/test-remove.c b/tests/test-remove.c index c084d8c65..870878e75 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, 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,6 +20,9 @@ #include +#include "signature.h" +SIGNATURE_CHECK (remove, int, (char const *)); + #include #include #include @@ -27,25 +30,15 @@ #include #include -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ - while (0) +#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); + system ("rm -rf " BASE "*"); /* Setup. */ ASSERT (mkdir (BASE "dir", 0700) == 0); @@ -92,7 +85,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; } @@ -113,6 +106,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; }