ls: support --hyperlink to output file:// URIs
[coreutils.git] / tests / ls / hyperlink.sh
blobbc1331147d226bfc8a3bc0c57c23554c2b5fc720
1 #!/bin/sh
2 # Test --hyperlink processing
4 # Copyright (C) 2017 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_ ls realpath
22 hostname=$(hostname) || skip_ 'unable to determine hostname'
24 # lookup based on first letter
25 encode() {
26 printf '%s\n' \
27 'sp%20ace' 'ques%3ftion' 'back%5cslash' 'encoded%253Fquestion' 'testdir' \
28 "$1" |
29 sort -k1,1.1 -s | uniq -w1 -d
32 ls_encoded() {
33 ef=$(encode "$1")
34 echo "$ef" | grep -q 'dir$' && dir=: || dir=''
35 printf '\033]8;;file://%s%s/%s\a%s\033]8;;\a%s\n' \
36 $hostname $basepath $ef "$1" "$dir"
39 mkdir testdir || framework_failure_
40 basepath=$(realpath -m .) || framework_failure_
42 cd testdir
43 ls_encoded "testdir" > ../exp.t || framework_failure_
44 basepath="$basepath/testdir"
45 for f in 'back\slash' 'encoded%3Fquestion' 'ques?tion' 'sp ace'; do
46 touch "$f" || framework_failure_
47 ls_encoded "$f" >> ../exp.t || framework_failure_
48 done
50 ln -s testdir testdirl || framework_failure_
51 (cat exp.t && echo && sed 's/[^\/]testdir/&l/' exp.t) > exp \
52 || framework_failure_
53 ls --hyper testdir testdirl >out || fail=1
54 compare exp out || fail=1
56 ln -s '/probably/missing' testlink || framework_failure_
57 target=$(realpath -m testlink) || framework_failure_
58 ls -l --hyper testlink > out || fail=1
59 grep "file://.*$target" out || fail=1
61 Exit $fail