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