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