Mercurial > hg > octave-shane > gnulib-hg
annotate tests/test-remove.c @ 17530:8981b79e1271
error: make the module depend on vfprintf-posix
* modules/error (Depends-on): Add vfprintf-posix, since error
calls vfprintf unconditionally, via error_tail.
author | Jim Meyering <meyering@fb.com> |
---|---|
date | Sat, 12 Oct 2013 19:28:40 -0700 |
parents | e542fd46ad6f |
children | 344018b6e5d7 |
rev | line source |
---|---|
12041
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
1 /* Tests of remove. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
2 Copyright (C) 2009-2013 Free Software Foundation, Inc. |
12041
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
3 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
7 (at your option) any later version. |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
8 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
13 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
16 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
18 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
19 #include <config.h> |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
20 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
21 #include <stdio.h> |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
22 |
12489 | 23 #include "signature.h" |
24 SIGNATURE_CHECK (remove, int, (char const *)); | |
25 | |
12041
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
26 #include <fcntl.h> |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
27 #include <errno.h> |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
28 #include <stdlib.h> |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
29 #include <string.h> |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
30 #include <sys/stat.h> |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
31 #include <unistd.h> |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
32 |
12842
b2bf8684a2db
tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents:
12559
diff
changeset
|
33 #include "ignore-value.h" |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12489
diff
changeset
|
34 #include "macros.h" |
12041
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
35 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
36 #define BASE "test-remove.t" |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
37 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
38 int |
12197
e45d9bb2233e
tests: avoid several compiler warnings
Eric Blake <ebb9@byu.net>
parents:
12146
diff
changeset
|
39 main (void) |
12041
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
40 { |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
41 /* Remove any leftovers from a previous partial run. */ |
12842
b2bf8684a2db
tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents:
12559
diff
changeset
|
42 ignore_value (system ("rm -rf " BASE "*")); |
12041
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
43 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
44 /* Setup. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
45 ASSERT (mkdir (BASE "dir", 0700) == 0); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
46 ASSERT (close (creat (BASE "dir/file", 0600)) == 0); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
47 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
48 /* Basic error conditions. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
49 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
50 ASSERT (remove ("") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
51 ASSERT (errno == ENOENT); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
52 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
53 ASSERT (remove ("nosuch") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
54 ASSERT (errno == ENOENT); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
55 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
56 ASSERT (remove ("nosuch/") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
57 ASSERT (errno == ENOENT); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
58 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
59 ASSERT (remove (".") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
60 ASSERT (errno == EINVAL || errno == EBUSY); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
61 /* Resulting errno after ".." or "/" is too varied to test; it is |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
62 reasonable to see any of EINVAL, EEXIST, ENOTEMPTY, EACCES. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
63 ASSERT (remove ("..") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
64 ASSERT (remove ("/") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
65 ASSERT (remove ("///") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
66 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
67 ASSERT (remove (BASE "dir/file/") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
68 ASSERT (errno == ENOTDIR); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
69 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
70 /* Non-empty directory. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
71 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
72 ASSERT (remove (BASE "dir") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
73 ASSERT (errno == EEXIST || errno == ENOTEMPTY); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
74 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
75 /* Non-directory. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
76 ASSERT (remove (BASE "dir/file") == 0); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
77 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
78 /* Empty directory. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
79 errno = 0; |
12084
34277de50e87
tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents:
12057
diff
changeset
|
80 ASSERT (remove (BASE "dir/.//") == -1); |
14144
a0e5b3297968
remove test: Avoid failure on HP-UX 11.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
81 ASSERT (errno == EINVAL || errno == EBUSY || errno == EEXIST); |
12041
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
82 ASSERT (remove (BASE "dir") == 0); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
83 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
84 /* Test symlink behavior. Specifying trailing slash should remove |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
85 referent directory, or cause ENOTDIR failure, but not touch |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
86 symlink. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
87 if (symlink (BASE "dir", BASE "link") != 0) |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
88 { |
12146
e076a06bae48
maint: prefer 'file system' over 'filesystem'
Eric Blake <ebb9@byu.net>
parents:
12084
diff
changeset
|
89 fputs ("skipping test: symlinks not supported on this file system\n", |
12041
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
90 stderr); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
91 return 77; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
92 } |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
93 ASSERT (mkdir (BASE "dir", 0700) == 0); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
94 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
95 if (remove (BASE "link/") == 0) |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
96 { |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
97 struct stat st; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
98 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
99 ASSERT (stat (BASE "link", &st) == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
100 ASSERT (errno == ENOENT); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
101 } |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
102 else |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
103 ASSERT (remove (BASE "dir") == 0); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
104 { |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
105 struct stat st; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
106 ASSERT (lstat (BASE "link", &st) == 0); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
107 ASSERT (S_ISLNK (st.st_mode)); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
108 } |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
109 ASSERT (remove (BASE "link") == 0); |
12262
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
110 /* Trailing slash on symlink to non-directory is an error. */ |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
111 ASSERT (symlink (BASE "loop", BASE "loop") == 0); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
112 errno = 0; |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
113 ASSERT (remove (BASE "loop/") == -1); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
114 ASSERT (errno == ELOOP || errno == ENOTDIR); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
115 ASSERT (remove (BASE "loop") == 0); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
116 ASSERT (close (creat (BASE "file", 0600)) == 0); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
117 ASSERT (symlink (BASE "file", BASE "link") == 0); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
118 errno = 0; |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
119 ASSERT (remove (BASE "link/") == -1); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
120 ASSERT (errno == ENOTDIR); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
121 ASSERT (remove (BASE "link") == 0); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
122 ASSERT (remove (BASE "file") == 0); |
12041
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
123 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
124 return 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
125 } |