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