xref: /freebsd/usr.bin/rs/tests/rs_test.sh (revision 0957b409)
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 empty rs -c < /dev/null
38}
39
40atf_test_case s_flag
41s_flag_head()
42{
43	atf_set "descr" "Verify the usage of option 's'"
44}
45
46s_flag_body()
47{
48	atf_check -s exit:0 -o empty rs -s < /dev/null
49}
50
51atf_test_case C_flag
52C_flag_head()
53{
54	atf_set "descr" "Verify the usage of option 'C'"
55}
56
57C_flag_body()
58{
59	atf_check -s exit:0 -o empty rs -C < /dev/null
60}
61
62atf_test_case S_flag
63S_flag_head()
64{
65	atf_set "descr" "Verify the usage of option 'S'"
66}
67
68S_flag_body()
69{
70	atf_check -s exit:0 -o empty rs -S < /dev/null
71}
72
73atf_test_case t_flag
74t_flag_head()
75{
76	atf_set "descr" "Verify the usage of option 't'"
77}
78
79t_flag_body()
80{
81	atf_check -s exit:0 -o empty rs -t < /dev/null
82}
83
84atf_test_case T_flag
85T_flag_head()
86{
87	atf_set "descr" "Verify the usage of option 'T'"
88}
89
90T_flag_body()
91{
92	atf_check -s exit:0 -o empty rs -T < /dev/null
93}
94
95atf_test_case k_flag
96k_flag_head()
97{
98	atf_set "descr" "Verify the usage of option 'k'"
99}
100
101k_flag_body()
102{
103	atf_check -s exit:0 -o empty rs -k < /dev/null
104}
105
106atf_test_case K_flag
107K_flag_head()
108{
109	atf_set "descr" "Verify the usage of option 'K'"
110}
111
112K_flag_body()
113{
114	atf_check -s exit:0 -o inline:"
115" rs -K < /dev/null
116}
117
118atf_test_case g_flag
119g_flag_head()
120{
121	atf_set "descr" "Verify the usage of option 'g'"
122}
123
124g_flag_body()
125{
126	atf_check -s exit:0 -o empty rs -g < /dev/null
127}
128
129atf_test_case G_flag
130G_flag_head()
131{
132	atf_set "descr" "Verify the usage of option 'G'"
133}
134
135G_flag_body()
136{
137	atf_check -s exit:0 -o empty rs -G < /dev/null
138}
139
140atf_test_case e_flag
141e_flag_head()
142{
143	atf_set "descr" "Verify the usage of option 'e'"
144}
145
146e_flag_body()
147{
148	atf_check -s exit:0 -o inline:"
149" rs -e < /dev/null
150}
151
152atf_test_case n_flag
153n_flag_head()
154{
155	atf_set "descr" "Verify the usage of option 'n'"
156}
157
158n_flag_body()
159{
160	atf_check -s exit:0 -o empty rs -n < /dev/null
161}
162
163atf_test_case y_flag
164y_flag_head()
165{
166	atf_set "descr" "Verify the usage of option 'y'"
167}
168
169y_flag_body()
170{
171	atf_check -s exit:0 -o empty rs -y < /dev/null
172}
173
174atf_test_case h_flag
175h_flag_head()
176{
177	atf_set "descr" "Verify the usage of option 'h'"
178}
179
180h_flag_body()
181{
182	atf_check -s exit:0 -o inline:"1 0
183" rs -h < /dev/null
184}
185
186atf_test_case H_flag
187H_flag_head()
188{
189	atf_set "descr" "Verify the usage of option 'H'"
190}
191
192H_flag_body()
193{
194	atf_check -s exit:0 -o inline:" 0 line 1
1951 0
196" rs -H < /dev/null
197}
198
199atf_test_case j_flag
200j_flag_head()
201{
202	atf_set "descr" "Verify the usage of option 'j'"
203}
204
205j_flag_body()
206{
207	atf_check -s exit:0 -o empty rs -j < /dev/null
208}
209
210atf_test_case m_flag
211m_flag_head()
212{
213	atf_set "descr" "Verify the usage of option 'm'"
214}
215
216m_flag_body()
217{
218	atf_check -s exit:0 -o empty rs -m < /dev/null
219}
220
221atf_test_case z_flag
222z_flag_head()
223{
224	atf_set "descr" "Verify the usage of option 'z'"
225}
226
227z_flag_body()
228{
229	atf_check -s exit:0 -o empty rs -z < /dev/null
230}
231
232atf_test_case invalid_usage
233invalid_usage_head()
234{
235	atf_set "descr" "Verify that an invalid usage with a supported option produces a valid error message"
236}
237
238invalid_usage_body()
239{
240	atf_check -s not-exit:0 -e inline:"rs: width must be a positive integer
241" rs -w
242}
243
244atf_test_case no_arguments
245no_arguments_head()
246{
247	atf_set "descr" "Verify that rs(1) executes successfully and produces a valid output when invoked without any arguments"
248}
249
250no_arguments_body()
251{
252	atf_check -s exit:0 -o inline:"
253" rs < /dev/null
254}
255
256atf_init_test_cases()
257{
258	atf_add_test_case c_flag
259	atf_add_test_case s_flag
260	atf_add_test_case C_flag
261	atf_add_test_case S_flag
262	atf_add_test_case t_flag
263	atf_add_test_case T_flag
264	atf_add_test_case k_flag
265	atf_add_test_case K_flag
266	atf_add_test_case g_flag
267	atf_add_test_case G_flag
268	atf_add_test_case e_flag
269	atf_add_test_case n_flag
270	atf_add_test_case y_flag
271	atf_add_test_case h_flag
272	atf_add_test_case H_flag
273	atf_add_test_case j_flag
274	atf_add_test_case m_flag
275	atf_add_test_case z_flag
276	atf_add_test_case invalid_usage
277	atf_add_test_case no_arguments
278}
279