]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/diff/tests/diff_test.sh
bhyvectl(8): Normalize the man page date
[FreeBSD/FreeBSD.git] / usr.bin / diff / tests / diff_test.sh
1 # $FreeBSD$
2
3 atf_test_case simple
4 atf_test_case unified
5 atf_test_case header
6 atf_test_case header_ns
7 atf_test_case ifdef
8 atf_test_case group_format
9 atf_test_case side_by_side
10 atf_test_case brief_format
11 atf_test_case b230049
12 atf_test_case Bflag
13 atf_test_case Nflag
14 atf_test_case tabsize
15 atf_test_case conflicting_format
16 atf_test_case label
17
18 simple_body()
19 {
20         atf_check -o file:$(atf_get_srcdir)/simple.out -s eq:1 \
21                 diff "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
22
23         atf_check -o file:$(atf_get_srcdir)/simple_e.out -s eq:1 \
24                 diff -e "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
25
26         atf_check -o file:$(atf_get_srcdir)/simple_u.out -s eq:1 \
27                 diff -u -L input1 -L input2 "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
28
29         atf_check -o file:$(atf_get_srcdir)/simple_n.out -s eq:1 \
30                 diff -n "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
31
32         atf_check -o inline:"Files $(atf_get_srcdir)/input1.in and $(atf_get_srcdir)/input2.in differ\n" -s eq:1 \
33                 diff -q "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
34
35         atf_check \
36                 diff -q "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input1.in"
37
38         atf_check -o file:$(atf_get_srcdir)/simple_i.out -s eq:1 \
39                 diff -i "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
40
41         atf_check -o file:$(atf_get_srcdir)/simple_w.out -s eq:1 \
42                 diff -w "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
43
44         atf_check -o file:$(atf_get_srcdir)/simple_b.out -s eq:1 \
45                 diff -b "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
46
47         atf_check -o file:$(atf_get_srcdir)/simple_p.out -s eq:1 \
48                 diff --label input_c1.in --label input_c2.in -p "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
49 }
50
51 unified_body()
52 {
53         atf_check -o file:$(atf_get_srcdir)/unified_p.out -s eq:1 \
54                 diff -up -L input_c1.in -L input_c2.in  "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
55         atf_check -o file:$(atf_get_srcdir)/unified_9999.out -s eq:1 \
56                 diff -u9999 -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
57 }
58
59 b230049_body()
60 {
61         printf 'a\nb\r\nc\n' > b230049_a.in
62         printf 'a\r\nb\r\nc\r\n' > b230049_b.in
63         atf_check -o empty -s eq:0 \
64                 diff -up --strip-trailing-cr -L b230049_a.in -L b230049_b.in \
65                     b230049_a.in b230049_b.in
66 }
67
68 header_body()
69 {
70         export TZ=UTC
71         : > empty
72         echo hello > hello
73         touch -d 2015-04-03T01:02:03 empty
74         touch -d 2016-12-22T11:22:33 hello
75         atf_check -o "file:$(atf_get_srcdir)/header.out" -s eq:1 \
76                 diff -u empty hello
77 }
78
79 header_ns_body()
80 {
81         export TZ=UTC
82         : > empty
83         echo hello > hello
84         touch -d 2015-04-03T01:02:03.123456789 empty
85         touch -d 2016-12-22T11:22:33.987654321 hello
86         atf_check -o "file:$(atf_get_srcdir)/header_ns.out" -s eq:1 \
87                 diff -u empty hello
88 }
89
90 ifdef_body()
91 {
92         atf_check -o file:$(atf_get_srcdir)/ifdef.out -s eq:1 \
93                 diff -D PLOP "$(atf_get_srcdir)/input_c1.in" \
94                 "$(atf_get_srcdir)/input_c2.in"
95 }
96
97 group_format_body()
98 {
99         atf_check -o file:$(atf_get_srcdir)/group-format.out -s eq:1 \
100                 diff --changed-group-format='<<<<<<< (local)
101 %<=======
102 %>>>>>>>> (stock)
103 ' "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
104 }
105
106 side_by_side_body()
107 {
108         atf_check -o save:A printf "A\nB\nC\n"
109         atf_check -o save:B printf "D\nB\nE\n"
110
111         exp_output=$(printf "A[[:space:]]+|[[:space:]]+D\nB[[:space:]]+B\nC[[:space:]]+|[[:space:]]+E")
112         exp_output_suppressed=$(printf "A[[:space:]]+|[[:space:]]+D\nC[[:space:]]+|[[:space:]]+E")
113
114         atf_check -o match:"$exp_output" -s exit:1 \
115             diff --side-by-side A B
116         atf_check -o match:"$exp_output" -s exit:1 \
117             diff -y A B
118         atf_check -o match:"$exp_output_suppressed" -s exit:1 \
119             diff -y --suppress-common-lines A B
120         atf_check -o match:"$exp_output_suppressed" -s exit:1 \
121             diff -W 65 -y --suppress-common-lines A B
122 }
123
124 brief_format_body()
125 {
126         atf_check mkdir A B
127
128         atf_check -x "echo 1 > A/test-file"
129         atf_check -x "echo 2 > B/test-file"
130
131         atf_check cp -Rf A C
132         atf_check cp -Rf A D
133
134         atf_check -x "echo 3 > D/another-test-file"
135
136         atf_check \
137             -s exit:1 \
138             -o inline:"Files A/test-file and B/test-file differ\n" \
139             diff -rq A B
140
141         atf_check diff -rq A C
142
143         atf_check \
144             -s exit:1 \
145             -o inline:"Only in D: another-test-file\n" \
146             diff -rq A D
147
148         atf_check \
149             -s exit:1 \
150             -o inline:"Files A/another-test-file and D/another-test-file differ\n" \
151             diff -Nrq A D
152 }
153
154 Bflag_body()
155 {
156         atf_check -x 'printf "A\nB\n" > A'
157         atf_check -x 'printf "A\n\nB\n" > B'
158         atf_check -x 'printf "A\n \nB\n" > C'
159         atf_check -x 'printf "A\nC\nB\n" > D'
160         atf_check -x 'printf "A\nB\nC\nD\nE\nF\nG\nH" > E'
161         atf_check -x 'printf "A\n\nB\nC\nD\nE\nF\nX\nH" > F'
162
163         atf_check -s exit:0 -o inline:"" diff -B A B
164         atf_check -s exit:1 -o file:"$(atf_get_srcdir)/Bflag_C.out" diff -B A C
165         atf_check -s exit:1 -o file:"$(atf_get_srcdir)/Bflag_D.out" diff -B A D
166         atf_check -s exit:1 -o file:"$(atf_get_srcdir)/Bflag_F.out" diff -B E F
167 }
168
169 Nflag_body()
170 {
171         atf_check -x 'printf "foo" > A'
172
173         atf_check -s exit:1 -o ignore -e ignore diff -N A NOFILE 
174         atf_check -s exit:1 -o ignore -e ignore diff -N NOFILE A 
175         atf_check -s exit:2 -o ignore -e ignore diff -N NOFILE1 NOFILE2 
176 }
177
178 tabsize_body()
179 {
180         printf "\tA\n" > A
181         printf "\tB\n" > B
182
183         atf_check -s exit:1 \
184             -o inline:"1c1\n<  A\n---\n>  B\n" \
185             diff -t --tabsize 1 A B
186 }
187
188 conflicting_format_body()
189 {
190         printf "\tA\n" > A
191         printf "\tB\n" > B
192
193         atf_check -s exit:2 -e ignore diff -c -u A B
194         atf_check -s exit:2 -e ignore diff -e -f A B
195         atf_check -s exit:2 -e ignore diff -y -q A B
196         atf_check -s exit:2 -e ignore diff -q -u A B
197         atf_check -s exit:2 -e ignore diff -q -c A B
198         atf_check -s exit:2 -e ignore diff --normal -c A B
199         atf_check -s exit:2 -e ignore diff -c --normal A B
200
201         atf_check -s exit:1 -o ignore -e ignore diff -u -u A B
202         atf_check -s exit:1 -o ignore -e ignore diff -e -e A B
203         atf_check -s exit:1 -o ignore -e ignore diff -y -y A B
204         atf_check -s exit:1 -o ignore -e ignore diff -q -q A B
205         atf_check -s exit:1 -o ignore -e ignore diff -c -c A B
206         atf_check -s exit:1 -o ignore -e ignore diff --normal --normal A B
207 }
208
209 label_body()
210 {
211         printf "\tA\n" > A
212
213         atf_check -o inline:"Files hello and world are identical\n" \
214                 -s exit:0 diff --label hello --label world -s A A
215
216         atf_check -o inline:"Binary files hello and world differ\n" \
217                 -s exit:1 diff --label hello --label world `which diff` `which ls`
218 }
219
220 atf_init_test_cases()
221 {
222         atf_add_test_case simple
223         atf_add_test_case unified
224         atf_add_test_case header
225         atf_add_test_case header_ns
226         atf_add_test_case ifdef
227         atf_add_test_case group_format
228         atf_add_test_case side_by_side
229         atf_add_test_case brief_format
230         atf_add_test_case b230049
231         atf_add_test_case Bflag
232         atf_add_test_case Nflag
233         atf_add_test_case tabsize
234         atf_add_test_case conflicting_format
235         atf_add_test_case label
236 }