1#!/bin/sh
2# Make sure that ls -i works properly on symlinks.
3
4# Copyright (C) 2003-2023 Free Software Foundation, Inc.
5
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.
10
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.
15
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ ls
21
22touch f || framework_failure_
23ln -s f slink || framework_failure_
24
25
26# When listed explicitly:
27
28set x $(ls -Ci f slink); shift
29test $# = 4 || fail=1
30# The inode numbers should differ.
31test "$1" != "$3" || fail=1
32
33set x $(ls -CLi f slink); shift
34test $# = 4 || fail=1
35# With -L, they must be the same.
36test "$1" = "$3" || fail=1
37
38set x $(ls -CHi f slink); shift
39test $# = 4 || fail=1
40# With -H, they must be the same, too, from the command line.
41# Note that POSIX says -H must make ls dereference only
42# symlinks (specified on the command line) to directories,
43# but the historical BSD meaning of -H is to dereference
44# any symlink given on the command line.  For compatibility GNU ls
45# implements the BSD semantics.
46test "$1" = "$3" || fail=1
47
48# When listed from a directory:
49
50set x $(ls -Ci); shift
51test $# = 4 || fail=1
52# The inode numbers should differ.
53test "$1" != "$3" || fail=1
54
55set x $(ls -CLi); shift
56test $# = 4 || fail=1
57# With -L, they must be the same.
58test "$1" = "$3" || fail=1
59
60set x $(ls -CHi); shift
61test $# = 4 || fail=1
62# With -H, they must be different from inside a directory.
63test "$1" != "$3" || fail=1
64
65Exit $fail
66