xref: /freebsd/usr.bin/sdiff/tests/sdiff_test.sh (revision cc426dd31990b8b50b210efc450e404596548ca1)
1# $NetBSD: t_sdiff.sh,v 1.1 2012/03/17 16:33:15 jruoho Exp $
2# $FreeBSD$
3#
4# Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26# POSSIBILITY OF SUCH DAMAGE.
27#
28
29atf_test_case flags
30flags_head()
31{
32	atf_set "descr" "Checks -l, -s and -w flags"
33}
34flags_body()
35{
36	atf_check -o file:$(atf_get_srcdir)/d_flags_l.out -s eq:1 \
37	    sdiff -l "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input2"
38
39	atf_check -o file:$(atf_get_srcdir)/d_flags_s.out -s eq:1 \
40	    sdiff -s "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input2"
41
42	atf_check -o file:$(atf_get_srcdir)/d_flags_w.out -s eq:1 \
43	    sdiff -w 125 "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input2"
44}
45
46atf_test_case iflags
47iflags_head()
48{
49	atf_set "descr" "Checks flags -l, -s and -w combined with -I"
50}
51iflags_body()
52{
53	tail1="-w 125 -I .*filename.* $(atf_get_srcdir)/d_input1 $(atf_get_srcdir)/d_input2"
54	tail2="-w 125 -I .*filename.* $(atf_get_srcdir)/d_input2 $(atf_get_srcdir)/d_input1"
55
56	atf_check -o file:$(atf_get_srcdir)/d_iflags_a1.out -s eq:1 sdiff ${tail1}
57	atf_check -o file:$(atf_get_srcdir)/d_iflags_a2.out -s eq:1 sdiff ${tail2}
58	atf_check -o file:$(atf_get_srcdir)/d_iflags_b1.out -s eq:1 sdiff -s ${tail1}
59	atf_check -o file:$(atf_get_srcdir)/d_iflags_b2.out -s eq:1 sdiff -s ${tail2}
60	atf_check -o file:$(atf_get_srcdir)/d_iflags_c1.out -s eq:1 sdiff -l ${tail1}
61	atf_check -o file:$(atf_get_srcdir)/d_iflags_c2.out -s eq:1 sdiff -l ${tail2}
62	atf_check -o file:$(atf_get_srcdir)/d_iflags_d1.out -s eq:1 sdiff -s ${tail1}
63	atf_check -o file:$(atf_get_srcdir)/d_iflags_d2.out -s eq:1 sdiff -s ${tail2}
64}
65
66atf_test_case tabs
67tabs_head()
68{
69	atf_set "descr" "Checks comparing files containing tabs"
70}
71tabs_body()
72{
73	atf_check -o file:$(atf_get_srcdir)/d_tabs.out -s eq:1 \
74	    sdiff "$(atf_get_srcdir)/d_tabs1.in" "$(atf_get_srcdir)/d_tabs2.in"
75}
76
77atf_test_case tabends
78tabends_head()
79{
80	atf_set "descr" "Checks correct handling of lines ended with tabs"
81}
82tabends_body()
83{
84	atf_check -o file:$(atf_get_srcdir)/d_tabends_a.out -s eq:1 \
85	    sdiff -w30 "$(atf_get_srcdir)/d_tabends.in" /dev/null
86
87	atf_check -o file:$(atf_get_srcdir)/d_tabends_b.out -s eq:1 \
88	    sdiff -w30 /dev/null "$(atf_get_srcdir)/d_tabends.in"
89
90	atf_check -o file:$(atf_get_srcdir)/d_tabends_c.out -s eq:1 \
91	    sdiff -w19 "$(atf_get_srcdir)/d_tabends.in" /dev/null
92}
93
94atf_test_case merge
95merge_head()
96{
97	atf_set "descr" "Checks interactive merging"
98}
99merge_body()
100{
101	merge_tail="-o merge.out $(atf_get_srcdir)/d_input1 \
102$(atf_get_srcdir)/d_input2 >/dev/null ; cat merge.out"
103
104	cp $(atf_get_srcdir)/d_input* .
105
106	atf_check -o file:d_input1 -x "yes l | sdiff ${merge_tail}"
107	atf_check -o file:d_input2 -x "yes r | sdiff ${merge_tail}"
108
109	atf_check -o file:d_input1 -x \
110		"yes el | EDITOR=cat VISUAL=cat sdiff ${merge_tail}"
111	atf_check -o file:d_input2 -x \
112		"yes er | EDITOR=cat VISUAL=cat sdiff ${merge_tail}"
113
114	atf_check -o file:d_input1 -x "yes l | sdiff -s ${merge_tail}"
115	atf_check -o file:d_input2 -x "yes r | sdiff -s ${merge_tail}"
116	atf_check -o file:d_input1 -x "yes l | sdiff -l ${merge_tail}"
117	atf_check -o file:d_input2 -x "yes r | sdiff -l ${merge_tail}"
118	atf_check -o file:d_input1 -x "yes l | sdiff -ls ${merge_tail}"
119	atf_check -o file:d_input2 -x "yes r | sdiff -ls ${merge_tail}"
120
121	atf_check -o file:d_input1 -x "{ while :; do echo s; echo l; \
122echo v; echo l; done; } | sdiff ${merge_tail}"
123
124	atf_check -o file:d_input2 -x "{ while :; do echo s; echo r; \
125echo v; echo r; done; } | sdiff ${merge_tail}"
126}
127
128atf_test_case same
129same_head()
130{
131	atf_set "descr" "Checks comparing file with itself"
132}
133same_body()
134{
135	atf_check -o file:$(atf_get_srcdir)/d_same.out \
136	    sdiff "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input1"
137}
138
139atf_test_case oneline
140oneline_head()
141{
142	atf_set "descr" "Checks comparing one-line files"
143}
144oneline_body()
145{
146	atf_check -o file:$(atf_get_srcdir)/d_oneline_a.out -s eq:1 \
147	    sdiff /dev/null "$(atf_get_srcdir)/d_oneline.in"
148
149	atf_check -o file:$(atf_get_srcdir)/d_oneline_b.out -s eq:1 \
150	    sdiff "$(atf_get_srcdir)/d_oneline.in" /dev/null
151}
152
153atf_test_case dot
154dot_head()
155{
156	atf_set "descr" "Checks comparing with file containing only one character"
157}
158dot_body()
159{
160	echo ".                                                             <" > expout
161	atf_check -o file:expout -s eq:1 sdiff "$(atf_get_srcdir)/d_dot.in" /dev/null
162
163	echo "                                                              > ." > expout
164	atf_check -o file:expout -s eq:1 sdiff /dev/null "$(atf_get_srcdir)/d_dot.in"
165}
166
167atf_test_case stdin
168stdin_head()
169{
170	atf_set "descr" "Checks reading data from stdin"
171}
172stdin_body()
173{
174	echo "                                                              > stdin" > expout
175	atf_check -o file:expout -s eq:1 -x \
176	    "echo stdin | sdiff /dev/null /dev/stdin"
177
178	echo "stdin                                                         <" > expout
179	atf_check -o file:expout -s eq:1 -x \
180	    "echo stdin | sdiff /dev/stdin /dev/null"
181}
182
183atf_test_case short
184short_head()
185{
186	atf_set "descr" "Checks premature stop of merging"
187}
188short_body()
189{
190	atf_check -o file:$(atf_get_srcdir)/d_short.out -x \
191	    "printf \"r\\nl\\nr\\nl\" | sdiff -o merge.out $(atf_get_srcdir)/d_input1 \
192$(atf_get_srcdir)/d_input2 >/dev/null ; cat merge.out"
193}
194
195atf_init_test_cases()
196{
197	atf_add_test_case flags
198	atf_add_test_case iflags
199	atf_add_test_case tabs
200	atf_add_test_case tabends
201	atf_add_test_case merge
202	atf_add_test_case same
203	atf_add_test_case oneline
204	atf_add_test_case dot
205	atf_add_test_case stdin
206	atf_add_test_case short
207}
208