xref: /freebsd/usr.bin/diff/tests/diff_test.sh (revision 5e386598)
1# $FreeBSD$
2
3atf_test_case simple
4atf_test_case unified
5atf_test_case header
6atf_test_case header_ns
7
8simple_body()
9{
10	atf_check -o file:$(atf_get_srcdir)/simple.out -s eq:1 \
11		diff "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
12
13	atf_check -o file:$(atf_get_srcdir)/simple_e.out -s eq:1 \
14		diff -e "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
15
16	atf_check -o file:$(atf_get_srcdir)/simple_u.out -s eq:1 \
17		diff -u -L input1 -L input2 "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
18
19	atf_check -o file:$(atf_get_srcdir)/simple_n.out -s eq:1 \
20		diff -n "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
21
22	atf_check -o inline:"Files $(atf_get_srcdir)/input1.in and $(atf_get_srcdir)/input2.in differ\n" -s eq:1 \
23		diff -q "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in"
24
25	atf_check \
26		diff -q "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input1.in"
27
28	atf_check -o file:$(atf_get_srcdir)/simple_i.out -s eq:1 \
29		diff -i "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
30
31	atf_check -o file:$(atf_get_srcdir)/simple_w.out -s eq:1 \
32		diff -w "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
33
34	atf_check -o file:$(atf_get_srcdir)/simple_b.out -s eq:1 \
35		diff -b "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
36
37	atf_check -o file:$(atf_get_srcdir)/simple_p.out -s eq:1 \
38		diff --label input_c1.in --label input_c2.in -p "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
39}
40
41unified_body()
42{
43	atf_check -o file:$(atf_get_srcdir)/unified_p.out -s eq:1 \
44		diff -up -L input_c1.in -L input_c2.in  "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
45	atf_check -o file:$(atf_get_srcdir)/unified_c9999.out -s eq:1 \
46		diff -u -c9999 -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_9999.out -s eq:1 \
48		diff -u9999 -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
49}
50
51header_body()
52{
53	export TZ=UTC
54	: > empty
55	echo hello > hello
56	touch -d 2015-04-03T01:02:03 empty
57	touch -d 2016-12-22T11:22:33 hello
58	atf_check -o "file:$(atf_get_srcdir)/header.out" -s eq:1 \
59		diff -u empty hello
60}
61
62header_ns_body()
63{
64	export TZ=UTC
65	: > empty
66	echo hello > hello
67	touch -d 2015-04-03T01:02:03.123456789 empty
68	touch -d 2016-12-22T11:22:33.987654321 hello
69	atf_check -o "file:$(atf_get_srcdir)/header_ns.out" -s eq:1 \
70		diff -u empty hello
71}
72
73atf_init_test_cases()
74{
75	atf_add_test_case simple
76	atf_add_test_case unified
77	atf_add_test_case header
78	atf_add_test_case header_ns
79}
80