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. */
31 # define symlink(a,b) (-1)
34 #define ASSERT(expr) \
39 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
46 #define BASE "test-remove.t"
51 /* Remove any leftovers from a previous partial run. */
52 ASSERT (system ("rm -rf " BASE "*") == 0);
55 ASSERT (mkdir (BASE "dir", 0700) == 0);
56 ASSERT (close (creat (BASE "dir/file", 0600)) == 0);
58 /* Basic error conditions. */
60 ASSERT (remove ("") == -1);
61 ASSERT (errno == ENOENT);
63 ASSERT (remove ("nosuch") == -1);
64 ASSERT (errno == ENOENT);
66 ASSERT (remove ("nosuch/") == -1);
67 ASSERT (errno == ENOENT);
69 ASSERT (remove (".") == -1);
70 ASSERT (errno == EINVAL || errno == EBUSY);
71 /* Resulting errno after ".." or "/" is too varied to test; it is
72 reasonable to see any of EINVAL, EEXIST, ENOTEMPTY, EACCES. */
73 ASSERT (remove ("..") == -1);
74 ASSERT (remove ("/") == -1);
75 ASSERT (remove ("///") == -1);
77 ASSERT (remove (BASE "dir/file/") == -1);
78 ASSERT (errno == ENOTDIR);
80 /* Non-empty directory. */
82 ASSERT (remove (BASE "dir") == -1);
83 ASSERT (errno == EEXIST || errno == ENOTEMPTY);
86 ASSERT (remove (BASE "dir/file") == 0);
88 /* Empty directory. */
90 ASSERT (remove (BASE "dir/./") == -1);
91 ASSERT (errno == EINVAL || errno == EBUSY);
92 ASSERT (remove (BASE "dir") == 0);
94 /* Test symlink behavior. Specifying trailing slash should remove
95 referent directory, or cause ENOTDIR failure, but not touch
97 if (symlink (BASE "dir", BASE "link") != 0)
99 fputs ("skipping test: symlinks not supported on this filesystem\n",
103 ASSERT (mkdir (BASE "dir", 0700) == 0);
105 if (remove (BASE "link/") == 0)
109 ASSERT (stat (BASE "link", &st) == -1);
110 ASSERT (errno == ENOENT);
113 ASSERT (remove (BASE "dir") == 0);
116 ASSERT (lstat (BASE "link", &st) == 0);
117 ASSERT (S_ISLNK (st.st_mode));
119 ASSERT (remove (BASE "link") == 0);