fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

NahorFix failing system tests on Cygwin440e7fcbc

master
5.8 KiB161 linesraw
1# RUN: %fish %s
2
3cygwin_nosymlinks && set nosymlinks
4
5# $XDG_DATA_HOME can itself be a relative path. So force it to an absolute
6# path so we can remove it from any resolved paths below. This is needed
7# because the contents of the builtin realpath.out file can't include any $PWD
8# data since $PWD isn't under our control.
9set -l data_home_realpath (builtin realpath $XDG_DATA_HOME)
10
11# A bogus absolute path is handled correctly and sets a failure status.
12if not builtin realpath /this/better/be/an/invalid/path
13    echo first invalid path handled okay
14    # CHECK: first invalid path handled okay
15    # CHECKERR: realpath: /this/better/be/an/invalid/path: No such file or directory
16end
17
18# A non-existent file relative to $PWD succeeds.
19set -l real_path (builtin realpath nonexistent-file)
20if test "$real_path" = (realpath $PWD)"/nonexistent-file"
21    echo nonexistent-file in PWD correctly converted
22    # CHECK: nonexistent-file in PWD correctly converted
23end
24
25# The simplest absolute path should undergo no transformation.
26builtin realpath /
27# CHECK: /
28
29# The second simplest absolute path should undergo no transformation.
30builtin realpath /this-better-not-exist
31# CHECK: /this-better-not-exist
32
33# Check that a pathological case is handled correctly (i.e., there is only one
34# leading slash).
35builtin realpath /../../x
36# CHECK: /x
37
38# Another pathological corner case. GNU realpath first strips trailing slashes
39# so that "/a//" is converted to "/a" before performing the real path
40# conversion. So, despite appearances, it considers "a" to be the last
41# component in that case.
42builtin realpath /abc/
43# CHECK: /abc
44builtin realpath /def///
45# CHECK: /def
46
47# Verify `realpath .` when cwd is a deleted directory gives a no such file or dir error.
48set -l tmpdir (mktemp -d)
49pushd $tmpdir
50mkdir subdir
51cd subdir
52# Solaris rmdir tries to protect against deleting $PWD.
53# But that's what we want to test, so we weasel around it.
54sh -c "cd ../..; rmdir $tmpdir/subdir $tmpdir"
55builtin realpath .
56# CHECKERR: realpath: .: No such file or directory
57builtin realpath -s .
58# CHECKERR: realpath: realpath failed: No such file or directory
59popd
60
61# A single symlink to a directory is correctly resolved.
62ln -fs fish $XDG_DATA_HOME/fish-symlink
63set -l real_path (builtin realpath $XDG_DATA_HOME/fish-symlink)
64set -l expected_real_path "$data_home_realpath/fish"
65if set -q nosymlinks
66    echo "fish-symlink handled correctly"
67else if test "$real_path" = "$expected_real_path"
68    echo "fish-symlink handled correctly"
69else
70    echo "fish-symlink not handled correctly: $real_path != $expected_real_path" >&2
71end
72# CHECK: fish-symlink handled correctly
73
74# With "-s" the symlink is not resolved.
75set -l real_path (builtin realpath -s $data_home_realpath/fish-symlink)
76set -l expected_real_path "$data_home_realpath/fish-symlink"
77if test "$real_path" = "$expected_real_path"
78    echo "fish-symlink with -s handled correctly"
79else
80    echo "fish-symlink with -s not handled correctly: $real_path != $expected_real_path" >&2
81end
82# CHECK: fish-symlink with -s handled correctly
83
84# But the $PWD is still resolved
85set -l oldpwd $PWD
86cd $XDG_DATA_HOME/fish-symlink
87set -l real_path (builtin realpath -s $data_home_realpath/fish-symlink)
88set -l expected_real_path "$data_home_realpath/fish-symlink"
89if test "$real_path" = "$expected_real_path"
90    echo "fish-symlink after cd handled correctly"
91else
92    echo "fish-symlink after cd not handled correctly: $real_path != $expected_real_path" >&2
93end
94# CHECK: fish-symlink after cd handled correctly
95cd $oldpwd
96
97set -l real_path (builtin realpath -s .)
98set -l expected_real_path (pwd -P) # Physical working directory.
99if test "$real_path" = "$expected_real_path"
100    echo "relative path correctly handled"
101else
102    echo "relative path not handled correctly: $real_path != $expected_real_path" >&2
103end
104# CHECK: relative path correctly handled
105
106test (builtin realpath -s /usr/bin/../) = /usr
107or echo builtin realpath -s does not resolve .. or resolves symlink wrong
108
109# A nonexistent file relative to a valid symlink to a directory gets converted.
110# This depends on the symlink created by the previous test.
111if set -q nosymlinks
112    echo "fish-symlink/nonexistent-file-relative-to-a-symlink correctly converted"
113else
114    set -l real_path (builtin realpath $XDG_DATA_HOME/fish-symlink/nonexistent-file-relative-to-a-symlink)
115    set -l expected_real_path "$data_home_realpath/fish/nonexistent-file-relative-to-a-symlink"
116    if test "$real_path" = "$expected_real_path"
117        echo "fish-symlink/nonexistent-file-relative-to-a-symlink correctly converted"
118    else
119        echo "failure nonexistent-file-relative-to-a-symlink: $real_path != $expected_real_path" >&2
120    end
121end
122# CHECK: fish-symlink/nonexistent-file-relative-to-a-symlink correctly converted
123
124# We remove leading slashes even with "-s".
125# This is how GNU realpath -s behaves, and also e.g.
126# how bash normalizes its $PWD.
127builtin realpath -s ///bin
128# CHECK: /bin
129
130builtin realpath -s //bin
131# CHECK: /bin
132
133# A path with two symlinks, first to a directory, second to a file, is correctly resolved.
134if set -q nosymlinks
135    echo "fish-symlink/symlink_file handled correctly"
136else
137    ln -fs fish $XDG_DATA_HOME/fish-symlink2
138    touch $XDG_DATA_HOME/fish/real_file
139    ln -fs real_file $XDG_DATA_HOME/fish/symlink_file
140    set -l real_path (builtin realpath $XDG_DATA_HOME/fish-symlink/symlink_file)
141    set -l expected_real_path "$data_home_realpath/fish/real_file"
142    if test "$real_path" = "$expected_real_path"
143        echo "fish-symlink/symlink_file handled correctly"
144    else
145        echo "fish-symlink/symlink_file not handled correctly: $real_path != expected_real_path" >&2
146    end
147end
148# CHECK: fish-symlink/symlink_file handled correctly
149
150builtin realpath / /
151# CHECK: /
152# CHECK: /
153
154builtin realpath '' /tmp '' /dont-exist ''
155# CHECKERR: realpath: Invalid arg:
156# CHECK: {{.*}}/tmp
157# CHECKERR: realpath: Invalid arg:
158# CHECK: /dont-exist
159# CHECKERR: realpath: Invalid arg:
160
161exit 0