aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-04-13 17:14:50 -0700
committerGravatar Kurtis Rader <krader@skepticism.us>2016-04-28 16:03:27 -0700
commit6c329e8a839c1b5eeaf2e545b4f4084c3a8830f7 (patch)
tree65597d006e0cd94e9f74b95b67c75451b2daecd8 /tests
parent5fa8370c133738aa21a3b4a7d3a89f9188068498 (diff)
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
Diffstat (limited to 'tests')
-rw-r--r--tests/fish_realpath.err3
-rw-r--r--tests/fish_realpath.in39
-rw-r--r--tests/fish_realpath.out5
-rw-r--r--tests/fish_realpath.status1
4 files changed, 48 insertions, 0 deletions
diff --git a/tests/fish_realpath.err b/tests/fish_realpath.err
new file mode 100644
index 00000000..f12c3618
--- /dev/null
+++ b/tests/fish_realpath.err
@@ -0,0 +1,3 @@
+fish_realpath: Invalid path: /this/better/be/an/invalid/path
+fish_realpath: Invalid path: nonexistent-file
+fish_realpath: Invalid path: ../test/data/fish-symlink/nonexistent-file-relative-to-a-symlink
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
diff --git a/tests/fish_realpath.out b/tests/fish_realpath.out
new file mode 100644
index 00000000..d14bca83
--- /dev/null
+++ b/tests/fish_realpath.out
@@ -0,0 +1,5 @@
+first invalid path handled okay
+/
+fish
+fish/real_file
+pwd-resolved-to-itself
diff --git a/tests/fish_realpath.status b/tests/fish_realpath.status
new file mode 100644
index 00000000..573541ac
--- /dev/null
+++ b/tests/fish_realpath.status
@@ -0,0 +1 @@
+0