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. */
29 #define ASSERT(expr) \
34 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
41 #define BASE "test-symlink.t"
46 /* Remove any leftovers from a previous partial run. */
47 ASSERT (system ("rm -rf " BASE "*") == 0);
49 if (symlink ("nowhere", BASE "link1"))
51 fputs ("skipping test: symlinks not supported on this filesystem\n",
56 /* Some systems allow the creation of 0-length symlinks as a synonym
57 for "."; but most reject it. */
59 if (symlink ("", BASE "link2") == -1)
60 ASSERT (errno == ENOENT || errno == EINVAL);
62 ASSERT (unlink (BASE "link2") == 0);
64 /* Sanity checks of failures. */
66 ASSERT (symlink ("nowhere", "") == -1);
67 ASSERT (errno == ENOENT);
69 ASSERT (symlink ("nowhere", ".") == -1);
70 ASSERT (errno == EEXIST || errno == EINVAL);
72 ASSERT (symlink ("somewhere", BASE "link1") == -1);
73 ASSERT (errno == EEXIST);
75 ASSERT (symlink ("nowhere", BASE "link2/") == -1);
76 ASSERT (errno == ENOTDIR || errno == ENOENT);
77 ASSERT (mkdir (BASE "dir", 0700) == 0);
79 ASSERT (symlink ("nowhere", BASE "dir") == -1);
80 ASSERT (errno == EEXIST);
82 ASSERT (symlink ("nowhere", BASE "dir/") == -1);
83 ASSERT (errno == EEXIST);
84 ASSERT (close (creat (BASE "file", 0600)) == 0);
86 ASSERT (symlink ("nowhere", BASE "file") == -1);
87 ASSERT (errno == EEXIST);
89 ASSERT (symlink ("nowhere", BASE "file/") == -1);
90 ASSERT (errno == EEXIST || errno == ENOTDIR);
92 ASSERT (rmdir (BASE "dir") == 0);
93 ASSERT (unlink (BASE "file") == 0);
94 ASSERT (unlink (BASE "link1") == 0);