1298823Sbapt# $NetBSD: t_sdiff.sh,v 1.1 2012/03/17 16:33:15 jruoho Exp $
2298823Sbapt# $FreeBSD: stable/11/usr.bin/sdiff/tests/sdiff_test.sh 316256 2017-03-30 06:20:24Z ngie $
3298823Sbapt#
4298823Sbapt# Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
5298823Sbapt# All rights reserved.
6298823Sbapt#
7298823Sbapt# Redistribution and use in source and binary forms, with or without
8298823Sbapt# modification, are permitted provided that the following conditions
9298823Sbapt# are met:
10298823Sbapt# 1. Redistributions of source code must retain the above copyright
11298823Sbapt#    notice, this list of conditions and the following disclaimer.
12298823Sbapt# 2. Redistributions in binary form must reproduce the above copyright
13298823Sbapt#    notice, this list of conditions and the following disclaimer in the
14298823Sbapt#    documentation and/or other materials provided with the distribution.
15298823Sbapt#
16298823Sbapt# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17298823Sbapt# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18298823Sbapt# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19298823Sbapt# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20298823Sbapt# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21298823Sbapt# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22298823Sbapt# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23298823Sbapt# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24298823Sbapt# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25298823Sbapt# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26298823Sbapt# POSSIBILITY OF SUCH DAMAGE.
27298823Sbapt#
28298823Sbapt
29298823Sbaptatf_test_case flags
30298823Sbaptflags_head()
31298823Sbapt{
32298823Sbapt	atf_set "descr" "Checks -l, -s and -w flags"
33298823Sbapt}
34298823Sbaptflags_body()
35298823Sbapt{
36298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_flags_l.out -s eq:1 \
37298823Sbapt	    sdiff -l "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input2"
38298823Sbapt
39298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_flags_s.out -s eq:1 \
40298823Sbapt	    sdiff -s "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input2"
41298823Sbapt
42298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_flags_w.out -s eq:1 \
43298823Sbapt	    sdiff -w 125 "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input2"
44298823Sbapt}
45298823Sbapt
46298823Sbaptatf_test_case iflags
47298823Sbaptiflags_head()
48298823Sbapt{
49298823Sbapt	atf_set "descr" "Checks flags -l, -s and -w combined with -I"
50298823Sbapt}
51298823Sbaptiflags_body()
52298823Sbapt{
53298823Sbapt	tail1="-w 125 -I .*filename.* $(atf_get_srcdir)/d_input1 $(atf_get_srcdir)/d_input2"
54298823Sbapt	tail2="-w 125 -I .*filename.* $(atf_get_srcdir)/d_input2 $(atf_get_srcdir)/d_input1"
55298823Sbapt
56298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_iflags_a1.out -s eq:1 sdiff ${tail1}
57298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_iflags_a2.out -s eq:1 sdiff ${tail2}
58298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_iflags_b1.out -s eq:1 sdiff -s ${tail1}
59298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_iflags_b2.out -s eq:1 sdiff -s ${tail2}
60298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_iflags_c1.out -s eq:1 sdiff -l ${tail1}
61298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_iflags_c2.out -s eq:1 sdiff -l ${tail2}
62298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_iflags_d1.out -s eq:1 sdiff -s ${tail1}
63298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_iflags_d2.out -s eq:1 sdiff -s ${tail2}
64298823Sbapt}
65298823Sbapt
66298823Sbaptatf_test_case tabs
67298823Sbapttabs_head()
68298823Sbapt{
69298823Sbapt	atf_set "descr" "Checks comparing files containing tabs"
70298823Sbapt}
71298823Sbapttabs_body()
72298823Sbapt{
73298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_tabs.out -s eq:1 \
74298823Sbapt	    sdiff "$(atf_get_srcdir)/d_tabs1.in" "$(atf_get_srcdir)/d_tabs2.in"
75298823Sbapt}
76298823Sbapt
77298823Sbaptatf_test_case tabends
78298823Sbapttabends_head()
79298823Sbapt{
80298823Sbapt	atf_set "descr" "Checks correct handling of lines ended with tabs"
81298823Sbapt}
82298823Sbapttabends_body()
83298823Sbapt{
84298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_tabends_a.out -s eq:1 \
85298823Sbapt	    sdiff -w30 "$(atf_get_srcdir)/d_tabends.in" /dev/null
86298823Sbapt
87298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_tabends_b.out -s eq:1 \
88298823Sbapt	    sdiff -w30 /dev/null "$(atf_get_srcdir)/d_tabends.in"
89298823Sbapt
90298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_tabends_c.out -s eq:1 \
91298823Sbapt	    sdiff -w19 "$(atf_get_srcdir)/d_tabends.in" /dev/null
92298823Sbapt}
93298823Sbapt
94298823Sbaptatf_test_case merge
95298823Sbaptmerge_head()
96298823Sbapt{
97298823Sbapt	atf_set "descr" "Checks interactive merging"
98298823Sbapt}
99298823Sbaptmerge_body()
100298823Sbapt{
101298823Sbapt	merge_tail="-o merge.out $(atf_get_srcdir)/d_input1 \
102298823Sbapt$(atf_get_srcdir)/d_input2 >/dev/null ; cat merge.out"
103298823Sbapt
104298823Sbapt	cp $(atf_get_srcdir)/d_input* .
105298823Sbapt
106298823Sbapt	atf_check -o file:d_input1 -x "yes l | sdiff ${merge_tail}"
107298823Sbapt	atf_check -o file:d_input2 -x "yes r | sdiff ${merge_tail}"
108298823Sbapt
109298823Sbapt	atf_check -o file:d_input1 -x \
110298823Sbapt		"yes el | EDITOR=cat VISUAL=cat sdiff ${merge_tail}"
111298823Sbapt	atf_check -o file:d_input2 -x \
112298823Sbapt		"yes er | EDITOR=cat VISUAL=cat sdiff ${merge_tail}"
113298823Sbapt
114298823Sbapt	atf_check -o file:d_input1 -x "yes l | sdiff -s ${merge_tail}"
115298823Sbapt	atf_check -o file:d_input2 -x "yes r | sdiff -s ${merge_tail}"
116298823Sbapt	atf_check -o file:d_input1 -x "yes l | sdiff -l ${merge_tail}"
117298823Sbapt	atf_check -o file:d_input2 -x "yes r | sdiff -l ${merge_tail}"
118298823Sbapt	atf_check -o file:d_input1 -x "yes l | sdiff -ls ${merge_tail}"
119298823Sbapt	atf_check -o file:d_input2 -x "yes r | sdiff -ls ${merge_tail}"
120298823Sbapt
121298823Sbapt	atf_check -o file:d_input1 -x "{ while :; do echo s; echo l; \
122298823Sbaptecho v; echo l; done; } | sdiff ${merge_tail}"
123298823Sbapt
124298823Sbapt	atf_check -o file:d_input2 -x "{ while :; do echo s; echo r; \
125298823Sbaptecho v; echo r; done; } | sdiff ${merge_tail}"
126298823Sbapt}
127298823Sbapt
128298823Sbaptatf_test_case same
129298823Sbaptsame_head()
130298823Sbapt{
131298823Sbapt	atf_set "descr" "Checks comparing file with itself"
132298823Sbapt}
133298823Sbaptsame_body()
134298823Sbapt{
135298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_same.out \
136298823Sbapt	    sdiff "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input1"
137298823Sbapt}
138298823Sbapt
139298823Sbaptatf_test_case oneline
140298823Sbaptoneline_head()
141298823Sbapt{
142298823Sbapt	atf_set "descr" "Checks comparing one-line files"
143298823Sbapt}
144298823Sbaptoneline_body()
145298823Sbapt{
146298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_oneline_a.out -s eq:1 \
147298823Sbapt	    sdiff /dev/null "$(atf_get_srcdir)/d_oneline.in"
148298823Sbapt
149298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_oneline_b.out -s eq:1 \
150298823Sbapt	    sdiff "$(atf_get_srcdir)/d_oneline.in" /dev/null
151298823Sbapt}
152298823Sbapt
153298823Sbaptatf_test_case dot
154298823Sbaptdot_head()
155298823Sbapt{
156298823Sbapt	atf_set "descr" "Checks comparing with file containing only one character"
157298823Sbapt}
158298823Sbaptdot_body()
159298823Sbapt{
160298823Sbapt	echo ".                                                             <" > expout
161298823Sbapt	atf_check -o file:expout -s eq:1 sdiff "$(atf_get_srcdir)/d_dot.in" /dev/null
162298823Sbapt
163298823Sbapt	echo "                                                              > ." > expout
164298823Sbapt	atf_check -o file:expout -s eq:1 sdiff /dev/null "$(atf_get_srcdir)/d_dot.in"
165298823Sbapt}
166298823Sbapt
167298823Sbaptatf_test_case stdin
168298823Sbaptstdin_head()
169298823Sbapt{
170298823Sbapt	atf_set "descr" "Checks reading data from stdin"
171298823Sbapt}
172298823Sbaptstdin_body()
173298823Sbapt{
174298823Sbapt	echo "                                                              > stdin" > expout
175298823Sbapt	atf_check -o file:expout -s eq:1 -x \
176298823Sbapt	    "echo stdin | sdiff /dev/null /dev/stdin"
177298823Sbapt
178298823Sbapt	echo "stdin                                                         <" > expout
179298823Sbapt	atf_check -o file:expout -s eq:1 -x \
180298823Sbapt	    "echo stdin | sdiff /dev/stdin /dev/null"
181298823Sbapt}
182298823Sbapt
183298823Sbaptatf_test_case short
184298823Sbaptshort_head()
185298823Sbapt{
186298823Sbapt	atf_set "descr" "Checks premature stop of merging"
187298823Sbapt}
188298823Sbaptshort_body()
189298823Sbapt{
190298823Sbapt	atf_check -o file:$(atf_get_srcdir)/d_short.out -x \
191298823Sbapt	    "printf \"r\\nl\\nr\\nl\" | sdiff -o merge.out $(atf_get_srcdir)/d_input1 \
192298823Sbapt$(atf_get_srcdir)/d_input2 >/dev/null ; cat merge.out"
193298823Sbapt}
194298823Sbapt
195298823Sbaptatf_init_test_cases()
196298823Sbapt{
197298823Sbapt	atf_add_test_case flags
198298823Sbapt	atf_add_test_case iflags
199298823Sbapt	atf_add_test_case tabs
200298823Sbapt	atf_add_test_case tabends
201298823Sbapt	atf_add_test_case merge
202298823Sbapt	atf_add_test_case same
203298823Sbapt	atf_add_test_case oneline
204298823Sbapt	atf_add_test_case dot
205298823Sbapt	atf_add_test_case stdin
206298823Sbapt	atf_add_test_case short
207298823Sbapt}
208