Mercurial > hg > octave-shane > gnulib-hg
annotate tests/test-remove.c @ 12496:a48d3d749ca5
Refactor common macros used in tests.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Thu, 24 Dec 2009 21:01:42 +0100 |
parents | 33ab12a7cea2 |
children | 013b270a78b9 |
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. |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
2 Copyright (C) 2009 Free Software Foundation, Inc. |
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 |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12489
diff
changeset
|
33 #include "macros.h" |
12041
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
34 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
35 #define BASE "test-remove.t" |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
36 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
37 int |
12197
e45d9bb2233e
tests: avoid several compiler warnings
Eric Blake <ebb9@byu.net>
parents:
12146
diff
changeset
|
38 main (void) |
12041
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
39 { |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
40 /* Remove any leftovers from a previous partial run. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
41 ASSERT (system ("rm -rf " BASE "*") == 0); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
42 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
43 /* Setup. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
44 ASSERT (mkdir (BASE "dir", 0700) == 0); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
45 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
|
46 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
47 /* Basic error conditions. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
48 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
49 ASSERT (remove ("") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
50 ASSERT (errno == ENOENT); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
51 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
52 ASSERT (remove ("nosuch") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
53 ASSERT (errno == ENOENT); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
54 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
55 ASSERT (remove ("nosuch/") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
56 ASSERT (errno == ENOENT); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
57 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
58 ASSERT (remove (".") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
59 ASSERT (errno == EINVAL || errno == EBUSY); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
60 /* 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
|
61 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
|
62 ASSERT (remove ("..") == -1); |
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 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
66 ASSERT (remove (BASE "dir/file/") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
67 ASSERT (errno == ENOTDIR); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
68 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
69 /* Non-empty directory. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
70 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
71 ASSERT (remove (BASE "dir") == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
72 ASSERT (errno == EEXIST || errno == ENOTEMPTY); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
73 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
74 /* Non-directory. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
75 ASSERT (remove (BASE "dir/file") == 0); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
76 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
77 /* Empty directory. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
78 errno = 0; |
12084
34277de50e87
tests: tighten link, rmdir, and remove tests
Eric Blake <ebb9@byu.net>
parents:
12057
diff
changeset
|
79 ASSERT (remove (BASE "dir/.//") == -1); |
12041
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
80 ASSERT (errno == EINVAL || errno == EBUSY); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
81 ASSERT (remove (BASE "dir") == 0); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
82 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
83 /* 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
|
84 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
|
85 symlink. */ |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
86 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
|
87 { |
12146
e076a06bae48
maint: prefer 'file system' over 'filesystem'
Eric Blake <ebb9@byu.net>
parents:
12084
diff
changeset
|
88 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
|
89 stderr); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
90 return 77; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
91 } |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
92 ASSERT (mkdir (BASE "dir", 0700) == 0); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
93 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
94 if (remove (BASE "link/") == 0) |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
95 { |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
96 struct stat st; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
97 errno = 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
98 ASSERT (stat (BASE "link", &st) == -1); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
99 ASSERT (errno == ENOENT); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
100 } |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
101 else |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
102 ASSERT (remove (BASE "dir") == 0); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
103 { |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
104 struct stat st; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
105 ASSERT (lstat (BASE "link", &st) == 0); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
106 ASSERT (S_ISLNK (st.st_mode)); |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
107 } |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
108 ASSERT (remove (BASE "link") == 0); |
12262
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
109 /* 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
|
110 ASSERT (symlink (BASE "loop", BASE "loop") == 0); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
111 errno = 0; |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
112 ASSERT (remove (BASE "loop/") == -1); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
113 ASSERT (errno == ELOOP || errno == ENOTDIR); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
114 ASSERT (remove (BASE "loop") == 0); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
115 ASSERT (close (creat (BASE "file", 0600)) == 0); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
116 ASSERT (symlink (BASE "file", BASE "link") == 0); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
117 errno = 0; |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
118 ASSERT (remove (BASE "link/") == -1); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
119 ASSERT (errno == ENOTDIR); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
120 ASSERT (remove (BASE "link") == 0); |
29121a37225b
unlink, remove: detect FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
12197
diff
changeset
|
121 ASSERT (remove (BASE "file") == 0); |
12041
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
122 |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
123 return 0; |
73e9ab6e2c90
remove: new module, for mingw and Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
124 } |