xref: /freebsd/usr.bin/diff/tests/diff_test.sh (revision 9257ada0a43b1b762755b6a56f77cf160cef308a)
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
9
10simple_body()
11{
12	atf_check -o file:$(atf_get_srcdir)/simple.out -s eq:1 \
13		diff "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
14
15	atf_check -o file:$(atf_get_srcdir)/simple_e.out -s eq:1 \
16		diff -e "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
17
18	atf_check -o file:$(atf_get_srcdir)/simple_u.out -s eq:1 \
19		diff -u -L input1 -L input2 "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
20
21	atf_check -o file:$(atf_get_srcdir)/simple_n.out -s eq:1 \
22		diff -n "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
23
24	atf_check -o inline:"Files $(atf_get_srcdir)/input1.in and $(atf_get_srcdir)/input2.in differ\n" -s eq:1 \
25		diff -q "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
26
27	atf_check \
28		diff -q "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input1.in"
29
30	atf_check -o file:$(atf_get_srcdir)/simple_i.out -s eq:1 \
31		diff -i "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
32
33	atf_check -o file:$(atf_get_srcdir)/simple_w.out -s eq:1 \
34		diff -w "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
35
36	atf_check -o file:$(atf_get_srcdir)/simple_b.out -s eq:1 \
37		diff -b "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
38
39	atf_check -o file:$(atf_get_srcdir)/simple_p.out -s eq:1 \
40		diff --label input_c1.in --label input_c2.in -p "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
41}
42
43unified_body()
44{
45	atf_check -o file:$(atf_get_srcdir)/unified_p.out -s eq:1 \
46		diff -up -L input_c1.in -L input_c2.in  "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
47	atf_check -o file:$(atf_get_srcdir)/unified_c9999.out -s eq:1 \
48		diff -u -c9999 -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
49	atf_check -o file:$(atf_get_srcdir)/unified_9999.out -s eq:1 \
50		diff -u9999 -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
51}
52
53header_body()
54{
55	export TZ=UTC
56	: > empty
57	echo hello > hello
58	touch -d 2015-04-03T01:02:03 empty
59	touch -d 2016-12-22T11:22:33 hello
60	atf_check -o "file:$(atf_get_srcdir)/header.out" -s eq:1 \
61		diff -u empty hello
62}
63
64header_ns_body()
65{
66	export TZ=UTC
67	: > empty
68	echo hello > hello
69	touch -d 2015-04-03T01:02:03.123456789 empty
70	touch -d 2016-12-22T11:22:33.987654321 hello
71	atf_check -o "file:$(atf_get_srcdir)/header_ns.out" -s eq:1 \
72		diff -u empty hello
73}
74
75ifdef_body()
76{
77	atf_check -o file:$(atf_get_srcdir)/ifdef.out -s eq:1 \
78		diff -D PLOP "$(atf_get_srcdir)/input_c1.in" \
79		"$(atf_get_srcdir)/input_c2.in"
80}
81
82group_format_body()
83{
84	atf_check -o file:$(atf_get_srcdir)/group-format.out -s eq:1 \
85		diff --changed-group-format='<<<<<<< (local)
86%<=======
87%>>>>>>>> (stock)
88' "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
89}
90
91atf_init_test_cases()
92{
93	atf_add_test_case simple
94	atf_add_test_case unified
95	atf_add_test_case header
96	atf_add_test_case header_ns
97	atf_add_test_case ifdef
98	atf_add_test_case group_format
99}
100