tests: avoid false failure in tail inotify test
[coreutils.git] / tests / misc / realpath.sh
blobc2c8f0820e443dbe1774b950764f5c67507b1eb4
1 #!/bin/sh
2 # Validate realpath operation
4 # Copyright (C) 2011-2016 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ realpath
22 stat_single=$(stat -c %d:%i /) || framework_failure_
23 stat_double=$(stat -c %d:%i //) || framework_failure_
24 double_slash=//
25 if test x"$stat_single" = x"$stat_double"; then
26 double_slash=/
28 nl='
31 test -d /dev || framework_failure_
33 # Setup dir, file, symlink structure
35 mkdir -p dir1/dir2 || framework_failure_
36 ln -s dir1/dir2 ldir2 || framework_failure_
37 touch dir1/f dir1/dir2/f || framework_failure_
38 ln -s / one || framework_failure_
39 ln -s // two || framework_failure_
40 ln -s /// three || framework_failure_
42 # Basic operation
43 realpath -Pqz . >/dev/null || fail=1
44 # Operand is required
45 returns_ 1 realpath >/dev/null || fail=1
46 returns_ 1 realpath --relative-base . --relative-to . || fail=1
47 returns_ 1 realpath --relative-base . || fail=1
49 # -e --relative-* require directories
50 returns_ 1 realpath -e --relative-to=dir1/f --relative-base=. . || fail=1
51 realpath -e --relative-to=dir1/ --relative-base=. . || fail=1
53 # Note NUL params are unconditionally rejected by canonicalize_filename_mode
54 returns_ 1 realpath -m '' || fail=1
55 returns_ 1 realpath --relative-base= --relative-to=. . || fail=1
57 # symlink resolution
58 this=$(realpath .)
59 test "$(realpath ldir2/..)" = "$this/dir1" || fail=1
60 test "$(realpath -L ldir2/..)" = "$this" || fail=1
61 test "$(realpath -s ldir2)" = "$this/ldir2" || fail=1
63 # relative string handling
64 test $(realpath -m --relative-to=prefix prefixed/1) = '../prefixed/1' || fail=1
65 test $(realpath -m --relative-to=prefixed prefix/1) = '../prefix/1' || fail=1
66 test $(realpath -m --relative-to=prefixed prefixed/1) = '1' || fail=1
68 # Ensure no redundant trailing '/' present, as was the case in v8.15
69 test $(realpath -sm --relative-to=/usr /) = '..' || fail=1
70 # Ensure no redundant leading '../' present, as was the case in v8.15
71 test $(realpath -sm --relative-to=/ /usr) = 'usr' || fail=1
73 # Ensure --relative-base works
74 out=$(realpath -sm --relative-base=/usr --relative-to=/usr /tmp /usr) || fail=1
75 test "$out" = "/tmp$nl." || fail=1
76 out=$(realpath -sm --relative-base=/ --relative-to=/ / /usr) || fail=1
77 test "$out" = ".${nl}usr" || fail=1
78 # --relative-to defaults to the value of --relative-base
79 out=$(realpath -sm --relative-base=/usr /tmp /usr) || fail=1
80 test "$out" = "/tmp$nl." || fail=1
81 out=$(realpath -sm --relative-base=/ / /usr) || fail=1
82 test "$out" = ".${nl}usr" || fail=1
83 # For now, --relative-base must be a prefix of --relative-to, or all output
84 # will be absolute (compare to MacOS 'relpath -d dir start end').
85 out=$(realpath -sm --relative-base=/usr/local --relative-to=/usr \
86 /usr /usr/local) || fail=1
87 test "$out" = "/usr${nl}/usr/local" || fail=1
89 # Ensure // is handled correctly.
90 test "$(realpath / // ///)" = "/$nl$double_slash$nl/" || fail=1
91 test "$(realpath one two three)" = "/$nl$double_slash$nl/" || fail=1
92 out=$(realpath -sm --relative-to=/ / // /dev //dev) || fail=1
93 if test $double_slash = //; then
94 test "$out" = ".$nl//${nl}dev$nl//dev" || fail=1
95 else
96 test "$out" = ".$nl.${nl}dev${nl}dev" || fail=1
98 out=$(realpath -sm --relative-to=// / // /dev //dev) || fail=1
99 if test $double_slash = //; then
100 test "$out" = "/$nl.$nl/dev${nl}dev" || fail=1
101 else
102 test "$out" = ".$nl.${nl}dev${nl}dev" || fail=1
104 out=$(realpath --relative-base=/ --relative-to=// / //) || fail=1
105 if test $double_slash = //; then
106 test "$out" = "/$nl//" || fail=1
107 else
108 test "$out" = ".$nl." || fail=1
111 Exit $fail