blob: 06d5a4fd7923eaf70b4a775aa5750fcbcaa430dd [file] [log] [blame]
Denis Vlasenkocee01cf2008-03-24 20:33:47 +00001#!/bin/sh
2# Copyright 2008 by Denys Vlasenko
3# Licensed under GPL v2, see file LICENSE for details.
4
Mike Frysingercaa79402009-11-04 18:41:22 -05005. ./testing.sh
Denis Vlasenkocee01cf2008-03-24 20:33:47 +00006
7# testing "test name" "options" "expected result" "file input" "stdin"
8
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
Matheus Izvekov6f99c912010-01-21 18:58:03 -020047testing "diff of empty file against nonempty one" \
48 "diff -u - input | $TRIM_TAB" \
49"\
50--- -
51+++ input
52@@ -0,0 +1 @@
53+a
54" \
55 "a\n" \
56 ""
57
Denys Vlasenkob972f942010-01-18 01:04:20 +010058testing "diff -b treats EOF as whitespace" \
59 'diff -ub - input; echo $?' \
60 "0\n" \
61 "abc" \
62 "abc "
63
Denys Vlasenkob972f942010-01-18 01:04:20 +010064testing "diff -b treats all spaces as equal" \
65 'diff -ub - input; echo $?' \
66 "0\n" \
67 "a \t c\n" \
68 "a\t \tc\n"
69
Matheus Izvekov6f99c912010-01-21 18:58:03 -020070testing "diff -B ignores changes whose lines are all blank" \
71 'diff -uB - input; echo $?' \
72 "0\n" \
73 "a\n" \
74 "\na\n\n"
75
76testing "diff -B does not ignore changes whose lines are not all blank" \
77 "diff -uB - input | $TRIM_TAB" \
78"\
79--- -
80+++ input
81@@ -1,3 +1 @@
82-
83-b
84-
85+a
86" \
87 "a\n" \
88 "\nb\n\n"
89
Denys Vlasenkob972f942010-01-18 01:04:20 +010090testing "diff always takes context from old file" \
91 "diff -ub - input | $TRIM_TAB" \
92"\
93--- -
94+++ input
95@@ -1 +1,3 @@
96+abc
97 a c
98+def
99" \
100 "abc\na c\ndef\n" \
101 "a c\n"
102
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000103# testing "test name" "options" "expected result" "file input" "stdin"
104
105rm -rf diff1 diff2
106mkdir diff1 diff2 diff2/subdir
107echo qwe >diff1/-
108echo asd >diff2/subdir/-
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200109optional FEATURE_DIFF_DIR
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000110testing "diff diff1 diff2/subdir" \
111 "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
112"\
113--- diff1/-
114+++ diff2/subdir/-
115@@ -1 +1 @@
116-qwe
117+asd
118" \
119 "" ""
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200120SKIP=
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000121
122# using directory structure from prev test...
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200123optional FEATURE_DIFF_DIR
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000124testing "diff dir dir2/file/-" \
125 "diff -ur diff1 diff2/subdir/- | $TRIM_TAB" \
126"\
127--- diff1/-
128+++ diff2/subdir/-
129@@ -1 +1 @@
130-qwe
131+asd
132" \
133 "" ""
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200134SKIP=
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000135
136# using directory structure from prev test...
137mkdir diff1/test
138mkfifo diff2/subdir/test
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200139optional FEATURE_DIFF_DIR
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000140testing "diff of dir and fifo" \
141 "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
142"\
143--- diff1/-
144+++ diff2/subdir/-
145@@ -1 +1 @@
146-qwe
147+asd
148Only in diff2/subdir: test
149" \
150 "" ""
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200151SKIP=
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000152
153# using directory structure from prev test...
154rmdir diff1/test
155echo >diff1/test
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200156optional FEATURE_DIFF_DIR
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000157testing "diff of file and fifo" \
158 "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
159"\
160--- diff1/-
161+++ diff2/subdir/-
162@@ -1 +1 @@
163-qwe
164+asd
165File diff2/subdir/test is not a regular file or directory and was skipped
166" \
167 "" ""
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200168SKIP=
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000169
170# using directory structure from prev test...
171mkfifo diff1/test2
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200172optional FEATURE_DIFF_DIR
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000173testing "diff -rN does not read non-regular files" \
174 "diff -urN diff1 diff2/subdir | $TRIM_TAB" \
175"\
176--- diff1/-
177+++ diff2/subdir/-
178@@ -1 +1 @@
179-qwe
180+asd
181File diff2/subdir/test is not a regular file or directory and was skipped
182File diff1/test2 is not a regular file or directory and was skipped
183" \
184 "" ""
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200185SKIP=
Denis Vlasenkocee01cf2008-03-24 20:33:47 +0000186
187# clean up
188rm -rf diff1 diff2
189
190exit $FAILCOUNT