xref: /freebsd/usr.bin/diff3/tests/diff3_test.sh (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1
2atf_test_case diff3
3atf_test_case diff3_lesssimple
4atf_test_case diff3_ed
5atf_test_case diff3_A
6atf_test_case diff3_merge
7atf_test_case diff3_E_merge
8
9diff3_body()
10{
11	atf_check -o file:$(atf_get_srcdir)/1.out \
12		diff3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
13
14	atf_check -o file:$(atf_get_srcdir)/1.out \
15		diff3 --strip-trailing-cr $(atf_get_srcdir)/1cr.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
16
17	atf_check -o file:$(atf_get_srcdir)/1t.out \
18		diff3 -T $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
19
20	atf_check -o file:$(atf_get_srcdir)/2.out \
21		diff3 -e $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
22
23	atf_check -o file:$(atf_get_srcdir)/3.out \
24		diff3 -E -L 1 -L 2 -L 3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
25
26	atf_check -o file:$(atf_get_srcdir)/4.out \
27		diff3 -X -L 1 -L 2 -L 3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
28
29	atf_check -o file:$(atf_get_srcdir)/5.out \
30		diff3 -x $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
31
32	atf_check -o file:$(atf_get_srcdir)/6.out \
33		diff3 -3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
34
35	atf_check -o file:$(atf_get_srcdir)/7.out \
36		diff3 -i $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
37}
38
39diff3_lesssimple_body()
40{
41	atf_check -s exit:1 -o file:$(atf_get_srcdir)/10.out \
42		diff3 -m -L 1 -L 2 -L 3 $(atf_get_srcdir)/4.txt $(atf_get_srcdir)/5.txt $(atf_get_srcdir)/6.txt
43}
44
45diff3_ed_body()
46{
47	atf_check -s exit:0 -o file:$(atf_get_srcdir)/long-ed.out \
48		diff3 -e $(atf_get_srcdir)/long-m.txt $(atf_get_srcdir)/long-o.txt $(atf_get_srcdir)/long-y.txt
49}
50
51diff3_A_body()
52{
53	atf_check -s exit:1 -o file:$(atf_get_srcdir)/8.out \
54		diff3 -A -L 1 -L 2 -L 3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
55
56	atf_check -s exit:1 -o file:$(atf_get_srcdir)/long-A.out \
57		diff3 -A -L long-m.txt -L long-o.txt -L long-y.txt $(atf_get_srcdir)/long-m.txt $(atf_get_srcdir)/long-o.txt $(atf_get_srcdir)/long-y.txt
58}
59
60
61diff3_merge_body()
62{
63	atf_check -s exit:1 -o file:$(atf_get_srcdir)/9.out \
64		diff3 -m -L 1 -L 2 -L 3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
65
66	atf_check -s exit:1 -o file:$(atf_get_srcdir)/long-merge.out \
67		diff3 -m -L long-m.txt -L long-o.txt -L long-y.txt $(atf_get_srcdir)/long-m.txt $(atf_get_srcdir)/long-o.txt $(atf_get_srcdir)/long-y.txt
68}
69
70diff3_E_merge_body()
71{
72
73expected="<<<<<<< 2
74# \$FreeBSD: head/local 12000 jhb \$
75=======
76# \$FreeBSD: head/local 12345 jhb \$
77>>>>>>> 3
78# \$FreeBSD: head/local 12345 jhb \$
79
80this is a file
81
82these are some local mods to the file
83"
84	# first test the regular test
85	cp $(atf_get_srcdir)/fbsdid2.txt out.txt
86	atf_check -s exit:1 -o inline:"${expected}" \
87		diff3 -m -L 1 -L 2 -L 3 out.txt $(atf_get_srcdir)/fbsdid1.txt $(atf_get_srcdir)/fbsdid2.txt
88
89merged="# \$FreeBSD: head/local 12345 jhb \$
90
91this is a file
92
93these are some local mods to the file
94"
95	atf_check -s exit:0 -o inline:"${merged}" \
96		diff3 -E -m out.txt $(atf_get_srcdir)/fbsdid1.txt $(atf_get_srcdir)/fbsdid2.txt
97}
98
99
100atf_init_test_cases()
101{
102	atf_add_test_case diff3
103#	atf_add_test_case diff3_lesssimple
104	atf_add_test_case diff3_ed
105	atf_add_test_case diff3_A
106	atf_add_test_case diff3_merge
107	atf_add_test_case diff3_E_merge
108}
109