Imported Upstream version 3.3
[platform/upstream/diffutils.git] / tests / no-dereference
1 #!/bin/sh
2 # Test the --no-dereference option.
3
4 . "${srcdir=.}/init.sh"; path_prepend_ ../src
5
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
13
14 # Non-recursive comparisons.
15
16 # Test case 3: Compare regular file with regular file.
17 diff --no-dereference regular1 regular2 > out
18 test $? = 1 || fail=1
19 cat <<EOF > expected || framework_failure_
20 1c1
21 < Simple contents
22 ---
23 > Sample contents
24 EOF
25 compare expected out || fail=1
26
27 # Test case 4: Compare regular file with symbolic link.
28 diff --no-dereference regular1 symlink1 > out
29 test $? = 1 || fail=1
30 cat <<EOF > expected || framework_failure_
31 File regular1 is a regular file while file symlink1 is a symbolic link
32 EOF
33 compare expected out || fail=1
34
35 # Test case 5: Compare symbolic link with regular file.
36 diff --no-dereference symlink1 regular1 > out
37 test $? = 1 || fail=1
38 cat <<EOF > expected || framework_failure_
39 File symlink1 is a symbolic link while file regular1 is a regular file
40 EOF
41 compare expected out || fail=1
42
43 # Test case 6: Compare symbolic links with same value.
44 diff --no-dereference symlink1 symlink1bis > out
45 test $? = 0 || fail=1
46 compare /dev/null out || fail=1
47
48 # Test case 7: Compare symbolic links with different value and different target
49 # contents.
50 diff --no-dereference symlink1 symlink2 > out
51 test $? = 1 || fail=1
52 cat <<EOF > expected || framework_failure_
53 Symbolic links symlink1 and symlink2 differ
54 EOF
55 compare expected out || fail=1
56
57 # Test case 8: Compare symbolic links with different value and same target
58 # contents.
59 diff --no-dereference symlink2 symlink3 > out
60 test $? = 1 || fail=1
61 cat <<EOF > expected || framework_failure_
62 Symbolic links symlink2 and symlink3 differ
63 EOF
64 compare expected out || fail=1
65
66 # Recursive comparisons.
67
68 # Test case 1: Compare symbolic link with nonexistent file.
69 mkdir subdir1a
70 mkdir subdir1b
71 ln -s nonexistent subdir1a/foo
72 ln -s ../regular1 subdir1a/bar
73 diff -r --no-dereference subdir1a subdir1b > out
74 test $? = 1 || fail=1
75 cat <<EOF > expected || framework_failure_
76 Only in subdir1a: bar
77 Only in subdir1a: foo
78 EOF
79 compare expected out || fail=1
80
81 # Test case 1: Compare nonexistent file with symbolic link.
82 mkdir subdir2a
83 mkdir subdir2b
84 ln -s nonexistent subdir2b/foo
85 ln -s ../regular1 subdir2b/bar
86 diff -r --no-dereference subdir2a subdir2b > out
87 test $? = 1 || fail=1
88 cat <<EOF > expected || framework_failure_
89 Only in subdir2b: bar
90 Only in subdir2b: foo
91 EOF
92 compare expected out || fail=1
93
94 # Test case 3: Compare regular file with regular file.
95 mkdir subdir3a
96 mkdir subdir3b
97 cp regular1 subdir3a/foo
98 cp regular2 subdir3b/foo
99 diff -r --no-dereference subdir3a subdir3b > out
100 test $? = 1 || fail=1
101 cat <<EOF > expected || framework_failure_
102 diff -r --no-dereference subdir3a/foo subdir3b/foo
103 1c1
104 < Simple contents
105 ---
106 > Sample contents
107 EOF
108 compare expected out || fail=1
109
110 # Test case 4: Compare regular file with symbolic link.
111 mkdir subdir4a
112 mkdir subdir4b
113 cp regular1 subdir4a/foo
114 ln -s ../regular1 subdir4b/foo
115 diff -r --no-dereference subdir4a subdir4b > out
116 test $? = 1 || fail=1
117 cat <<EOF > expected || framework_failure_
118 File subdir4a/foo is a regular file while file subdir4b/foo is a symbolic link
119 EOF
120 compare expected out || fail=1
121
122 # Test case 5: Compare symbolic link with regular file.
123 mkdir subdir5a
124 mkdir subdir5b
125 ln -s ../regular1 subdir5a/foo
126 cp regular1 subdir5b/foo
127 diff -r --no-dereference subdir5a subdir5b > out
128 test $? = 1 || fail=1
129 cat <<EOF > expected || framework_failure_
130 File subdir5a/foo is a symbolic link while file subdir5b/foo is a regular file
131 EOF
132 compare expected out || fail=1
133
134 # Test case 6: Compare symbolic links with same value.
135 mkdir subdir6a
136 mkdir subdir6b
137 ln -s ../regular1 subdir6a/foo
138 ln -s ../regular1 subdir6b/foo
139 diff -r --no-dereference subdir6a subdir6b > out
140 test $? = 0 || fail=1
141 compare /dev/null out || fail=1
142
143 # Test case 7: Compare symbolic links with different value and different target
144 # contents.
145 mkdir subdir7a
146 mkdir subdir7b
147 ln -s ../regular1 subdir7a/foo
148 ln -s ../regular2 subdir7b/foo
149 diff -r --no-dereference subdir7a subdir7b > out
150 test $? = 1 || fail=1
151 cat <<EOF > expected || framework_failure_
152 Symbolic links subdir7a/foo and subdir7b/foo differ
153 EOF
154 compare expected out || fail=1
155
156 # Test case 8: Compare symbolic links with different value and same target
157 # contents.
158 mkdir subdir8a
159 mkdir subdir8b
160 ln -s ../regular2 subdir8a/foo
161 ln -s ../regular3 subdir8b/foo
162 diff -r --no-dereference subdir8a subdir8b > out
163 test $? = 1 || fail=1
164 cat <<EOF > expected || framework_failure_
165 Symbolic links subdir8a/foo and subdir8b/foo differ
166 EOF
167 compare expected out || fail=1
168
169 Exit $fail