xref: /freebsd/usr.bin/rs/tests/rs_test.sh (revision a90b9d0159070121c221b966469c3e36d912bf82)
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#
27
28atf_test_case c_flag
29c_flag_head()
30{
31	atf_set "descr" "Verify the usage of option 'c'"
32}
33
34c_flag_body()
35{
36	atf_check -s exit:0 -o inline:"1  2  3  4
375  6  7  8
38" rs -c, 2 <<EOF
391,2,3,4,5,6,7,8
40EOF
41}
42
43atf_test_case s_flag
44s_flag_head()
45{
46	atf_set "descr" "Verify the usage of option 's'"
47}
48
49s_flag_body()
50{
51	atf_check -s exit:0 -o inline:"1  2  3  4
525  6  7  8
53" rs -s% 2 <<EOF
541%%2%%3%4%5%%%6%%%7%8
55EOF
56
57}
58
59atf_test_case C_flag
60C_flag_head()
61{
62	atf_set "descr" "Verify the usage of option 'C'"
63}
64
65C_flag_body()
66{
67	atf_check -s exit:0 -o inline:"1,2,3,4,
685,6,7,8,
69" rs -C, 2 <<EOF
701 2 3 4 5 6 7 8
71EOF
72}
73
74atf_test_case S_flag
75S_flag_head()
76{
77	atf_set "descr" "Verify the usage of option 'S'"
78}
79
80S_flag_body()
81{
82	atf_check -s exit:0 -o inline:"1,,2,,3,,4
835,,6,,7,,8
84" rs -S, 2 <<EOF
851 2 3 4 5 6 7 8
86EOF
87}
88
89atf_test_case t_flag
90t_flag_head()
91{
92	atf_set "descr" "Verify the usage of option 't'"
93}
94
95t_flag_body()
96{
97	atf_check -s exit:0 -o inline:"1  4  7
982  5  8
993  6
100" rs -t 3 <<EOF
1011 2 3 4 5 6 7 8
102EOF
103}
104
105atf_test_case T_flag
106T_flag_head()
107{
108	atf_set "descr" "Verify the usage of option 'T'"
109}
110
111T_flag_body()
112{
113	atf_check -s exit:0 -o inline:"1
1142
1153
116" rs -T <<EOF
1171 2 3
118EOF
119}
120
121atf_test_case k_flag
122k_flag_head()
123{
124	atf_set "descr" "Verify the usage of option 'k'"
125}
126
127k_flag_body()
128{
129	atf_check -s exit:0 -o inline:"3  4  5
1306  7  8
131" rs -k 1 2 <<EOF
1321 2
1333 4 5 6
1347 8
135EOF
136}
137
138atf_test_case K_flag
139K_flag_head()
140{
141	atf_set "descr" "Verify the usage of option 'K'"
142}
143
144K_flag_body()
145{
146	atf_check -s exit:0 -o inline:"
147" rs -K 1 < /dev/null
148}
149
150atf_test_case g_flag
151g_flag_head()
152{
153	atf_set "descr" "Verify the usage of option 'g'"
154}
155
156g_flag_body()
157{
158	atf_check -s exit:0 -o inline:"1 2 3 4
1595 6 7 8
160" rs -g 1 2 <<EOF
1611 2 3 4 5 6 7 8
162EOF
163}
164
165atf_test_case G_flag
166G_flag_head()
167{
168	atf_set "descr" "Verify the usage of option 'G'"
169}
170
171G_flag_body()
172{
173	atf_check -s exit:0 -o inline:"1                2                3                4
1745                6                7                acbdefghij
175" rs -G 50 2 <<EOF
1761 2 3 4 5 6 7 acbdefghij
177EOF
178}
179
180atf_test_case e_flag
181e_flag_head()
182{
183	atf_set "descr" "Verify the usage of option 'e'"
184}
185
186e_flag_body()
187{
188	atf_check -s exit:0 -o inline:"
189" rs -e < /dev/null
190}
191
192atf_test_case n_flag
193n_flag_head()
194{
195	atf_set "descr" "Verify the usage of option 'n'"
196}
197
198n_flag_body()
199{
200	atf_check -s exit:0 -o inline:"1  2  3
2014  5
2026  7
203" rs -n 0 3 <<EOF
2041 2 3
2054 5
2066 7
207EOF
208}
209
210atf_test_case y_flag
211y_flag_head()
212{
213	atf_set "descr" "Verify the usage of option 'y'"
214}
215
216y_flag_body()
217{
218	atf_check -s exit:0 -o inline:"1  2  3
2194  5  6
2207  8  1
221" rs -y 3 <<EOF
2221 2 3 4 5 6 7 8
223EOF
224}
225
226atf_test_case h_flag
227h_flag_head()
228{
229	atf_set "descr" "Verify the usage of option 'h'"
230}
231
232h_flag_body()
233{
234	atf_check -s exit:0 -o inline:"1 0
235" rs -h < /dev/null
236}
237
238atf_test_case H_flag
239H_flag_head()
240{
241	atf_set "descr" "Verify the usage of option 'H'"
242}
243
244H_flag_body()
245{
246	atf_check -s exit:0 -o inline:" 0 line 1
2471 0
248" rs -H < /dev/null
249}
250
251atf_test_case j_flag
252j_flag_head()
253{
254	atf_set "descr" "Verify the usage of option 'j'"
255}
256
257j_flag_body()
258{
259	atf_check -s exit:0 -o inline:"  1    2    3
260abc  def  ghi
261" rs -j 2 <<EOF
2621 2 3 abc def ghi
263EOF
264}
265
266atf_test_case m_flag
267m_flag_head()
268{
269	atf_set "descr" "Verify the usage of option 'm'"
270}
271
272m_flag_body()
273{
274	atf_check -s exit:0 -o inline:"1    2    3
275abc  def  ghi
276" rs -m 2 <<EOF
2771 2 3 abc def ghi
278EOF
279}
280
281atf_test_case z_flag
282z_flag_head()
283{
284	atf_set "descr" "Verify the usage of option 'z'"
285}
286
287z_flag_body()
288{
289	atf_check -s exit:0 -o inline:"1  2  3  4
2905  6  7  acbdefghij
291" rs -z 2 <<EOF
2921 2 3 4 5 6 7 acbdefghij
293EOF
294}
295
296atf_test_case invalid_usage
297invalid_usage_head()
298{
299	atf_set "descr" "Verify that an invalid usage with a supported option produces a valid error message"
300}
301
302invalid_usage_body()
303{
304	atf_check -s not-exit:0 -e inline:"rs: option requires an argument -- w
305usage: rs [-[csCS][x][kKgGw][N]tTeEnyjhHmz] [rows [cols]]
306" rs -w
307}
308
309atf_test_case no_arguments
310no_arguments_head()
311{
312	atf_set "descr" "Verify that rs(1) executes successfully and produces a valid output when invoked without any arguments"
313}
314
315no_arguments_body()
316{
317	atf_check -s exit:0 -o inline:"1 2 3 4 5 6 7 8
318" rs <<EOF
3191 2 3 4 5 6 7 8
320EOF
321}
322
323atf_test_case rows_2
324rows_2_head()
325{
326	atf_set "descr" "Simple output with 2 rows"
327}
328
329rows_2_body()
330{
331	atf_check -s exit:0 -o inline:"1  2  3  4
3325  6  7  8
333" rs 2 <<EOF
3341 2 3 4 5 6 7 8
335EOF
336}
337
338atf_test_case rows_3
339rows_3_head()
340{
341	atf_set "descr" "Simple output with 3 rows"
342}
343
344rows_3_body()
345{
346	atf_check -s exit:0 -o inline:"1  2  3
3474  5  6
3487  8
349" rs 3 <<EOF
3501 2 3 4 5 6 7 8
351EOF
352}
353
354atf_test_case rows_4
355rows_4_head()
356{
357	atf_set "descr" "Simple output with 4 rows"
358}
359
360rows_4_body()
361{
362	atf_check -s exit:0 -o inline:"1  2
3633  4
3645  6
3657  8
366" rs 4 <<EOF
3671 2 3 4 5 6 7 8
368EOF
369}
370
371atf_init_test_cases()
372{
373	atf_add_test_case c_flag
374	atf_add_test_case s_flag
375	atf_add_test_case C_flag
376	atf_add_test_case S_flag
377	atf_add_test_case t_flag
378	atf_add_test_case T_flag
379	atf_add_test_case k_flag
380	atf_add_test_case K_flag
381	atf_add_test_case g_flag
382	atf_add_test_case G_flag
383	atf_add_test_case e_flag
384	atf_add_test_case n_flag
385	atf_add_test_case y_flag
386	atf_add_test_case h_flag
387	atf_add_test_case H_flag
388	atf_add_test_case j_flag
389	atf_add_test_case m_flag
390	atf_add_test_case z_flag
391	atf_add_test_case invalid_usage
392	atf_add_test_case no_arguments
393	atf_add_test_case rows_2
394	atf_add_test_case rows_3
395	atf_add_test_case rows_4
396}
397