xref: /freebsd/usr.bin/rs/tests/rs_test.sh (revision 19fae0f66023a97a9b464b3beeeabb2081f575b3)
1#
2# Copyright 2017 Shivansh
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9#    notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24# SUCH DAMAGE.
25#
26# $FreeBSD$
27#
28
29atf_test_case c_flag
30c_flag_head()
31{
32	atf_set "descr" "Verify the usage of option 'c'"
33}
34
35c_flag_body()
36{
37	atf_check -s exit:0 -o inline:"1  2  3  4
385  6  7  8
39" rs -c, 2 <<EOF
401,2,3,4,5,6,7,8
41EOF
42}
43
44atf_test_case s_flag
45s_flag_head()
46{
47	atf_set "descr" "Verify the usage of option 's'"
48}
49
50s_flag_body()
51{
52	atf_check -s exit:0 -o inline:"1  2  3  4
535  6  7  8
54" rs -s% 2 <<EOF
551%%2%%3%4%5%%%6%%%7%8
56EOF
57
58}
59
60atf_test_case C_flag
61C_flag_head()
62{
63	atf_set "descr" "Verify the usage of option 'C'"
64}
65
66C_flag_body()
67{
68	atf_check -s exit:0 -o inline:"1,2,3,4,
695,6,7,8,
70" rs -C, 2 <<EOF
711 2 3 4 5 6 7 8
72EOF
73}
74
75atf_test_case S_flag
76S_flag_head()
77{
78	atf_set "descr" "Verify the usage of option 'S'"
79}
80
81S_flag_body()
82{
83	atf_check -s exit:0 -o inline:"1,,2,,3,,4
845,,6,,7,,8
85" rs -S, 2 <<EOF
861 2 3 4 5 6 7 8
87EOF
88}
89
90atf_test_case t_flag
91t_flag_head()
92{
93	atf_set "descr" "Verify the usage of option 't'"
94}
95
96t_flag_body()
97{
98	atf_check -s exit:0 -o inline:"1  4  7
992  5  8
1003  6
101" rs -t 3 <<EOF
1021 2 3 4 5 6 7 8
103EOF
104}
105
106atf_test_case T_flag
107T_flag_head()
108{
109	atf_set "descr" "Verify the usage of option 'T'"
110}
111
112T_flag_body()
113{
114	atf_check -s exit:0 -o inline:"1
1152
1163
117" rs -T <<EOF
1181 2 3
119EOF
120}
121
122atf_test_case k_flag
123k_flag_head()
124{
125	atf_set "descr" "Verify the usage of option 'k'"
126}
127
128k_flag_body()
129{
130	atf_check -s exit:0 -o inline:"3  4  5
1316  7  8
132" rs -k 1 2 <<EOF
1331 2
1343 4 5 6
1357 8
136EOF
137}
138
139atf_test_case K_flag
140K_flag_head()
141{
142	atf_set "descr" "Verify the usage of option 'K'"
143}
144
145K_flag_body()
146{
147	atf_check -s exit:0 -o inline:"
148" rs -K 1 < /dev/null
149}
150
151atf_test_case g_flag
152g_flag_head()
153{
154	atf_set "descr" "Verify the usage of option 'g'"
155}
156
157g_flag_body()
158{
159	atf_check -s exit:0 -o inline:"1 2 3 4
1605 6 7 8
161" rs -g 1 2 <<EOF
1621 2 3 4 5 6 7 8
163EOF
164}
165
166atf_test_case G_flag
167G_flag_head()
168{
169	atf_set "descr" "Verify the usage of option 'G'"
170}
171
172G_flag_body()
173{
174	atf_check -s exit:0 -o inline:"1                2                3                4
1755                6                7                acbdefghij
176" rs -G 50 2 <<EOF
1771 2 3 4 5 6 7 acbdefghij
178EOF
179}
180
181atf_test_case e_flag
182e_flag_head()
183{
184	atf_set "descr" "Verify the usage of option 'e'"
185}
186
187e_flag_body()
188{
189	atf_check -s exit:0 -o inline:"
190" rs -e < /dev/null
191}
192
193atf_test_case n_flag
194n_flag_head()
195{
196	atf_set "descr" "Verify the usage of option 'n'"
197}
198
199n_flag_body()
200{
201	atf_check -s exit:0 -o inline:"1  2  3
2024  5
2036  7
204" rs -n 0 3 <<EOF
2051 2 3
2064 5
2076 7
208EOF
209}
210
211atf_test_case y_flag
212y_flag_head()
213{
214	atf_set "descr" "Verify the usage of option 'y'"
215}
216
217y_flag_body()
218{
219	atf_check -s exit:0 -o inline:"1  2  3
2204  5  6
2217  8  1
222" rs -y 3 <<EOF
2231 2 3 4 5 6 7 8
224EOF
225}
226
227atf_test_case h_flag
228h_flag_head()
229{
230	atf_set "descr" "Verify the usage of option 'h'"
231}
232
233h_flag_body()
234{
235	atf_check -s exit:0 -o inline:"1 0
236" rs -h < /dev/null
237}
238
239atf_test_case H_flag
240H_flag_head()
241{
242	atf_set "descr" "Verify the usage of option 'H'"
243}
244
245H_flag_body()
246{
247	atf_check -s exit:0 -o inline:" 0 line 1
2481 0
249" rs -H < /dev/null
250}
251
252atf_test_case j_flag
253j_flag_head()
254{
255	atf_set "descr" "Verify the usage of option 'j'"
256}
257
258j_flag_body()
259{
260	atf_check -s exit:0 -o inline:"  1    2    3
261abc  def  ghi
262" rs -j 2 <<EOF
2631 2 3 abc def ghi
264EOF
265}
266
267atf_test_case m_flag
268m_flag_head()
269{
270	atf_set "descr" "Verify the usage of option 'm'"
271}
272
273m_flag_body()
274{
275	atf_check -s exit:0 -o inline:"1    2    3
276abc  def  ghi
277" rs -m 2 <<EOF
2781 2 3 abc def ghi
279EOF
280}
281
282atf_test_case z_flag
283z_flag_head()
284{
285	atf_set "descr" "Verify the usage of option 'z'"
286}
287
288z_flag_body()
289{
290	atf_check -s exit:0 -o inline:"1  2  3  4
2915  6  7  acbdefghij
292" rs -z 2 <<EOF
2931 2 3 4 5 6 7 acbdefghij
294EOF
295}
296
297atf_test_case invalid_usage
298invalid_usage_head()
299{
300	atf_set "descr" "Verify that an invalid usage with a supported option produces a valid error message"
301}
302
303invalid_usage_body()
304{
305	atf_check -s not-exit:0 -e inline:"rs: option requires an argument -- w
306usage: rs [-[csCS][x][kKgGw][N]tTeEnyjhHmz] [rows [cols]]
307" rs -w
308}
309
310atf_test_case no_arguments
311no_arguments_head()
312{
313	atf_set "descr" "Verify that rs(1) executes successfully and produces a valid output when invoked without any arguments"
314}
315
316no_arguments_body()
317{
318	atf_check -s exit:0 -o inline:"1 2 3 4 5 6 7 8
319" rs <<EOF
3201 2 3 4 5 6 7 8
321EOF
322}
323
324atf_test_case rows_2
325rows_2_head()
326{
327	atf_set "descr" "Simple output with 2 rows"
328}
329
330rows_2_body()
331{
332	atf_check -s exit:0 -o inline:"1  2  3  4
3335  6  7  8
334" rs 2 <<EOF
3351 2 3 4 5 6 7 8
336EOF
337}
338
339atf_test_case rows_3
340rows_3_head()
341{
342	atf_set "descr" "Simple output with 3 rows"
343}
344
345rows_3_body()
346{
347	atf_check -s exit:0 -o inline:"1  2  3
3484  5  6
3497  8
350" rs 3 <<EOF
3511 2 3 4 5 6 7 8
352EOF
353}
354
355atf_test_case rows_4
356rows_4_head()
357{
358	atf_set "descr" "Simple output with 4 rows"
359}
360
361rows_4_body()
362{
363	atf_check -s exit:0 -o inline:"1  2
3643  4
3655  6
3667  8
367" rs 4 <<EOF
3681 2 3 4 5 6 7 8
369EOF
370}
371
372atf_init_test_cases()
373{
374	atf_add_test_case c_flag
375	atf_add_test_case s_flag
376	atf_add_test_case C_flag
377	atf_add_test_case S_flag
378	atf_add_test_case t_flag
379	atf_add_test_case T_flag
380	atf_add_test_case k_flag
381	atf_add_test_case K_flag
382	atf_add_test_case g_flag
383	atf_add_test_case G_flag
384	atf_add_test_case e_flag
385	atf_add_test_case n_flag
386	atf_add_test_case y_flag
387	atf_add_test_case h_flag
388	atf_add_test_case H_flag
389	atf_add_test_case j_flag
390	atf_add_test_case m_flag
391	atf_add_test_case z_flag
392	atf_add_test_case invalid_usage
393	atf_add_test_case no_arguments
394	atf_add_test_case rows_2
395	atf_add_test_case rows_3
396	atf_add_test_case rows_4
397}
398