doc: rewrite the "Unusual File Names" section
[diffutils.git] / tests / no-dereference
blob88b81afdc5369a9a3178f64f2d2e820e9db67059
1 #!/bin/sh
2 # Test the --no-dereference option.
4 . "${srcdir=.}/init.sh"; path_prepend_ ../src
6 echo 'Simple contents' > regular1
7 echo 'Sample contents' > regular2
8 echo 'Sample contents' > regular3
9 ln -s regular1 symlink1
10 ln -s regular1 symlink1bis
11 ln -s regular2 symlink2
12 ln -s regular3 symlink3
14 # Non-recursive comparisons.
16 # Compare regular file with regular file.
17 returns_ 1 diff --no-dereference regular1 regular2 > out || fail=1
18 cat <<EOF > expected || framework_failure_
19 1c1
20 < Simple contents
21 ---
22 > Sample contents
23 EOF
24 compare expected out || fail=1
26 # Compare regular file with symbolic link.
27 returns_ 1 diff --no-dereference regular1 symlink1 > out || fail=1
28 cat <<EOF > expected || framework_failure_
29 File regular1 is a regular file while file symlink1 is a symbolic link
30 EOF
31 compare expected out || fail=1
33 # Compare symbolic link with regular file.
34 returns_ 1 diff --no-dereference symlink1 regular1 > out || fail=1
35 cat <<EOF > expected || framework_failure_
36 File symlink1 is a symbolic link while file regular1 is a regular file
37 EOF
38 compare expected out || fail=1
40 # Compare symbolic links with same value.
41 diff --no-dereference symlink1 symlink1bis > out || fail=1
42 compare /dev/null out || fail=1
44 # Compare symbolic links with different value and different target contents.
45 LC_ALL=C returns_ 1 diff --no-dereference symlink1 symlink2 > out || fail=1
46 cat <<EOF > expected || framework_failure_
47 Symbolic links 'symlink1' -> 'regular1' and 'symlink2' -> 'regular2' differ
48 EOF
49 compare expected out || fail=1
51 # Compare symbolic links with different value and same target contents.
52 LC_ALL=C returns_ 1 diff --no-dereference symlink2 symlink3 > out || fail=1
53 cat <<EOF > expected || framework_failure_
54 Symbolic links 'symlink2' -> 'regular2' and 'symlink3' -> 'regular3' differ
55 EOF
56 compare expected out || fail=1
58 mkdir subdir &&
59 ln -s loop loop &&
60 ln -s loop subdir/loop || framework_failure_
61 diff --no-dereference loop subdir > out || fail=1
62 compare /dev/null out || fail=1
64 # Recursive comparisons.
66 # Compare symbolic link with nonexistent file.
67 mkdir subdir1a
68 mkdir subdir1b
69 ln -s nonexistent subdir1a/foo
70 ln -s ../regular1 subdir1a/bar
71 returns_ 1 diff -r --no-dereference subdir1a subdir1b > out || fail=1
72 cat <<EOF > expected || framework_failure_
73 Only in subdir1a: bar
74 Only in subdir1a: foo
75 EOF
76 compare expected out || fail=1
78 # Compare nonexistent file with symbolic link.
79 mkdir subdir2a
80 mkdir subdir2b
81 ln -s nonexistent subdir2b/foo
82 ln -s ../regular1 subdir2b/bar
83 returns_ 1 diff -r --no-dereference subdir2a subdir2b > out || fail=1
84 cat <<EOF > expected || framework_failure_
85 Only in subdir2b: bar
86 Only in subdir2b: foo
87 EOF
88 compare expected out || fail=1
90 # Compare regular file with regular file.
91 mkdir subdir3a
92 mkdir subdir3b
93 cp regular1 subdir3a/foo
94 cp regular2 subdir3b/foo
95 returns_ 1 diff -r --no-dereference subdir3a subdir3b > out || fail=1
96 cat <<EOF > expected || framework_failure_
97 diff -r --no-dereference subdir3a/foo subdir3b/foo
98 1c1
99 < Simple contents
101 > Sample contents
103 compare expected out || fail=1
105 # Compare regular file with symbolic link.
106 mkdir subdir4a
107 mkdir subdir4b
108 cp regular1 subdir4a/foo
109 ln -s ../regular1 subdir4b/foo
110 returns_ 1 diff -r --no-dereference subdir4a subdir4b > out || fail=1
111 cat <<EOF > expected || framework_failure_
112 File subdir4a/foo is a regular file while file subdir4b/foo is a symbolic link
114 compare expected out || fail=1
116 # Compare symbolic link with regular file.
117 mkdir subdir5a
118 mkdir subdir5b
119 ln -s ../regular1 subdir5a/foo
120 cp regular1 subdir5b/foo
121 returns_ 1 diff -r --no-dereference subdir5a subdir5b > out || fail=1
122 cat <<EOF > expected || framework_failure_
123 File subdir5a/foo is a symbolic link while file subdir5b/foo is a regular file
125 compare expected out || fail=1
127 # Compare symbolic links with same value.
128 mkdir subdir6a
129 mkdir subdir6b
130 ln -s ../regular1 subdir6a/foo
131 ln -s ../regular1 subdir6b/foo
132 diff -r --no-dereference subdir6a subdir6b > out || fail=1
133 compare /dev/null out || fail=1
135 # Compare symbolic links with different value and different target contents.
136 mkdir subdir7a
137 mkdir subdir7b
138 ln -s ../regular1 subdir7a/foo
139 ln -s ../regular2 subdir7b/foo
140 LC_ALL=C returns_ 1 diff -r --no-dereference subdir7a subdir7b > out || fail=1
141 cat <<EOF > expected || framework_failure_
142 Symbolic links 'subdir7a/foo' -> '../regular1' and 'subdir7b/foo' -> '../regular2' differ
144 compare expected out || fail=1
146 # Compare symbolic links with different value and same target contents.
147 mkdir subdir8a
148 mkdir subdir8b
149 ln -s ../regular2 subdir8a/foo
150 ln -s ../regular3 subdir8b/foo
151 LC_ALL=C returns_ 1 diff -r --no-dereference subdir8a subdir8b > out || fail=1
152 cat <<EOF > expected || framework_failure_
153 Symbolic links 'subdir8a/foo' -> '../regular2' and 'subdir8b/foo' -> '../regular3' differ
155 compare expected out || fail=1
157 Exit $fail