]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/diff/tests/diff_test.sh
MFC r336754: Improve --strip-trailing-cr handling.
[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
13 simple_body()
14 {
15         atf_check -o file:$(atf_get_srcdir)/simple.out -s eq:1 \
16                 diff "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
17
18         atf_check -o file:$(atf_get_srcdir)/simple_e.out -s eq:1 \
19                 diff -e "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
20
21         atf_check -o file:$(atf_get_srcdir)/simple_u.out -s eq:1 \
22                 diff -u -L input1 -L input2 "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
23
24         atf_check -o file:$(atf_get_srcdir)/simple_n.out -s eq:1 \
25                 diff -n "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
26
27         atf_check -o inline:"Files $(atf_get_srcdir)/input1.in and $(atf_get_srcdir)/input2.in differ\n" -s eq:1 \
28                 diff -q "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
29
30         atf_check \
31                 diff -q "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input1.in"
32
33         atf_check -o file:$(atf_get_srcdir)/simple_i.out -s eq:1 \
34                 diff -i "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
35
36         atf_check -o file:$(atf_get_srcdir)/simple_w.out -s eq:1 \
37                 diff -w "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
38
39         atf_check -o file:$(atf_get_srcdir)/simple_b.out -s eq:1 \
40                 diff -b "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
41
42         atf_check -o file:$(atf_get_srcdir)/simple_p.out -s eq:1 \
43                 diff --label input_c1.in --label input_c2.in -p "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
44 }
45
46 unified_body()
47 {
48         atf_check -o file:$(atf_get_srcdir)/unified_p.out -s eq:1 \
49                 diff -up -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_c9999.out -s eq:1 \
51                 diff -u -c9999 -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
52         atf_check -o file:$(atf_get_srcdir)/unified_9999.out -s eq:1 \
53                 diff -u9999 -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
54 }
55
56 b230049_body()
57 {
58         printf 'a\nb\r\nc\n' > b230049_a.in
59         printf 'a\r\nb\r\nc\r\n' > b230049_b.in
60         atf_check -o empty -s eq:0 \
61                 diff -up --strip-trailing-cr -L b230049_a.in -L b230049_b.in \
62                     b230049_a.in b230049_b.in
63 }
64
65 header_body()
66 {
67         export TZ=UTC
68         : > empty
69         echo hello > hello
70         touch -d 2015-04-03T01:02:03 empty
71         touch -d 2016-12-22T11:22:33 hello
72         atf_check -o "file:$(atf_get_srcdir)/header.out" -s eq:1 \
73                 diff -u empty hello
74 }
75
76 header_ns_body()
77 {
78         export TZ=UTC
79         : > empty
80         echo hello > hello
81         touch -d 2015-04-03T01:02:03.123456789 empty
82         touch -d 2016-12-22T11:22:33.987654321 hello
83         atf_check -o "file:$(atf_get_srcdir)/header_ns.out" -s eq:1 \
84                 diff -u empty hello
85 }
86
87 ifdef_body()
88 {
89         atf_check -o file:$(atf_get_srcdir)/ifdef.out -s eq:1 \
90                 diff -D PLOP "$(atf_get_srcdir)/input_c1.in" \
91                 "$(atf_get_srcdir)/input_c2.in"
92 }
93
94 group_format_body()
95 {
96         atf_check -o file:$(atf_get_srcdir)/group-format.out -s eq:1 \
97                 diff --changed-group-format='<<<<<<< (local)
98 %<=======
99 %>>>>>>>> (stock)
100 ' "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
101 }
102
103 side_by_side_body()
104 {
105         atf_expect_fail "--side-by-side not currently implemented (bug # 219933)"
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
123 brief_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
153 atf_init_test_cases()
154 {
155         atf_add_test_case simple
156         atf_add_test_case unified
157         atf_add_test_case header
158         atf_add_test_case header_ns
159         atf_add_test_case ifdef
160         atf_add_test_case group_format
161         atf_add_test_case side_by_side
162         atf_add_test_case brief_format
163         atf_add_test_case b230049
164 }