summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/usr.bin/sdiff/t_sdiff.sh
blob: 2d6fc2dcc882c92fe61bb0d5f3749951a8892e89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# $NetBSD: t_sdiff.sh,v 1.1 2012/03/17 16:33:15 jruoho Exp $
#
# Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

atf_test_case flags
flags_head()
{
	atf_set "descr" "Checks -l, -s and -w flags"
}
flags_body()
{
	atf_check -o file:$(atf_get_srcdir)/d_flags_l.out -s eq:1 \
	    sdiff -l "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input2"

	atf_check -o file:$(atf_get_srcdir)/d_flags_s.out -s eq:1 \
	    sdiff -s "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input2"

	atf_check -o file:$(atf_get_srcdir)/d_flags_w.out -s eq:1 \
	    sdiff -w 125 "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input2"
}

atf_test_case iflags
iflags_head()
{
	atf_set "descr" "Checks flags -l, -s and -w combined with -I"
}
iflags_body()
{
	tail1="-w 125 -I .*filename.* $(atf_get_srcdir)/d_input1 $(atf_get_srcdir)/d_input2"
	tail2="-w 125 -I .*filename.* $(atf_get_srcdir)/d_input2 $(atf_get_srcdir)/d_input1"

	atf_check -o file:$(atf_get_srcdir)/d_iflags_a1.out -s eq:1 sdiff ${tail1}
	atf_check -o file:$(atf_get_srcdir)/d_iflags_a2.out -s eq:1 sdiff ${tail2}
	atf_check -o file:$(atf_get_srcdir)/d_iflags_b1.out -s eq:1 sdiff -s ${tail1}
	atf_check -o file:$(atf_get_srcdir)/d_iflags_b2.out -s eq:1 sdiff -s ${tail2}
	atf_check -o file:$(atf_get_srcdir)/d_iflags_c1.out -s eq:1 sdiff -l ${tail1}
	atf_check -o file:$(atf_get_srcdir)/d_iflags_c2.out -s eq:1 sdiff -l ${tail2}
	atf_check -o file:$(atf_get_srcdir)/d_iflags_d1.out -s eq:1 sdiff -s ${tail1}
	atf_check -o file:$(atf_get_srcdir)/d_iflags_d2.out -s eq:1 sdiff -s ${tail2}
}

atf_test_case tabs
tabs_head()
{
	atf_set "descr" "Checks comparing files containing tabs"
}
tabs_body()
{
	atf_check -o file:$(atf_get_srcdir)/d_tabs.out -s eq:1 \
	    sdiff "$(atf_get_srcdir)/d_tabs1.in" "$(atf_get_srcdir)/d_tabs2.in"
}

atf_test_case tabends
tabends_head()
{
	atf_set "descr" "Checks correct handling of lines ended with tabs"
}
tabends_body()
{
	atf_check -o file:$(atf_get_srcdir)/d_tabends_a.out -s eq:1 \
	    sdiff -w30 "$(atf_get_srcdir)/d_tabends.in" /dev/null

	atf_check -o file:$(atf_get_srcdir)/d_tabends_b.out -s eq:1 \
	    sdiff -w30 /dev/null "$(atf_get_srcdir)/d_tabends.in"

	atf_check -o file:$(atf_get_srcdir)/d_tabends_c.out -s eq:1 \
	    sdiff -w19 "$(atf_get_srcdir)/d_tabends.in" /dev/null
}

atf_test_case merge
merge_head()
{
	atf_set "descr" "Checks interactive merging"
}
merge_body()
{
	merge_tail="-o merge.out $(atf_get_srcdir)/d_input1 \
$(atf_get_srcdir)/d_input2 >/dev/null ; cat merge.out"

	cp $(atf_get_srcdir)/d_input* .

	atf_check -o file:d_input1 -x "yes l | sdiff ${merge_tail}"
	atf_check -o file:d_input2 -x "yes r | sdiff ${merge_tail}"

	atf_check -o file:d_input1 -x \
		"yes el | EDITOR=cat VISUAL=cat sdiff ${merge_tail}"
	atf_check -o file:d_input2 -x \
		"yes er | EDITOR=cat VISUAL=cat sdiff ${merge_tail}"

	atf_check -o file:d_input1 -x "yes l | sdiff -s ${merge_tail}"
	atf_check -o file:d_input2 -x "yes r | sdiff -s ${merge_tail}"
	atf_check -o file:d_input1 -x "yes l | sdiff -l ${merge_tail}"
	atf_check -o file:d_input2 -x "yes r | sdiff -l ${merge_tail}"
	atf_check -o file:d_input1 -x "yes l | sdiff -ls ${merge_tail}"
	atf_check -o file:d_input2 -x "yes r | sdiff -ls ${merge_tail}"

	atf_check -o file:d_input1 -x "{ while :; do echo s; echo l; \
echo v; echo l; done; } | sdiff ${merge_tail}"

	atf_check -o file:d_input2 -x "{ while :; do echo s; echo r; \
echo v; echo r; done; } | sdiff ${merge_tail}"
}

atf_test_case same
same_head()
{
	atf_set "descr" "Checks comparing file with itself"
}
same_body()
{
	atf_check -o file:$(atf_get_srcdir)/d_same.out \
	    sdiff "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input1"
}

atf_test_case oneline
oneline_head()
{
	atf_set "descr" "Checks comparing one-line files"
}
oneline_body()
{
	atf_check -o file:$(atf_get_srcdir)/d_oneline_a.out -s eq:1 \
	    sdiff /dev/null "$(atf_get_srcdir)/d_oneline.in"

	atf_check -o file:$(atf_get_srcdir)/d_oneline_b.out -s eq:1 \
	    sdiff "$(atf_get_srcdir)/d_oneline.in" /dev/null
}

atf_test_case dot
dot_head()
{
	atf_set "descr" "Checks comparing with file containing only one character"
}
dot_body()
{
	echo ".                                                               <" > expout
	atf_check -o file:expout -s eq:1 sdiff "$(atf_get_srcdir)/d_dot.in" /dev/null

	echo "                                                                > ." > expout
	atf_check -o file:expout -s eq:1 sdiff /dev/null "$(atf_get_srcdir)/d_dot.in"
}

atf_test_case stdin
stdin_head()
{
	atf_set "descr" "Checks reading data from stdin"
}
stdin_body()
{
	echo "                                                                > stdin" > expout
	atf_check -o file:expout -s eq:1 -x \
	    "echo stdin | sdiff /dev/null /dev/stdin"

	echo "stdin                                                           <" > expout
	atf_check -o file:expout -s eq:1 -x \
	    "echo stdin | sdiff /dev/stdin /dev/null"
}

atf_test_case short
short_head()
{
	atf_set "descr" "Checks premature stop of merging"
}
short_body()
{
	atf_check -o file:$(atf_get_srcdir)/d_short.out -x \
	    "printf \"r\\nl\\nr\\nl\" | sdiff -o merge.out $(atf_get_srcdir)/d_input1 \
$(atf_get_srcdir)/d_input2 >/dev/null ; cat merge.out"
}

atf_init_test_cases()
{
	atf_add_test_case flags
	atf_add_test_case iflags
	atf_add_test_case tabs
	atf_add_test_case tabends
	atf_add_test_case merge
	atf_add_test_case same
	atf_add_test_case oneline
	atf_add_test_case dot
	atf_add_test_case stdin
	atf_add_test_case short
}
OpenPOWER on IntegriCloud