2019-07-03 04:59:38 +08:00
|
|
|
# RUN: %fish %s
|
2016-10-04 08:51:27 +08:00
|
|
|
# $XDG_DATA_HOME can itself be a relative path. So force it to an absolute
|
|
|
|
# path so we can remove it from any resolved paths below. This is needed
|
|
|
|
# because the contents of the builtin realpath.out file can't include any $PWD
|
|
|
|
# data since $PWD isn't under our control.
|
|
|
|
set -l data_home_realpath (builtin realpath $XDG_DATA_HOME)
|
|
|
|
|
|
|
|
# A bogus absolute path is handled correctly and sets a failure status.
|
|
|
|
if not builtin realpath /this/better/be/an/invalid/path
|
|
|
|
echo first invalid path handled okay
|
2019-07-03 04:59:38 +08:00
|
|
|
# CHECK: first invalid path handled okay
|
|
|
|
# CHECKERR: builtin realpath: /this/better/be/an/invalid/path: No such file or directory
|
2016-10-04 08:51:27 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# A non-existent file relative to $PWD succeeds.
|
|
|
|
set -l real_path (builtin realpath nonexistent-file)
|
2019-04-05 11:25:45 +08:00
|
|
|
if test "$real_path" = (realpath $PWD)"/nonexistent-file"
|
2016-10-04 08:51:27 +08:00
|
|
|
echo nonexistent-file in PWD correctly converted
|
2019-07-03 04:59:38 +08:00
|
|
|
# CHECK: nonexistent-file in PWD correctly converted
|
2016-10-04 08:51:27 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# The simplest absolute path should undergo no transformation.
|
|
|
|
builtin realpath /
|
2019-07-03 04:59:38 +08:00
|
|
|
# CHECK: /
|
2016-10-04 08:51:27 +08:00
|
|
|
|
|
|
|
# The second simplest absolute path should undergo no transformation.
|
|
|
|
builtin realpath /this-better-not-exist
|
2019-07-03 04:59:38 +08:00
|
|
|
# CHECK: /this-better-not-exist
|
2016-10-04 08:51:27 +08:00
|
|
|
|
|
|
|
# Check that a pathological case is handled correctly (i.e., there is only one
|
|
|
|
# leading slash).
|
|
|
|
builtin realpath /../../x
|
2019-07-03 04:59:38 +08:00
|
|
|
# CHECK: /x
|
2016-10-04 08:51:27 +08:00
|
|
|
|
|
|
|
# Another pathological corner case. GNU realpath first strips trailing slashes
|
|
|
|
# so that "/a//" is converted to "/a" before performing the real path
|
|
|
|
# conversion. So, despite appearances, it considers "a" to be the last
|
|
|
|
# component in that case.
|
|
|
|
builtin realpath /abc/
|
2019-07-03 04:59:38 +08:00
|
|
|
# CHECK: /abc
|
2016-10-04 08:51:27 +08:00
|
|
|
builtin realpath /def///
|
2019-07-03 04:59:38 +08:00
|
|
|
# CHECK: /def
|
2016-10-04 08:51:27 +08:00
|
|
|
|
2018-11-19 00:56:24 +08:00
|
|
|
# Verify `realpath .` when cwd is a deleted directory gives a no such file or dir error.
|
|
|
|
set -l tmpdir (mktemp -d)
|
|
|
|
pushd $tmpdir
|
2019-01-19 05:54:09 +08:00
|
|
|
# Solaris rmdir tries to protect against deleting $PWD.
|
|
|
|
# But that's what we want to test, so we weasel around it.
|
|
|
|
sh -c "cd ..; rmdir $tmpdir"
|
2018-11-19 00:56:24 +08:00
|
|
|
builtin realpath .
|
2019-07-03 04:59:38 +08:00
|
|
|
# CHECKERR: builtin realpath: .: No such file or directory
|
2018-11-19 00:56:24 +08:00
|
|
|
popd
|
|
|
|
|
2016-10-04 08:51:27 +08:00
|
|
|
# A single symlink to a directory is correctly resolved.
|
2019-12-19 02:31:24 +08:00
|
|
|
ln -fs fish $XDG_DATA_HOME/fish-symlink
|
2016-10-04 08:51:27 +08:00
|
|
|
set -l real_path (builtin realpath $XDG_DATA_HOME/fish-symlink)
|
|
|
|
set -l expected_real_path "$data_home_realpath/fish"
|
|
|
|
if test "$real_path" = "$expected_real_path"
|
|
|
|
echo "fish-symlink handled correctly"
|
2019-07-03 04:59:38 +08:00
|
|
|
# CHECK: fish-symlink handled correctly
|
2016-10-04 08:51:27 +08:00
|
|
|
else
|
|
|
|
echo "fish-symlink not handled correctly: $real_path != $expected_real_path" >&2
|
|
|
|
end
|
|
|
|
|
2020-09-13 01:26:04 +08:00
|
|
|
# With "-s" the symlink is not resolved.
|
2020-12-24 15:53:08 +08:00
|
|
|
set -l real_path (builtin realpath -s $data_home_realpath/fish-symlink)
|
|
|
|
set -l expected_real_path "$data_home_realpath/fish-symlink"
|
2020-09-13 01:26:04 +08:00
|
|
|
if test "$real_path" = "$expected_real_path"
|
|
|
|
echo "fish-symlink handled correctly"
|
|
|
|
# CHECK: fish-symlink handled correctly
|
|
|
|
else
|
|
|
|
echo "fish-symlink not handled correctly: $real_path != $expected_real_path" >&2
|
|
|
|
end
|
|
|
|
|
2020-12-24 15:53:08 +08:00
|
|
|
set -l real_path (builtin realpath -s .)
|
2021-08-30 05:10:50 +08:00
|
|
|
set -l expected_real_path (pwd -P) # Physical working directory.
|
2020-12-24 15:53:08 +08:00
|
|
|
if test "$real_path" = "$expected_real_path"
|
|
|
|
echo "relative path correctly handled"
|
|
|
|
# CHECK: relative path correctly handled
|
|
|
|
else
|
|
|
|
echo "relative path not handled correctly: $real_path != $expected_real_path" >&2
|
|
|
|
end
|
|
|
|
|
|
|
|
test (builtin realpath -s /usr/bin/../) = /usr
|
2020-09-13 01:26:04 +08:00
|
|
|
or echo builtin realpath -s does not resolve .. or resolves symlink wrong
|
|
|
|
|
2016-10-04 08:51:27 +08:00
|
|
|
# A nonexistent file relative to a valid symlink to a directory gets converted.
|
|
|
|
# This depends on the symlink created by the previous test.
|
|
|
|
set -l real_path (builtin realpath $XDG_DATA_HOME/fish-symlink/nonexistent-file-relative-to-a-symlink)
|
|
|
|
set -l expected_real_path "$data_home_realpath/fish/nonexistent-file-relative-to-a-symlink"
|
|
|
|
if test "$real_path" = "$expected_real_path"
|
|
|
|
echo "fish-symlink/nonexistent-file-relative-to-a-symlink correctly converted"
|
2019-07-03 04:59:38 +08:00
|
|
|
# CHECK: fish-symlink/nonexistent-file-relative-to-a-symlink correctly converted
|
2016-10-04 08:51:27 +08:00
|
|
|
else
|
|
|
|
echo "failure nonexistent-file-relative-to-a-symlink: $real_path != $expected_real_path" >&2
|
|
|
|
end
|
|
|
|
|
2021-09-09 23:22:14 +08:00
|
|
|
# We remove leading slashes even with "-s".
|
|
|
|
# This is how GNU realpath -s behaves, and also e.g.
|
|
|
|
# how bash normalizes its $PWD.
|
|
|
|
builtin realpath -s ///bin
|
|
|
|
# CHECK: /bin
|
|
|
|
|
|
|
|
builtin realpath -s //bin
|
|
|
|
# CHECK: /bin
|
|
|
|
|
2016-10-04 08:51:27 +08:00
|
|
|
# A path with two symlinks, first to a directory, second to a file, is correctly resolved.
|
2019-12-19 02:31:24 +08:00
|
|
|
ln -fs fish $XDG_DATA_HOME/fish-symlink2
|
2016-10-04 08:51:27 +08:00
|
|
|
touch $XDG_DATA_HOME/fish/real_file
|
2019-12-19 02:31:24 +08:00
|
|
|
ln -fs real_file $XDG_DATA_HOME/fish/symlink_file
|
2016-10-04 08:51:27 +08:00
|
|
|
set -l real_path (builtin realpath $XDG_DATA_HOME/fish-symlink/symlink_file)
|
|
|
|
set -l expected_real_path "$data_home_realpath/fish/real_file"
|
|
|
|
if test "$real_path" = "$expected_real_path"
|
|
|
|
echo "fish-symlink/symlink_file handled correctly"
|
2019-07-03 04:59:38 +08:00
|
|
|
# CHECK: fish-symlink/symlink_file handled correctly
|
2016-10-04 08:51:27 +08:00
|
|
|
else
|
|
|
|
echo "fish-symlink/symlink_file not handled correctly: $real_path != expected_real_path" >&2
|
|
|
|
end
|
|
|
|
|
|
|
|
exit 0
|