2 Copyright (C) 2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */
30 #define ASSERT(expr) \
35 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
42 #define BASE "test-remove.t"
47 /* Remove any leftovers from a previous partial run. */
48 ASSERT (system ("rm -rf " BASE "*") == 0);
51 ASSERT (mkdir (BASE "dir", 0700) == 0);
52 ASSERT (close (creat (BASE "dir/file", 0600)) == 0);
54 /* Basic error conditions. */
56 ASSERT (remove ("") == -1);
57 ASSERT (errno == ENOENT);
59 ASSERT (remove ("nosuch") == -1);
60 ASSERT (errno == ENOENT);
62 ASSERT (remove ("nosuch/") == -1);
63 ASSERT (errno == ENOENT);
65 ASSERT (remove (".") == -1);
66 ASSERT (errno == EINVAL || errno == EBUSY);
67 /* Resulting errno after ".." or "/" is too varied to test; it is
68 reasonable to see any of EINVAL, EEXIST, ENOTEMPTY, EACCES. */
69 ASSERT (remove ("..") == -1);
70 ASSERT (remove ("/") == -1);
71 ASSERT (remove ("///") == -1);
73 ASSERT (remove (BASE "dir/file/") == -1);
74 ASSERT (errno == ENOTDIR);
76 /* Non-empty directory. */
78 ASSERT (remove (BASE "dir") == -1);
79 ASSERT (errno == EEXIST || errno == ENOTEMPTY);
82 ASSERT (remove (BASE "dir/file") == 0);
84 /* Empty directory. */
86 ASSERT (remove (BASE "dir/.//") == -1);
87 ASSERT (errno == EINVAL || errno == EBUSY);
88 ASSERT (remove (BASE "dir") == 0);
90 /* Test symlink behavior. Specifying trailing slash should remove
91 referent directory, or cause ENOTDIR failure, but not touch
93 if (symlink (BASE "dir", BASE "link") != 0)
95 fputs ("skipping test: symlinks not supported on this file system\n",
99 ASSERT (mkdir (BASE "dir", 0700) == 0);
101 if (remove (BASE "link/") == 0)
105 ASSERT (stat (BASE "link", &st) == -1);
106 ASSERT (errno == ENOENT);
109 ASSERT (remove (BASE "dir") == 0);
112 ASSERT (lstat (BASE "link", &st) == 0);
113 ASSERT (S_ISLNK (st.st_mode));
115 ASSERT (remove (BASE "link") == 0);