xref: /freebsd/usr.bin/diff/tests/diff_test.sh (revision 13464e4a44fc58490a03bb8bfc7e3c972e9c30b2)
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
10
11simple_body()
12{
13	atf_check -o file:$(atf_get_srcdir)/simple.out -s eq:1 \
14		diff "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
15
16	atf_check -o file:$(atf_get_srcdir)/simple_e.out -s eq:1 \
17		diff -e "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
18
19	atf_check -o file:$(atf_get_srcdir)/simple_u.out -s eq:1 \
20		diff -u -L input1 -L input2 "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
21
22	atf_check -o file:$(atf_get_srcdir)/simple_n.out -s eq:1 \
23		diff -n "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
24
25	atf_check -o inline:"Files $(atf_get_srcdir)/input1.in and $(atf_get_srcdir)/input2.in differ\n" -s eq:1 \
26		diff -q "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
27
28	atf_check \
29		diff -q "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input1.in"
30
31	atf_check -o file:$(atf_get_srcdir)/simple_i.out -s eq:1 \
32		diff -i "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
33
34	atf_check -o file:$(atf_get_srcdir)/simple_w.out -s eq:1 \
35		diff -w "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
36
37	atf_check -o file:$(atf_get_srcdir)/simple_b.out -s eq:1 \
38		diff -b "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
39
40	atf_check -o file:$(atf_get_srcdir)/simple_p.out -s eq:1 \
41		diff --label input_c1.in --label input_c2.in -p "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
42}
43
44unified_body()
45{
46	atf_check -o file:$(atf_get_srcdir)/unified_p.out -s eq:1 \
47		diff -up -L input_c1.in -L input_c2.in  "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
48	atf_check -o file:$(atf_get_srcdir)/unified_c9999.out -s eq:1 \
49		diff -u -c9999 -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
50	atf_check -o file:$(atf_get_srcdir)/unified_9999.out -s eq:1 \
51		diff -u9999 -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
52}
53
54header_body()
55{
56	export TZ=UTC
57	: > empty
58	echo hello > hello
59	touch -d 2015-04-03T01:02:03 empty
60	touch -d 2016-12-22T11:22:33 hello
61	atf_check -o "file:$(atf_get_srcdir)/header.out" -s eq:1 \
62		diff -u empty hello
63}
64
65header_ns_body()
66{
67	export TZ=UTC
68	: > empty
69	echo hello > hello
70	touch -d 2015-04-03T01:02:03.123456789 empty
71	touch -d 2016-12-22T11:22:33.987654321 hello
72	atf_check -o "file:$(atf_get_srcdir)/header_ns.out" -s eq:1 \
73		diff -u empty hello
74}
75
76ifdef_body()
77{
78	atf_check -o file:$(atf_get_srcdir)/ifdef.out -s eq:1 \
79		diff -D PLOP "$(atf_get_srcdir)/input_c1.in" \
80		"$(atf_get_srcdir)/input_c2.in"
81}
82
83group_format_body()
84{
85	atf_check -o file:$(atf_get_srcdir)/group-format.out -s eq:1 \
86		diff --changed-group-format='<<<<<<< (local)
87%<=======
88%>>>>>>>> (stock)
89' "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
90}
91
92side_by_side_body()
93{
94	atf_expect_fail "--side-by-side not currently implemented (bug # 219933)"
95
96	atf_check -o save:A printf "A\nB\nC\n"
97	atf_check -o save:B printf "D\nB\nE\n"
98
99	exp_output="A[[:space:]]+|[[:space:]]+D\nB[[:space:]]+B\nC[[:space:]]+|[[:space:]]+E"
100	exp_output_suppressed="A[[:space:]]+|[[:space:]]+D\nC[[:space:]]+|[[:space:]]+E"
101
102	atf_check -o match:"$exp_output" -s exit:1 \
103	    diff --side-by-side A B
104	atf_check -o match:"$exp_output" -s exit:1 \
105	    diff -y A B
106	atf_check -o match:"$exp_output_suppressed" -s exit:1 \
107	    diff -y --suppress-common-lines A B
108	atf_check -o match:"$exp_output_suppressed" -s exit:1 \
109	    diff -W 65 -y --suppress-common-lines A B
110}
111
112atf_init_test_cases()
113{
114	atf_add_test_case simple
115	atf_add_test_case unified
116	atf_add_test_case header
117	atf_add_test_case header_ns
118	atf_add_test_case ifdef
119	atf_add_test_case group_format
120	atf_add_test_case side_by_side
121}
122