Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/atf/atf-sh/misc_helpers.sh
39478 views
1
# Copyright (c) 2007 The NetBSD Foundation, Inc.
2
# All rights reserved.
3
#
4
# Redistribution and use in source and binary forms, with or without
5
# modification, are permitted provided that the following conditions
6
# are met:
7
# 1. Redistributions of source code must retain the above copyright
8
# notice, this list of conditions and the following disclaimer.
9
# 2. Redistributions in binary form must reproduce the above copyright
10
# notice, this list of conditions and the following disclaimer in the
11
# documentation and/or other materials provided with the distribution.
12
#
13
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14
# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26
# -------------------------------------------------------------------------
27
# Helper tests for "t_atf_check".
28
# -------------------------------------------------------------------------
29
30
atf_test_case atf_check_info_ok
31
atf_check_info_ok_head()
32
{
33
atf_set "descr" "Helper test case for the t_atf_check test program"
34
}
35
atf_check_info_ok_body()
36
{
37
atf_check -s eq:0 -o empty -e empty true
38
}
39
40
atf_test_case atf_check_info_fail
41
atf_check_info_fail_head()
42
{
43
atf_set "descr" "Helper test case for the t_atf_check test program"
44
}
45
atf_check_info_fail_body()
46
{
47
# In Solaris, /usr/bin/false returns 255 rather than 1. Use the
48
# built-in version for the check.
49
atf_check -s eq:1 -o empty -e empty sh -c "false"
50
}
51
52
atf_test_case atf_check_expout_mismatch
53
atf_check_expout_mismatch_head()
54
{
55
atf_set "descr" "Helper test case for the t_atf_check test program"
56
}
57
atf_check_expout_mismatch_body()
58
{
59
cat >expout <<SECONDEOF
60
foo
61
SECONDEOF
62
atf_check -s eq:0 -o file:expout -e empty echo bar
63
}
64
65
atf_test_case atf_check_experr_mismatch
66
atf_check_experr_mismatch_head()
67
{
68
atf_set "descr" "Helper test case for the t_atf_check test program"
69
}
70
atf_check_experr_mismatch_body()
71
{
72
cat >experr <<SECONDEOF
73
foo
74
SECONDEOF
75
atf_check -s eq:0 -o empty -e file:experr -x 'echo bar 1>&2'
76
}
77
78
atf_test_case atf_check_null_stdout
79
atf_check_null_stdout_head()
80
{
81
atf_set "descr" "Helper test case for the t_atf_check test program"
82
}
83
atf_check_null_stdout_body()
84
{
85
atf_check -s eq:0 -o empty -e empty echo "These are the contents"
86
}
87
88
atf_test_case atf_check_null_stderr
89
atf_check_null_stderr_head()
90
{
91
atf_set "descr" "Helper test case for the t_atf_check test program"
92
}
93
atf_check_null_stderr_body()
94
{
95
atf_check -s eq:0 -o empty -e empty -x 'echo "These are the contents" 1>&2'
96
}
97
98
atf_test_case atf_check_equal_ok
99
atf_check_equal_ok_head()
100
{
101
atf_set "descr" "Helper test case for the t_atf_check test program"
102
}
103
atf_check_equal_ok_body()
104
{
105
atf_check_equal a a
106
}
107
108
atf_test_case atf_check_equal_fail
109
atf_check_equal_fail_head()
110
{
111
atf_set "descr" "Helper test case for the t_atf_check test program"
112
}
113
atf_check_equal_fail_body()
114
{
115
atf_check_equal a b
116
}
117
118
atf_test_case atf_check_equal_eval_ok
119
atf_check_equal_eval_ok_head()
120
{
121
atf_set "descr" "Helper test case for the t_atf_check test program"
122
}
123
atf_check_equal_eval_ok_body()
124
{
125
x=a
126
y=a
127
atf_check_equal '${x}' '${y}'
128
}
129
130
atf_test_case atf_check_equal_eval_fail
131
atf_check_equal_eval_fail_head()
132
{
133
atf_set "descr" "Helper test case for the t_atf_check test program"
134
}
135
atf_check_equal_eval_fail_body()
136
{
137
x=a
138
y=b
139
atf_check_equal '${x}' '${y}'
140
}
141
142
atf_test_case atf_check_not_equal_ok
143
atf_check_not_equal_ok_head()
144
{
145
atf_set "descr" "Helper test case for the t_atf_check test program"
146
}
147
atf_check_not_equal_ok_body()
148
{
149
atf_check_not_equal a b
150
}
151
152
atf_test_case atf_check_not_equal_fail
153
atf_check_not_equal_fail_head()
154
{
155
atf_set "descr" "Helper test case for the t_atf_check test program"
156
}
157
atf_check_not_equal_fail_body()
158
{
159
atf_check_not_equal a a
160
}
161
162
atf_test_case atf_check_not_equal_eval_ok
163
atf_check_not_equal_eval_ok_head()
164
{
165
atf_set "descr" "Helper test case for the t_atf_check test program"
166
}
167
atf_check_not_equal_eval_ok_body()
168
{
169
x=a
170
y=b
171
atf_check_not_equal '${x}' '${y}'
172
}
173
174
atf_test_case atf_check_not_equal_eval_fail
175
atf_check_not_equal_eval_fail_head()
176
{
177
atf_set "descr" "Helper test case for the t_atf_check test program"
178
}
179
atf_check_not_equal_eval_fail_body()
180
{
181
x=a
182
y=a
183
atf_check_not_equal '${x}' '${y}'
184
}
185
186
atf_test_case atf_check_flush_stdout
187
atf_check_flush_stdout_head()
188
{
189
atf_set "descr" "Helper test case for the t_atf_check test program"
190
atf_set "timeout" "30"
191
}
192
atf_check_flush_stdout_body()
193
{
194
atf_check true
195
atf_check -s exit:1 false
196
touch "${CONTROL_FILE:-done}"
197
while :; do
198
sleep 1
199
done
200
}
201
202
# -------------------------------------------------------------------------
203
# Helper tests for "t_config".
204
# -------------------------------------------------------------------------
205
206
atf_test_case config_get
207
config_get_head()
208
{
209
atf_set "descr" "Helper test case for the t_config test program"
210
}
211
config_get_body()
212
{
213
if atf_config_has ${TEST_VARIABLE}; then
214
echo "${TEST_VARIABLE} = $(atf_config_get ${TEST_VARIABLE})"
215
fi
216
}
217
218
atf_test_case config_has
219
config_has_head()
220
{
221
atf_set "descr" "Helper test case for the t_config test program"
222
}
223
config_has_body()
224
{
225
if atf_config_has ${TEST_VARIABLE}; then
226
echo "${TEST_VARIABLE} found"
227
else
228
echo "${TEST_VARIABLE} not found"
229
fi
230
}
231
232
# -------------------------------------------------------------------------
233
# Helper tests for "t_normalize".
234
# -------------------------------------------------------------------------
235
236
atf_test_case normalize
237
normalize_head()
238
{
239
atf_set "descr" "Helper test case for the t_normalize test program"
240
atf_set "a.b" "test value 1"
241
atf_set "c-d" "test value 2"
242
}
243
normalize_body()
244
{
245
echo "a.b: $(atf_get a.b)"
246
echo "c-d: $(atf_get c-d)"
247
}
248
249
# -------------------------------------------------------------------------
250
# Helper tests for "t_tc".
251
# -------------------------------------------------------------------------
252
253
atf_test_case tc_pass_true
254
tc_pass_true_head()
255
{
256
atf_set "descr" "Helper test case for the t_tc test program"
257
}
258
tc_pass_true_body()
259
{
260
true
261
}
262
263
atf_test_case tc_pass_false
264
tc_pass_false_head()
265
{
266
atf_set "descr" "Helper test case for the t_tc test program"
267
}
268
tc_pass_false_body()
269
{
270
false
271
}
272
273
atf_test_case tc_pass_return_error
274
tc_pass_return_error_head()
275
{
276
atf_set "descr" "Helper test case for the t_tc test program"
277
}
278
tc_pass_return_error_body()
279
{
280
return 1
281
}
282
283
atf_test_case tc_fail
284
tc_fail_head()
285
{
286
atf_set "descr" "Helper test case for the t_tc test program"
287
}
288
tc_fail_body()
289
{
290
echo "An error" 1>&2
291
exit 1
292
}
293
294
atf_test_case tc_missing_body
295
tc_missing_body_head()
296
{
297
atf_set "descr" "Helper test case for the t_tc test program"
298
}
299
300
# -------------------------------------------------------------------------
301
# Helper tests for "t_tp".
302
# -------------------------------------------------------------------------
303
304
atf_test_case tp_srcdir
305
tp_srcdir_head()
306
{
307
atf_set "descr" "Helper test case for the t_tp test program"
308
}
309
tp_srcdir_body()
310
{
311
echo "Calling helper"
312
helper_subr || atf_fail "Could not call helper subroutine"
313
}
314
315
# -------------------------------------------------------------------------
316
# Main.
317
# -------------------------------------------------------------------------
318
319
atf_init_test_cases()
320
{
321
# Add helper tests for t_atf_check.
322
atf_add_test_case atf_check_info_ok
323
atf_add_test_case atf_check_info_fail
324
atf_add_test_case atf_check_expout_mismatch
325
atf_add_test_case atf_check_experr_mismatch
326
atf_add_test_case atf_check_null_stdout
327
atf_add_test_case atf_check_null_stderr
328
atf_add_test_case atf_check_equal_ok
329
atf_add_test_case atf_check_equal_fail
330
atf_add_test_case atf_check_equal_eval_ok
331
atf_add_test_case atf_check_equal_eval_fail
332
atf_add_test_case atf_check_not_equal_ok
333
atf_add_test_case atf_check_not_equal_fail
334
atf_add_test_case atf_check_not_equal_eval_ok
335
atf_add_test_case atf_check_not_equal_eval_fail
336
atf_add_test_case atf_check_flush_stdout
337
338
# Add helper tests for t_config.
339
atf_add_test_case config_get
340
atf_add_test_case config_has
341
342
# Add helper tests for t_normalize.
343
atf_add_test_case normalize
344
345
# Add helper tests for t_tc.
346
atf_add_test_case tc_pass_true
347
atf_add_test_case tc_pass_false
348
atf_add_test_case tc_pass_return_error
349
atf_add_test_case tc_fail
350
atf_add_test_case tc_missing_body
351
352
# Add helper tests for t_tp.
353
[ -f $(atf_get_srcdir)/subrs ] && . $(atf_get_srcdir)/subrs
354
atf_add_test_case tp_srcdir
355
}
356
357
# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
358
359