blob: 0ced0f248fed2f46a371e591c7ec6e5f2a3cb481 [file] [log] [blame]
Denis Vlasenkocee01cf2008-03-24 20:33:47 +00001#!/bin/sh
2# Copyright 2008 by Denys Vlasenko
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02003# Licensed under GPLv2, see file LICENSE in this source tree.
Denis Vlasenkocee01cf2008-03-24 20:33:47 +00004
Mike Frysingercaa79402009-11-04 18:41:22 -05005. ./testing.sh
Denis Vlasenkocee01cf2008-03-24 20:33:47 +00006
Matheus Izvekov61f5f782010-07-09 19:40:00 +02007# testing "test name" "commands" "expected result" "file input" "stdin"
Denis Vlasenkocee01cf2008-03-24 20:33:47 +00008
9# diff outputs date/time in the header, which should not be analysed
10# NB: sed has tab character in s command!
11TRIM_TAB="sed 's/ .*//'"
12
13testing "diff of stdin" \
14 "diff -u - input | $TRIM_TAB" \
15"\
16--- -
17+++ input
18@@ -1 +1,3 @@
19+qwe
20 asd
21+zxc
22" \
23 "qwe\nasd\nzxc\n" \
24 "asd\n"
25
26testing "diff of stdin, no newline in the file" \
27 "diff -u - input | $TRIM_TAB" \
28"\
29--- -
30+++ input
31@@ -1 +1,3 @@
32+qwe
33 asd
34+zxc
35\\ No newline at end of file
36" \
37 "qwe\nasd\nzxc" \
38 "asd\n"
39
40# we also test that stdin is in fact NOT read
41testing "diff of stdin, twice" \
Denys Vlasenkob972f942010-01-18 01:04:20 +010042 'diff - -; echo $?; wc -c' \
Denis Vlasenkocee01cf2008-03-24 20:33:47 +000043 "0\n5\n" \
44 "" \
45 "stdin"
46
Denys Vlasenko39f01722015-01-11 16:41:54 +010047testing "diff of empty file against stdin" \
48 "diff -u - input | $TRIM_TAB" \
49"\
50--- -
51+++ input
52@@ -1 +0,0 @@
53-a
54" \
55 "" \
56 "a\n"
57
Matheus Izvekov6f99c912010-01-21 18:58:03 -020058testing "diff of empty file against nonempty one" \
59 "diff -u - input | $TRIM_TAB" \
60"\
61--- -
62+++ input
63@@ -0,0 +1 @@
64+a
65" \
66 "a\n" \
67 ""
68
Denys Vlasenkob972f942010-01-18 01:04:20 +010069testing "diff -b treats EOF as whitespace" \
70 'diff -ub - input; echo $?' \
71 "0\n" \
72 "abc" \
73 "abc "
74
Denys Vlasenkob972f942010-01-18 01:04:20 +010075testing "diff -b treats all spaces as equal" \
76 'diff -ub - input; echo $?' \
77 "0\n" \
78 "a \t c\n" \
79 "a\t \tc\n"
80
Matheus Izvekov6f99c912010-01-21 18:58:03 -020081testing "diff -B ignores changes whose lines are all blank" \
82 'diff -uB - input; echo $?' \
83 "0\n" \
84 "a\n" \
85 "\na\n\n"
86
87testing "diff -B does not ignore changes whose lines are not all blank" \
88 "diff -uB - input | $TRIM_TAB" \
89"\
90--- -
91+++ input
92@@ -1,3 +1 @@
93-
94-b
95-
96+a
97" \
98 "a\n" \
99 "\nb\n\n"
100
Aaro Koskinenad27a6d2015-07-30 23:13:26 +0300101testing "diff -B ignores blank single line change" \
102 'diff -qB - input; echo $?' \
103 "0\n" \
104 "\n1\n" \
105 "1\n"
106
107testing "diff -B does not ignore non-blank single line change" \
108 'diff -qB - input; echo $?' \
109 "Files - and input differ\n1\n" \
110 "0\n" \
111 "1\n"
112
Denys Vlasenkob972f942010-01-18 01:04:20 +0100113testing "diff always takes context from old file" \
114 "diff -ub - input | $TRIM_TAB" \
115"\
116--- -
117+++ input
118@@ -1 +1,3 @@
119+abc
120 a c
121+def
122" \
123 "abc\na c\ndef\n" \
124 "a c\n"
125
Matheus Izvekov61f5f782010-07-09 19:40:00 +0200126# testing "test name" "commands" "expected result" "file input" "stdin"
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000127
Matheus Izvekov61f5f782010-07-09 19:40:00 +0200128# clean up
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000129rm -rf diff1 diff2
Matheus Izvekov61f5f782010-07-09 19:40:00 +0200130
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000131mkdir diff1 diff2 diff2/subdir
132echo qwe >diff1/-
133echo asd >diff2/subdir/-
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200134optional FEATURE_DIFF_DIR
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000135testing "diff diff1 diff2/subdir" \
136 "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
137"\
138--- diff1/-
139+++ diff2/subdir/-
140@@ -1 +1 @@
141-qwe
142+asd
143" \
144 "" ""
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200145SKIP=
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000146
147# using directory structure from prev test...
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200148optional FEATURE_DIFF_DIR
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000149testing "diff dir dir2/file/-" \
150 "diff -ur diff1 diff2/subdir/- | $TRIM_TAB" \
151"\
152--- diff1/-
153+++ diff2/subdir/-
154@@ -1 +1 @@
155-qwe
156+asd
157" \
158 "" ""
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200159SKIP=
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000160
161# using directory structure from prev test...
162mkdir diff1/test
163mkfifo diff2/subdir/test
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200164optional FEATURE_DIFF_DIR
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000165testing "diff of dir and fifo" \
166 "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
167"\
168--- diff1/-
169+++ diff2/subdir/-
170@@ -1 +1 @@
171-qwe
172+asd
173Only in diff2/subdir: test
174" \
175 "" ""
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200176SKIP=
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000177
178# using directory structure from prev test...
179rmdir diff1/test
180echo >diff1/test
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200181optional FEATURE_DIFF_DIR
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000182testing "diff of file and fifo" \
183 "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
184"\
185--- diff1/-
186+++ diff2/subdir/-
187@@ -1 +1 @@
188-qwe
189+asd
190File diff2/subdir/test is not a regular file or directory and was skipped
191" \
192 "" ""
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200193SKIP=
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000194
195# using directory structure from prev test...
196mkfifo diff1/test2
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200197optional FEATURE_DIFF_DIR
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000198testing "diff -rN does not read non-regular files" \
199 "diff -urN diff1 diff2/subdir | $TRIM_TAB" \
200"\
201--- diff1/-
202+++ diff2/subdir/-
203@@ -1 +1 @@
204-qwe
205+asd
206File diff2/subdir/test is not a regular file or directory and was skipped
207File diff1/test2 is not a regular file or directory and was skipped
208" \
209 "" ""
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200210SKIP=
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000211
212# clean up
213rm -rf diff1 diff2
214
Matheus Izvekov61f5f782010-07-09 19:40:00 +0200215# NOT using directory structure from prev test...
216mkdir diff1 diff2
217echo qwe >diff1/-
218echo rty >diff2/-
219optional FEATURE_DIFF_DIR
220testing "diff diff1 diff2/" \
221 "diff -ur diff1 diff2/ | $TRIM_TAB; diff -ur .///diff1 diff2//// | $TRIM_TAB" \
222"\
223--- diff1/-
224+++ diff2/-
225@@ -1 +1 @@
226-qwe
227+rty
228--- .///diff1/-
229+++ diff2////-
230@@ -1 +1 @@
231-qwe
232+rty
233" \
234 "" ""
235SKIP=
236
237# clean up
238rm -rf diff1 diff2
239
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000240exit $FAILCOUNT