From 6c329e8a839c1b5eeaf2e545b4f4084c3a8830f7 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Wed, 13 Apr 2016 17:14:50 -0700 Subject: provide a realpath implementation Not all distros have a `realpath` command. Provide a function that uses the real command if available else use the fish builtin. Fixes #2932 --- tests/fish_realpath.in | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/fish_realpath.in (limited to 'tests/fish_realpath.in') diff --git a/tests/fish_realpath.in b/tests/fish_realpath.in new file mode 100644 index 00000000..f25309c9 --- /dev/null +++ b/tests/fish_realpath.in @@ -0,0 +1,39 @@ +# $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 fish_realpath.out file can't include any $PWD +# data since $PWD isn't under our control. +set -l data_home_realpath (fish_realpath $XDG_DATA_HOME) + +# A bogus absolute path is handled correctly and sets a failure status. +if not fish_realpath /this/better/be/an/invalid/path + echo first invalid path handled okay +end + +# A non-existent file relative to $PWD fails. +fish_realpath nonexistent-file + +# The simplest absolute path should undergo no transformation. +fish_realpath / + +# A single symlink to a directory is correctly resolved. +ln -s fish $XDG_DATA_HOME/fish-symlink +set -l real_path (fish_realpath $XDG_DATA_HOME/fish-symlink) +string replace "$data_home_realpath/" "" $real_path + +# A nonexistent file relative to a valid symlink to a directory fails. +# This depends on the symlink created by the previous test. +set -l real_path (fish_realpath $XDG_DATA_HOME/fish-symlink/nonexistent-file-relative-to-a-symlink) + +# A path with two symlinks, first to a directory, second to a file, is correctly resolved. +ln -s fish $XDG_DATA_HOME/fish-symlink2 +touch $XDG_DATA_HOME/fish/real_file +ln -s real_file $XDG_DATA_HOME/fish/symlink_file +set -l real_path (fish_realpath $XDG_DATA_HOME/fish-symlink/symlink_file) +string replace "$data_home_realpath/" "" $real_path + +# The $PWD should undergo no further transformations because it should already +# be a "realpath". +set -l real_path (fish_realpath $PWD) +string replace $PWD "pwd-resolved-to-itself" $real_path + +exit 0 -- cgit v1.2.3