summaryrefslogtreecommitdiff
path: root/tests/cmp
blob: 79568a241d37f19857bb2a45d10eacc7e29c817c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/sh
# Test 'cmp'.

# Copyright 2017-2021 Free Software Foundation, Inc.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

. "${srcdir=.}/init.sh"; path_prepend_ ../src

fail=0

cat <<'EOF' > exp || fail=1
cmp a a
0
cmp a b
a b differ: char 1, line 1
1
cmp a c
cmp: EOF on c which is empty
1
cmp a d
cmp: d: No such file or directory
2
cmp b a
b a differ: char 1, line 1
1
cmp b b
0
cmp b c
cmp: EOF on c which is empty
1
cmp b d
cmp: d: No such file or directory
2
cmp c a
cmp: EOF on c which is empty
1
cmp c b
cmp: EOF on c which is empty
1
cmp c c
0
cmp c d
cmp: d: No such file or directory
2
cmp d a
cmp: d: No such file or directory
2
cmp d b
cmp: d: No such file or directory
2
cmp d c
cmp: d: No such file or directory
2
cmp d d
cmp: d: No such file or directory
2
cmp -l a a
0
cmp -l a b
1 141 142
1
cmp -l a c
cmp: EOF on c which is empty
1
cmp -l a d
cmp: d: No such file or directory
2
cmp -l b a
1 142 141
1
cmp -l b b
0
cmp -l b c
cmp: EOF on c which is empty
1
cmp -l b d
cmp: d: No such file or directory
2
cmp -l c a
cmp: EOF on c which is empty
1
cmp -l c b
cmp: EOF on c which is empty
1
cmp -l c c
0
cmp -l c d
cmp: d: No such file or directory
2
cmp -l d a
cmp: d: No such file or directory
2
cmp -l d b
cmp: d: No such file or directory
2
cmp -l d c
cmp: d: No such file or directory
2
cmp -l d d
cmp: d: No such file or directory
2
cmp -s a a
0
cmp -s a b
1
cmp -s a c
1
cmp -s a d
2
cmp -s b a
1
cmp -s b b
0
cmp -s b c
1
cmp -s b d
2
cmp -s c a
1
cmp -s c b
1
cmp -s c c
0
cmp -s c d
2
cmp -s d a
2
cmp -s d b
2
cmp -s d c
2
cmp -s d d
2
EOF

echo a >a
echo b >b
: >c
rm -f d

for option in '' -l -s; do
  for i in a b c d; do
    for j in a b c d; do
      echo cmp $option $i $j
      cmp $option $i $j >stdout 2>stderr
      status=$?
      cat stderr stdout
      echo $status
    done
  done
done >out

compare exp out || fail=1

cat <<'EOF' > exp1 || fail=1
cmp a0 a1
cmp: EOF on a0 which is empty
1
cmp a1 a2
cmp: EOF on a1 after byte 2, line 1
1
cmp a2 a3
cmp: EOF on a2 after byte 5, in line 2
1
cmp -l a0 a1
cmp: EOF on a0 which is empty
1
cmp -l a1 a2
cmp: EOF on a1 after byte 2
1
cmp -l a2 a3
cmp: EOF on a2 after byte 5
1
cmp -s a0 a1
1
cmp -s a1 a2
1
cmp -s a2 a3
1
EOF

printf '' >a0
printf '1\n' >a1
printf '1\nfoo' >a2
printf '1\nfoolery\n' >a3

for option in '' -l -s; do
  for files in 'a0 a1' 'a1 a2' 'a2 a3'; do
    echo cmp $option $files
    cmp $option $files >stdout 2>stderr
    status=$?
    cat stderr stdout
    echo $status
  done
done >out1

compare exp1 out1 || fail=1

printf 'bad\n' >bad
printf 'bug\n' >bug
echo LC_ALL=C cmp -b bad bug
LC_ALL=C cmp -b bad bug
test $? -eq 1 || fail=1
case `LC_ALL=C cmp -b bad bug` in
  'bad bug differ: byte 2, line 1 is '*' a '*' u') ;;
  *) echo 'expected cmp -b to report a and u'; fail=1;;
esac

printf 'Jackdaws love my big sphinx of quartz!' > j1
printf 'jackdaws love my big sphinx of quartz.' > j2
cat <<'EOF' > exp2 || fail=1
 1 112 J    152 j
38  41 !     56 .
EOF
cmp -bl j1 j2 > out2
test $? -eq 1 || fail=1
compare exp2 out2 || fail=1

Exit $fail