t_builtins.sh revision 1.4 1 1.4 kre # $NetBSD: t_builtins.sh,v 1.4 2018/12/12 11:52:05 kre Exp $
2 1.1 kre #
3 1.2 kre # Copyright (c) 2018 The NetBSD Foundation, Inc.
4 1.1 kre # All rights reserved.
5 1.1 kre #
6 1.1 kre # Redistribution and use in source and binary forms, with or without
7 1.1 kre # modification, are permitted provided that the following conditions
8 1.1 kre # are met:
9 1.1 kre # 1. Redistributions of source code must retain the above copyright
10 1.1 kre # notice, this list of conditions and the following disclaimer.
11 1.1 kre # 2. Redistributions in binary form must reproduce the above copyright
12 1.1 kre # notice, this list of conditions and the following disclaimer in the
13 1.1 kre # documentation and/or other materials provided with the distribution.
14 1.1 kre #
15 1.1 kre # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1 kre # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1 kre # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1 kre # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1 kre # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1 kre # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1 kre # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1 kre # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1 kre # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1 kre # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 kre # POSSIBILITY OF SUCH DAMAGE.
26 1.1 kre #
27 1.1 kre # the implementation of "sh" to test
28 1.1 kre : ${TEST_SH:="/bin/sh"}
29 1.1 kre
30 1.1 kre #
31 1.1 kre # This file tests the various sh builtin utilities.
32 1.1 kre #
33 1.1 kre # Those utilities that are really external programs, which are builtin in
34 1.1 kre # for (mostly) performance (printf, kill, test, ...), are tested elsewhere.
35 1.1 kre # We do test the builtin "echo" here as (in NetBSD) it is different than
36 1.1 kre # the external one.
37 1.1 kre #
38 1.1 kre # The (mostly special) builtins which appear to be more syntax than command
39 1.1 kre # are tested in other test programs, rather than here (break, continue...)
40 1.1 kre #
41 1.1 kre # And finally, those which are fundamental to the operation of the shell,
42 1.1 kre # like wait, set, shift, ... are also tested in other test programs where
43 1.1 kre # all their operations can be more thoroughly verified.
44 1.1 kre #
45 1.1 kre # This leaves those which need to be built in (cd, umask, ...) but whose
46 1.1 kre # purpose is mostly to alter the environment in which the shell operates
47 1.1 kre # of that of the commands it runs. These tests act in co-operation with
48 1.1 kre # other tests exist here (where thy do) by not duplicating tests run
49 1.1 kre # elsewhere (ulimit is one example) but just adding to those.
50 1.1 kre # One day these might be unified.
51 1.1 kre #
52 1.1 kre # We do test both standard use of the builtins (where they are standard)
53 1.1 kre # and NetBSD sh extensions (when run on a shell with no support, such tests
54 1.1 kre # should be skipped.)
55 1.1 kre #
56 1.1 kre
57 1.1 kre # Utility function able to test whether most of the builtins exist in
58 1.1 kre # the shell being tested.
59 1.1 kre have_builtin()
60 1.1 kre {
61 1.1 kre ${TEST_SH} -c "( $3 $1 $4 ) >/dev/null 2>&1" &&
62 1.1 kre LC_ALL=C ${TEST_SH} -c \
63 1.1 kre 'case "$( (type '"$1"') 2>&1)" in
64 1.1 kre (*built*) exit 0 ;;
65 1.3 kre (*reserved*) exit 0 ;; # zsh!! (reserved words are builtin)
66 1.1 kre esac
67 1.1 kre exit 1' ||
68 1.1 kre {
69 1.1 kre test -z "$2" && atf_skip "${TEST_SH} has no '$1$5' built-in"
70 1.1 kre return 1;
71 1.1 kre }
72 1.1 kre
73 1.1 kre return 0
74 1.1 kre }
75 1.1 kre
76 1.1 kre ### Helper functions
77 1.1 kre
78 1.1 kre nl='
79 1.1 kre '
80 1.1 kre reset()
81 1.1 kre {
82 1.1 kre TEST_NUM=0
83 1.1 kre TEST_FAILURES=''
84 1.1 kre TEST_FAIL_COUNT=0
85 1.1 kre TEST_ID="$1"
86 1.1 kre
87 1.1 kre # These are used in check()
88 1.1 kre atf_require_prog tr
89 1.1 kre atf_require_prog printf
90 1.1 kre atf_require_prog mktemp
91 1.1 kre }
92 1.1 kre
93 1.1 kre # Test run & validate.
94 1.1 kre #
95 1.1 kre # $1 is the command to run (via sh -c)
96 1.1 kre # $2 is the expected output
97 1.1 kre # $3 is the expected exit status from sh
98 1.1 kre # $4 is optional extra data for the error msg (if there is one)
99 1.1 kre #
100 1.1 kre # Stderr is exxpected to be empty, unless the expected exit code ($3) is != 0
101 1.1 kre # in which case some message there is expected (and nothing is a failure).
102 1.1 kre # When non-zero exit is expected, we note a different (non-zero) value
103 1.1 kre # observed, but do not fail the test because of that.
104 1.1 kre
105 1.1 kre check()
106 1.1 kre {
107 1.1 kre fail=false
108 1.1 kre TEMP_FILE=$( mktemp OUT.XXXXXX )
109 1.1 kre TEST_NUM=$(( $TEST_NUM + 1 ))
110 1.1 kre MSG=
111 1.1 kre
112 1.1 kre # our local shell (ATF_SHELL) better do quoting correctly...
113 1.1 kre # some of the tests expect us to expand $nl internally...
114 1.1 kre CMD="$1"
115 1.1 kre
116 1.1 kre # determine what the test generates, preserving trailing \n's
117 1.1 kre result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" && printf X )"
118 1.1 kre STATUS=$?
119 1.1 kre result="${result%X}"
120 1.1 kre
121 1.1 kre
122 1.1 kre if [ "${STATUS}" -ne "$3" ]; then
123 1.1 kre MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
124 1.1 kre MSG="${MSG} expected exit code $3, got ${STATUS}"
125 1.1 kre
126 1.1 kre # don't actually fail just because of wrong exit code
127 1.1 kre # unless we either expected, or received "good"
128 1.1 kre # or something else is detected as incorrect as well.
129 1.1 kre case "$3/${STATUS}" in
130 1.1 kre (*/0|0/*) fail=true;;
131 1.1 kre esac
132 1.1 kre fi
133 1.1 kre
134 1.1 kre if [ "$3" -eq 0 ]; then
135 1.1 kre if [ -s "${TEMP_FILE}" ]; then
136 1.1 kre MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
137 1.1 kre MSG="${MSG} Messages produced on stderr unexpected..."
138 1.1 kre MSG="${MSG}${nl}$( cat "${TEMP_FILE}" )"
139 1.1 kre fail=true
140 1.1 kre fi
141 1.1 kre else
142 1.1 kre if ! [ -s "${TEMP_FILE}" ]; then
143 1.1 kre MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
144 1.1 kre MSG="${MSG} Expected messages on stderr,"
145 1.1 kre MSG="${MSG} nothing produced"
146 1.1 kre fail=true
147 1.1 kre fi
148 1.1 kre fi
149 1.1 kre rm -f "${TEMP_FILE}"
150 1.1 kre
151 1.1 kre if [ "$2" != "${result}" ]
152 1.1 kre then
153 1.1 kre MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
154 1.1 kre MSG="${MSG} Expected: <<$2>>, received: <<$result>>"
155 1.1 kre fail=true
156 1.1 kre fi
157 1.1 kre
158 1.1 kre if $fail
159 1.1 kre then
160 1.1 kre if [ -n "$4" ]; then
161 1.1 kre MSG="${MSG}${MSG:+${nl}}[$TEST_NUM] Note: ${4}"
162 1.1 kre fi
163 1.1 kre MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
164 1.1 kre MSG="${MSG} Full command: <<${CMD}>>"
165 1.1 kre fi
166 1.1 kre
167 1.1 kre $fail && test -n "$TEST_ID" && {
168 1.1 kre TEST_FAILURES="${TEST_FAILURES}${TEST_FAILURES:+${nl}}"
169 1.1 kre TEST_FAILURES="${TEST_FAILURES}${TEST_ID}[$TEST_NUM]:"
170 1.1 kre TEST_FAILURES="${TEST_FAILURES} Test of <<$1>> failed.";
171 1.1 kre TEST_FAILURES="${TEST_FAILURES}${nl}${MSG}"
172 1.1 kre TEST_FAIL_COUNT=$(( $TEST_FAIL_COUNT + 1 ))
173 1.1 kre return 0
174 1.1 kre }
175 1.1 kre $fail && atf_fail "Test[$TEST_NUM] failed: $(
176 1.1 kre # ATF does not like newlines in messages, so change them...
177 1.1 kre printf '%s' "${MSG}" | tr '\n' ';'
178 1.1 kre )"
179 1.1 kre return 0
180 1.1 kre }
181 1.1 kre
182 1.1 kre results()
183 1.1 kre {
184 1.1 kre test -n "$1" && atf_expect_fail "$1"
185 1.1 kre
186 1.1 kre test -z "${TEST_ID}" && return 0
187 1.1 kre test -z "${TEST_FAILURES}" && return 0
188 1.1 kre
189 1.1 kre echo >&2 "=========================================="
190 1.1 kre echo >&2 "While testing '${TEST_ID}'"
191 1.1 kre echo >&2 " - - - - - - - - - - - - - - - - -"
192 1.1 kre echo >&2 "${TEST_FAILURES}"
193 1.1 kre
194 1.1 kre atf_fail \
195 1.1 kre "Test ${TEST_ID}: $TEST_FAIL_COUNT (of $TEST_NUM) subtests failed - see stderr"
196 1.1 kre }
197 1.1 kre
198 1.1 kre ####### End helpers
199 1.1 kre
200 1.1 kre atf_test_case colon
201 1.1 kre colon_head() {
202 1.1 kre atf_set "descr" "Tests the shell special builtin ':' command"
203 1.1 kre }
204 1.1 kre colon_body() {
205 1.1 kre have_builtin : || return 0
206 1.1 kre
207 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c ":"
208 1.1 kre
209 1.1 kre # ':' is a special builtin, so we should exit on redirect error
210 1.1 kre # and variable assignments should persist (stupid, but it is the rule)
211 1.1 kre
212 1.1 kre atf_check -s not-exit:0 -e not-empty -o empty ${TEST_SH} -c \
213 1.1 kre ": >/foo/bar; printf %s No-exit-BUG"
214 1.1 kre atf_check -s exit:0 -e empty -o inline:OK ${TEST_SH} -c \
215 1.1 kre 'X=BUG; X=OK : ; printf %s "${X}"'
216 1.1 kre }
217 1.1 kre
218 1.1 kre atf_test_case echo
219 1.1 kre echo_head() {
220 1.1 kre atf_set "descr" "Tests the shell builtin version of echo"
221 1.1 kre }
222 1.1 kre echo_body() {
223 1.1 kre have_builtin echo || return 0
224 1.1 kre
225 1.1 kre unset NETBSD_SHELL 2>/dev/null
226 1.1 kre if test -z "$( ${TEST_SH} -c 'printf %s "${NETBSD_SHELL}"')"; then
227 1.1 kre atf_skip \
228 1.1 kre "${TEST_SH%% *} is not the NetBSD shell, this test is for it alone"
229 1.1 kre return 0
230 1.1 kre fi
231 1.1 kre
232 1.1 kre reset echo
233 1.1 kre
234 1.1 kre check 'echo "hello world"' "hello world${nl}" 0
235 1.1 kre check 'echo hello world' "hello world${nl}" 0
236 1.1 kre check 'echo -n "hello world"' "hello world" 0
237 1.1 kre check 'IFS=:; echo hello world' "hello world${nl}" 0
238 1.1 kre check 'IFS=; echo hello world' "hello world${nl}" 0
239 1.1 kre
240 1.1 kre check 'echo -e "hello world"' "hello world${nl}" 0
241 1.1 kre check 'echo -e hello world' "hello world${nl}" 0
242 1.1 kre check 'IFS=:; echo -e hello world' "hello world${nl}" 0
243 1.1 kre
244 1.1 kre # only one of the options is used
245 1.1 kre check 'echo -e -n "hello world"' "-n hello world${nl}" 0
246 1.1 kre check 'echo -n -e "hello world"' "-e hello world" 0
247 1.1 kre # and only when it is alone
248 1.1 kre check 'echo -en "hello world"' "-en hello world${nl}" 0
249 1.1 kre check 'echo -ne "hello world"' "-ne hello world${nl}" 0
250 1.1 kre
251 1.1 kre # echo is specifically required to *not* support --
252 1.1 kre check 'echo -- "hello world"' "-- hello world${nl}" 0
253 1.1 kre
254 1.1 kre # similarly any other unknown option is simply part of the output
255 1.1 kre for OPT in a b c v E N Q V 0 1 2 @ , \? \[ \] \( \; . \* -help -version
256 1.1 kre do
257 1.1 kre check "echo '-${OPT}' foo" "-${OPT} foo${nl}" 0
258 1.1 kre done
259 1.1 kre
260 1.1 kre # Now test the \\ expansions, with and without -e
261 1.1 kre
262 1.1 kre # We rely upon printf %b (tested elsewhere, not only a sh test)
263 1.1 kre # to verify the output when the \\ is supposed to be expanded.
264 1.1 kre
265 1.1 kre for E in '' -e
266 1.1 kre do
267 1.1 kre for B in a b c e f n r t v \\ 04 010 012 0177
268 1.1 kre do
269 1.1 kre S="test string with \\${B} in it"
270 1.1 kre if [ -z "${E}" ]; then
271 1.1 kre R="${S}${nl}"
272 1.1 kre else
273 1.1 kre R="$(printf '%b\nX' "${S}")"
274 1.1 kre R=${R%X}
275 1.1 kre fi
276 1.1 kre check "echo $E '${S}'" "${R}" 0
277 1.1 kre done
278 1.1 kre done
279 1.1 kre
280 1.1 kre results
281 1.1 kre }
282 1.1 kre
283 1.1 kre atf_test_case eval
284 1.1 kre eval_head() {
285 1.1 kre atf_set "descr" "Tests the shell special builtin 'eval'"
286 1.1 kre }
287 1.1 kre eval_body() {
288 1.1 kre have_builtin eval || return 0
289 1.1 kre
290 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c 'eval "exit 0"'
291 1.1 kre atf_check -s exit:1 -e empty -o empty ${TEST_SH} -c 'eval "exit 1"'
292 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c 'eval exit 0'
293 1.1 kre
294 1.1 kre atf_check -s exit:0 -e empty -o inline:abc ${TEST_SH} -c \
295 1.1 kre 'X=a Y=b Z=c; for V in X Y Z; do eval "printf %s \$$V"; done'
296 1.1 kre atf_check -s exit:0 -e empty -o inline:abc ${TEST_SH} -c \
297 1.1 kre 'X=a Y=b Z=c; for V in X Y Z; do eval printf %s \$$V; done'
298 1.1 kre atf_check -s exit:0 -e empty -o inline:XYZ ${TEST_SH} -c \
299 1.1 kre 'for V in X Y Z; do eval "${V}=${V}"; done; printf %s "$X$Y$Z"'
300 1.1 kre }
301 1.1 kre
302 1.1 kre atf_test_case exec
303 1.1 kre exec_head() {
304 1.1 kre atf_set "descr" "Tests the shell special builtin 'exec'"
305 1.1 kre }
306 1.1 kre exec_body() {
307 1.1 kre have_builtin exec || return 0
308 1.1 kre
309 1.1 kre atf_check -s exit:0 -e empty -o inline:OK ${TEST_SH} -c \
310 1.1 kre 'exec printf OK; printf BROKEN; exit 3'
311 1.1 kre atf_check -s exit:3 -e empty -o inline:OKOK ${TEST_SH} -c \
312 1.1 kre '(exec printf OK); printf OK; exit 3'
313 1.1 kre }
314 1.1 kre
315 1.1 kre atf_test_case export
316 1.1 kre export_head() {
317 1.1 kre atf_set "descr" "Tests the shell builtin 'export'"
318 1.1 kre }
319 1.1 kre export_body() {
320 1.1 kre have_builtin export || return 0
321 1.1 kre
322 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c 'export VAR'
323 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c 'export VAR=abc'
324 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c 'export V A R'
325 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
326 1.1 kre 'export V A=1 R=2'
327 1.1 kre
328 1.1 kre atf_require_prog printenv
329 1.1 kre
330 1.1 kre atf_check -s exit:1 -e empty -o empty ${TEST_SH} -c \
331 1.1 kre 'unset VAR || exit 7; export VAR; printenv VAR'
332 1.1 kre atf_check -s exit:0 -e empty -o inline:\\n ${TEST_SH} -c \
333 1.1 kre 'unset VAR || exit 7; export VAR=; printenv VAR'
334 1.1 kre atf_check -s exit:0 -e empty -o inline:\\n ${TEST_SH} -c \
335 1.1 kre 'unset VAR || exit 7; VAR=; export VAR; printenv VAR'
336 1.1 kre atf_check -s exit:0 -e empty -o inline:\\n ${TEST_SH} -c \
337 1.1 kre 'unset VAR || exit 7; export VAR; VAR=; printenv VAR'
338 1.1 kre atf_check -s exit:0 -e empty -o inline:XYZ\\n ${TEST_SH} -c \
339 1.1 kre 'unset VAR || exit 7; export VAR=XYZ; printenv VAR'
340 1.1 kre atf_check -s exit:0 -e empty -o inline:ABC\\n ${TEST_SH} -c \
341 1.1 kre 'VAR=ABC; export VAR; printenv VAR'
342 1.1 kre atf_check -s exit:0 -e empty -o inline:ABC\\n ${TEST_SH} -c \
343 1.1 kre 'unset VAR || exit 7; export VAR; VAR=ABC; printenv VAR'
344 1.1 kre atf_check -s exit:0 -e empty -o inline:ABC\\nXYZ\\n ${TEST_SH} -c \
345 1.1 kre 'VAR=ABC; export VAR; printenv VAR; VAR=XYZ; printenv VAR'
346 1.1 kre atf_check -s exit:0 -e empty -o inline:ABC\\nXYZ\\n ${TEST_SH} -c \
347 1.1 kre 'unset VAR || exit 7; export VAR;
348 1.1 kre VAR=ABC; printenv VAR; VAR=XYZ; printenv VAR'
349 1.1 kre
350 1.3 kre # don't check VAR=value, some shells provide meaningless quoting...
351 1.3 kre atf_check -s exit:0 -e empty -o match:VAR= -o match:foobar \
352 1.3 kre ${TEST_SH} -c \
353 1.3 kre 'VAR=foobar ; export VAR ; export -p'
354 1.3 kre atf_check -s exit:0 -e empty -o match:VAR= -o match:foobar \
355 1.3 kre ${TEST_SH} -c \
356 1.3 kre 'export VAR=foobar ; export -p'
357 1.3 kre atf_check -s exit:0 -e empty -o match:VAR\$ ${TEST_SH} -c \
358 1.3 kre 'unset VAR ; export VAR ; export -p'
359 1.3 kre atf_check -s exit:0 -e empty -o not-match:VAR ${TEST_SH} -c \
360 1.3 kre 'export VAR ; unset VAR ; export -p'
361 1.3 kre atf_check -s exit:0 -e empty -o not-match:VAR -o not-match:foobar \
362 1.3 kre ${TEST_SH} -c \
363 1.3 kre 'VAR=foobar; export VAR ; unset VAR ; export -p'
364 1.3 kre
365 1.3 kre atf_check -s exit:0 -e empty -o match:VAR= -o match:FOUND=foobar \
366 1.3 kre ${TEST_SH} -c \
367 1.3 kre 'export VAR=foobar; V=$(export -p);
368 1.3 kre unset VAR; eval "$V"; export -p;
369 1.3 kre printf %s\\n FOUND=${VAR-unset}'
370 1.3 kre atf_check -s exit:0 -e empty -o match:VAR -o match:FOUND=unset \
371 1.3 kre ${TEST_SH} -c \
372 1.3 kre 'export VAR; V=$(export -p);
373 1.3 kre unset VAR; eval "$V"; export -p;
374 1.3 kre printf %s\\n FOUND=${VAR-unset}'
375 1.3 kre
376 1.1 kre atf_check -s exit:1 -e empty -o inline:ABC\\nXYZ\\n ${TEST_SH} -c \
377 1.1 kre 'VAR=ABC; export VAR; printenv VAR; VAR=XYZ; printenv VAR;
378 1.1 kre unset VAR; printenv VAR; VAR=PQR; printenv VAR'
379 1.1 kre atf_check -s exit:0 -e empty -o inline:ABC\\nXYZ\\nVAR=unset\\nMNO\\n \
380 1.1 kre ${TEST_SH} -c \
381 1.1 kre 'VAR=ABC; export VAR; printenv VAR; VAR=XYZ; printenv VAR;
382 1.1 kre unset VAR; printf %s\\n "VAR=${VAR-unset}"; printenv VAR;
383 1.1 kre VAR=PQR; printenv VAR; VAR=MNO; export VAR; printenv VAR'
384 1.1 kre }
385 1.1 kre
386 1.1 kre atf_test_case export_nbsd
387 1.1 kre export_nbsd_head() {
388 1.1 kre atf_set "descr" "Tests NetBSD extensions to the shell builtin 'export'"
389 1.1 kre }
390 1.1 kre export_nbsd_body() {
391 1.1 kre have_builtin "export" "" "" "-n foo" ' -n' || return 0
392 1.1 kre
393 1.1 kre atf_require_prog printenv
394 1.1 kre
395 1.1 kre atf_check -s exit:1 -e empty -o inline:ABC\\nXYZ\\n ${TEST_SH} -c \
396 1.1 kre 'VAR=ABC; export VAR; printenv VAR; VAR=XYZ; printenv VAR;
397 1.1 kre export -n VAR; printenv VAR; VAR=PQR; printenv VAR'
398 1.1 kre
399 1.1 kre atf_check -s exit:0 -e empty -o inline:ABC\\nXYZ\\nVAR=XYZ\\nMNO\\n \
400 1.1 kre ${TEST_SH} -c \
401 1.1 kre 'VAR=ABC; export VAR; printenv VAR; VAR=XYZ; printenv VAR;
402 1.1 kre export -n VAR; printf %s\\n "VAR=${VAR-unset}"; printenv VAR;
403 1.1 kre VAR=PQR; printenv VAR; VAR=MNO; export VAR; printenv VAR'
404 1.1 kre
405 1.1 kre have_builtin "export" "" "" -x ' -x' || return 0
406 1.1 kre
407 1.1 kre atf_check -s exit:1 -e empty -o empty ${TEST_SH} -c \
408 1.1 kre 'export VAR=exported; export -x VAR; printenv VAR'
409 1.1 kre atf_check -s exit:1 -e empty -o empty ${TEST_SH} -c \
410 1.1 kre 'export VAR=exported; export -x VAR; VAR=local; printenv VAR'
411 1.1 kre atf_check -s exit:0 -e empty -o inline:once\\nx\\n ${TEST_SH} -c \
412 1.1 kre 'export VAR=exported
413 1.1 kre export -x VAR
414 1.1 kre VAR=once printenv VAR
415 1.1 kre printenv VAR || printf %s\\n x'
416 1.1 kre
417 1.1 kre atf_check -s not-exit:0 -e not-empty -o empty ${TEST_SH} -c \
418 1.1 kre 'export VAR=exported; export -x VAR; export VAR=FOO'
419 1.4 kre
420 1.4 kre have_builtin export '' 'export VAR;' '-q VAR' ' -q' || return 0
421 1.4 kre
422 1.4 kre atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
423 1.4 kre 'unset VAR; VAR=set; export -q VAR'
424 1.4 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
425 1.4 kre 'export VAR=set; export -q VAR'
426 1.4 kre atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
427 1.4 kre 'VAR=set; RW=set; export -q VAR RW'
428 1.4 kre atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
429 1.4 kre 'VAR=set; export RO=set; export -q VAR RO'
430 1.4 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
431 1.4 kre 'export VAR=set RO=set; export -q VAR RO'
432 1.4 kre
433 1.4 kre atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
434 1.4 kre 'unset VAR; export -q VAR'
435 1.4 kre # next one is the same as the have_builtin test, so "cannot" fail...
436 1.4 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
437 1.4 kre 'unset VAR; export VAR; export -q VAR'
438 1.4 kre
439 1.4 kre # if we have -q we should also have -p var...
440 1.4 kre # What's more, we are testing NetBSD sh, so we know output format.
441 1.4 kre
442 1.4 kre atf_check -s exit:0 -e empty -o match:VAR=foobar \
443 1.4 kre ${TEST_SH} -c \
444 1.4 kre 'VAR=foobar ; export VAR ; export -p VAR'
445 1.4 kre atf_check -s exit:0 -e empty -o inline:1 \
446 1.4 kre ${TEST_SH} -c \
447 1.4 kre 'VAR=foobar ; export VAR ;
448 1.4 kre printf %d $(export -p VAR | wc -l)'
449 1.4 kre atf_check -s exit:0 -e empty \
450 1.4 kre -o inline:'export VAR=foobar\nexport OTHER\n' \
451 1.4 kre ${TEST_SH} -c \
452 1.4 kre 'VAR=foobar; export VAR OTHER; export -p VAR OTHER'
453 1.4 kre atf_check -s exit:0 -e empty \
454 1.4 kre -o inline:'export A=aaa\nexport B\nexport D='"''"'\n' \
455 1.4 kre ${TEST_SH} -c \
456 1.4 kre 'A=aaa D= C=foo; unset B; export A B D;
457 1.4 kre export -p A B C D'
458 1.1 kre }
459 1.1 kre
460 1.1 kre atf_test_case getopts
461 1.1 kre getopts_head() {
462 1.1 kre atf_set "descr" "Tests the shell builtin 'getopts'"
463 1.1 kre }
464 1.1 kre getopts_body() {
465 1.1 kre have_builtin getopts "" "f() {" "a x; }; f -a" || return 0
466 1.1 kre }
467 1.1 kre
468 1.1 kre atf_test_case jobs
469 1.1 kre jobs_head() {
470 1.1 kre atf_set "descr" "Tests the shell builting 'jobs' command"
471 1.1 kre }
472 1.1 kre jobs_body() {
473 1.1 kre have_builtin jobs || return 0
474 1.1 kre
475 1.1 kre atf_require_prog sleep
476 1.1 kre
477 1.1 kre # note that POSIX requires that we reference $! otherwise
478 1.1 kre # the shell is not required to remember the process...
479 1.1 kre
480 1.1 kre atf_check -s exit:0 -e empty -o match:sleep -o match:Running \
481 1.1 kre ${TEST_SH} -c 'sleep 1 & P=$!; jobs; wait'
482 1.1 kre atf_check -s exit:0 -e empty -o match:sleep -o match:Done \
483 1.1 kre ${TEST_SH} -c 'sleep 1 & P=$!; sleep 2; jobs; wait'
484 1.1 kre }
485 1.1 kre
486 1.1 kre atf_test_case read
487 1.1 kre read_head() {
488 1.1 kre atf_set "descr" "Tests the shell builtin read command"
489 1.1 kre }
490 1.1 kre read_body() {
491 1.1 kre have_builtin read "" "echo x|" "var" || return 0
492 1.1 kre }
493 1.1 kre
494 1.1 kre atf_test_case readonly
495 1.1 kre readonly_head() {
496 1.1 kre atf_set "descr" "Tests the shell builtin 'readonly'"
497 1.1 kre }
498 1.1 kre readonly_body() {
499 1.1 kre have_builtin readonly || return 0
500 1.1 kre
501 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c 'readonly VAR'
502 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c 'readonly VAR=abc'
503 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c 'readonly V A R'
504 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c 'readonly V A=1 R=2'
505 1.1 kre
506 1.1 kre atf_check -s exit:0 -e empty -o inline:unset ${TEST_SH} -c \
507 1.1 kre 'unset VAR; readonly VAR; printf %s ${VAR-unset}'
508 1.1 kre atf_check -s exit:0 -e empty -o inline:set ${TEST_SH} -c \
509 1.1 kre 'unset VAR; readonly VAR=set; printf %s ${VAR-unset}'
510 1.3 kre atf_check -s exit:0 -e empty -o inline:set ${TEST_SH} -c \
511 1.3 kre 'VAR=initial; readonly VAR=set; printf %s ${VAR-unset}'
512 1.1 kre atf_check -s not-exit:0 -e not-empty -o empty ${TEST_SH} -c \
513 1.1 kre 'readonly VAR=initial; VAR=new; printf %s "${VAR}"'
514 1.1 kre
515 1.3 kre # don't check VAR=value, some shells provide meaningless quoting...
516 1.3 kre atf_check -s exit:0 -e empty -o match:VAR= -o match:foobar \
517 1.3 kre ${TEST_SH} -c \
518 1.3 kre 'VAR=foobar ; readonly VAR ; readonly -p'
519 1.3 kre atf_check -s exit:0 -e empty -o match:VAR= -o match:foobar \
520 1.3 kre ${TEST_SH} -c \
521 1.3 kre 'readonly VAR=foobar ; readonly -p'
522 1.3 kre atf_check -s exit:0 -e empty -o match:VAR= -o match:foobar \
523 1.3 kre -o not-match:badvalue ${TEST_SH} -c \
524 1.3 kre 'VAR=badvalue; readonly VAR=foobar ; readonly -p'
525 1.3 kre atf_check -s exit:0 -e empty -o match:VAR\$ ${TEST_SH} -c \
526 1.3 kre 'unset VAR ; readonly VAR ; readonly -p'
527 1.3 kre
528 1.3 kre # checking that readonly -p works (to reset stuff) is a pain...
529 1.3 kre # particularly since not all shells say "readonly..." by default
530 1.3 kre atf_check -s exit:0 -e empty -o match:MYVAR= -o match:FOUND=foobar \
531 1.3 kre ${TEST_SH} -c \
532 1.3 kre 'V=$(readonly MYVAR=foobar; readonly -p | grep " MYVAR")
533 1.3 kre unset MYVAR; eval "$V"; readonly -p;
534 1.3 kre printf %s\\n FOUND=${MYVAR-unset}'
535 1.3 kre atf_check -s exit:0 -e empty -o match:MYVAR\$ -o match:FOUND=unset \
536 1.3 kre ${TEST_SH} -c \
537 1.3 kre 'V=$(readonly MYVAR; readonly -p | grep " MYVAR")
538 1.3 kre unset MYVAR; eval "$V"; readonly -p;
539 1.3 kre printf %s\\n "FOUND=${MYVAR-unset}"'
540 1.3 kre atf_check -s exit:0 -e empty -o match:MYVAR= -o match:FOUND=empty \
541 1.3 kre ${TEST_SH} -c \
542 1.3 kre 'V=$(readonly MYVAR=; readonly -p | grep " MYVAR")
543 1.3 kre unset VAR; eval "$V"; readonly -p;
544 1.3 kre printf %s\\n "FOUND=${MYVAR-unset&}${MYVAR:-empty}"'
545 1.3 kre
546 1.1 kre # don't test stderr, some shells inist on generating a message for an
547 1.1 kre # unset of a readonly var (rather than simply having unset make $?=1)
548 1.1 kre
549 1.1 kre atf_check -s not-exit:0 -e empty -o empty ${TEST_SH} -c \
550 1.1 kre 'unset VAR; readonly VAR=set;
551 1.1 kre unset VAR 2>/dev/null && printf %s ${VAR:-XX}'
552 1.1 kre atf_check -s not-exit:0 -e ignore -o empty ${TEST_SH} -c \
553 1.1 kre 'unset VAR; readonly VAR=set; unset VAR && printf %s ${VAR:-XX}'
554 1.1 kre atf_check -s exit:0 -e ignore -o inline:set ${TEST_SH} -c \
555 1.1 kre 'unset VAR; readonly VAR=set; unset VAR; printf %s ${VAR-unset}'
556 1.1 kre }
557 1.1 kre
558 1.4 kre atf_test_case readonly_nbsd
559 1.4 kre readonly_nbsd_head() {
560 1.4 kre atf_set "descr" "Tests NetBSD extensions to 'readonly'"
561 1.4 kre }
562 1.4 kre readonly_nbsd_body() {
563 1.4 kre have_builtin readonly '' 'readonly VAR;' '-q VAR' ' -q' || return 0
564 1.4 kre
565 1.4 kre atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
566 1.4 kre 'VAR=set; readonly -q VAR'
567 1.4 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
568 1.4 kre 'readonly VAR=set; readonly -q VAR'
569 1.4 kre atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
570 1.4 kre 'VAR=set; RW=set; readonly -q VAR RW'
571 1.4 kre atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
572 1.4 kre 'VAR=set; readonly RO=set; readonly -q VAR RO'
573 1.4 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
574 1.4 kre 'readonly VAR=set RO=set; readonly -q VAR RO'
575 1.4 kre
576 1.4 kre atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
577 1.4 kre 'unset VAR; readonly -q VAR'
578 1.4 kre # next one is the same as the have_builtin test, so "cannot" fail...
579 1.4 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
580 1.4 kre 'unset VAR; readonly VAR; readonly -q VAR'
581 1.4 kre
582 1.4 kre # if we have -q we should also have -p var...
583 1.4 kre # What's more, we are testing NetBSD sh, so we know output format.
584 1.4 kre
585 1.4 kre atf_check -s exit:0 -e empty -o match:VAR=foobar \
586 1.4 kre ${TEST_SH} -c \
587 1.4 kre 'VAR=foobar ; readonly VAR ; readonly -p VAR'
588 1.4 kre atf_check -s exit:0 -e empty -o inline:1 \
589 1.4 kre ${TEST_SH} -c \
590 1.4 kre 'VAR=foobar ; readonly VAR ;
591 1.4 kre printf %d $(readonly -p VAR | wc -l)'
592 1.4 kre atf_check -s exit:0 -e empty \
593 1.4 kre -o inline:'readonly VAR=foobar\nreadonly OTHER\n' \
594 1.4 kre ${TEST_SH} -c \
595 1.4 kre 'VAR=foobar; readonly VAR OTHER; readonly -p VAR OTHER'
596 1.4 kre atf_check -s exit:0 -e empty \
597 1.4 kre -o inline:'readonly A=aaa\nreadonly B\nreadonly D='"''"'\n' \
598 1.4 kre ${TEST_SH} -c \
599 1.4 kre 'A=aaa D= C=foo; unset B; readonly A B D;
600 1.4 kre readonly -p A B C D'
601 1.4 kre }
602 1.4 kre
603 1.1 kre atf_test_case cd_pwd
604 1.1 kre cd_pwd_head() {
605 1.1 kre atf_set "descr" "Tests the shell builtins 'cd' & 'pwd'"
606 1.1 kre }
607 1.1 kre cd_pwd_body() {
608 1.1 kre have_builtin cd "" "HOME=/;" || return 0
609 1.1 kre have_builtin pwd || return 0
610 1.1 kre }
611 1.1 kre
612 1.1 kre atf_test_case true_false
613 1.1 kre true_false_head() {
614 1.1 kre atf_set "descr" "Tests the 'true' and 'false' shell builtin commands"
615 1.1 kre }
616 1.1 kre true_false_body() {
617 1.1 kre have_builtin true || return 0
618 1.1 kre
619 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c true
620 1.1 kre
621 1.1 kre # true is not a special builtin, so errors do not cause exit
622 1.1 kre # but we should still get an error from the broken redirect
623 1.1 kre # and the exit status of true should be false...
624 1.1 kre
625 1.1 kre atf_check -s exit:0 -e not-empty -o inline:OK ${TEST_SH} -c \
626 1.1 kre "true >/foo/bar && printf %s NOT-; printf %s OK"
627 1.1 kre
628 1.1 kre # and var-assigns should not affect the current sh env
629 1.1 kre
630 1.1 kre atf_check -s exit:0 -e empty -o inline:IS-OK ${TEST_SH} -c \
631 1.1 kre 'X=OK; X=BROKEN true && printf %s IS-; printf %s "${X}"'
632 1.1 kre
633 1.1 kre have_builtin false "" ! || return 0
634 1.1 kre
635 1.1 kre atf_check -s exit:1 -e empty -o empty ${TEST_SH} -c false
636 1.1 kre }
637 1.1 kre
638 1.1 kre atf_test_case type
639 1.1 kre type_head() {
640 1.1 kre atf_set "descr" "Tests the sh builtin 'type' command"
641 1.1 kre }
642 1.1 kre type_body() {
643 1.1 kre have_builtin type "" "" type || return 0
644 1.1 kre }
645 1.1 kre
646 1.1 kre # This currently has its own t_ulimit - either merge that here,
647 1.1 kre # or delete this one and keep that... ulimit -n is also tested in
648 1.1 kre # the t_redir tests, as that affects the shell's use of file descriptors
649 1.1 kre atf_test_case ulimit
650 1.1 kre ulimit_head() {
651 1.1 kre atf_set "descr" "Tests the sh builtin 'ulimit'"
652 1.1 kre }
653 1.1 kre ulimit_body() {
654 1.1 kre have_builtin ulimit || return 0
655 1.1 kre }
656 1.1 kre
657 1.1 kre atf_test_case umask
658 1.1 kre umask_head() {
659 1.1 kre atf_set "descr" "Tests the sh builtin 'umask'"
660 1.1 kre }
661 1.1 kre umask_body() {
662 1.1 kre have_builtin umask || return 0
663 1.1 kre
664 1.1 kre atf_require_prog touch
665 1.1 kre atf_require_prog stat
666 1.1 kre atf_require_prog rm
667 1.1 kre atf_require_prog chmod
668 1.1 kre
669 1.1 kre reset umask
670 1.1 kre
671 1.1 kre # 8 octal digits
672 1.1 kre for M in 0 1 2 3 4 5 6 7
673 1.1 kre do
674 1.1 kre # Test numbers start: 1 25 49 73 97 121 145 169
675 1.1 kre
676 1.1 kre # 8 combinations of each to test (64 inner loops)
677 1.1 kre # 3 tests in each loop, hence 192 subtests in all
678 1.1 kre
679 1.1 kre # Test numbers from loop above, plus (below) and the next 2
680 1.1 kre #+ 1 4 7 10 13
681 1.1 kre for T in "0${M}" "00${M}" "0${M}0" "0${M}00" "0${M}${M}" \
682 1.1 kre "0${M}${M}0" "0${M}${M}${M}" "0${M}0${M}"
683 1.1 kre #+ 16 19 22
684 1.1 kre do
685 1.1 kre # umask turns bits off, calculate which bits will be on...
686 1.1 kre
687 1.1 kre D=$(( 0777 & ~ T )) # for directories
688 1.1 kre F=$(( $D & ~ 0111 )) # and files with no 'x' bits
689 1.1 kre
690 1.1 kre # Note: $(( )) always produces decimal, so we test that format
691 1.1 kre # (see '%d' in printf of stat result)
692 1.1 kre
693 1.1 kre # need chmod or we might have no perm to rmdir TD
694 1.1 kre { chmod +rwx TF TFT TD; rm -fr TF TFT TD; } 2>/dev/null || :
695 1.1 kre
696 1.1 kre # check that the umask applies to files created by the shell
697 1.1 kre check \
698 1.1 kre "umask $T; > TF; printf %d \$(stat -nf %#Lp TF)" \
699 1.1 kre "$F" 0 "$F is $(printf %#o $F)" # 1 4 7 10 ...
700 1.1 kre
701 1.1 kre # and to files created by commands that the shell runs
702 1.1 kre check \
703 1.1 kre "umask $T; touch TFT; printf %d \$(stat -nf %#Lp TFT)" \
704 1.1 kre "$F" 0 "$F is $(printf %#o $F)" # 2 5 8 11 ...
705 1.1 kre
706 1.1 kre # and to directories created b ... (directories keep 'x')
707 1.1 kre check \
708 1.1 kre "umask $T; mkdir TD; printf %d \$(stat -nf %#Lp TD)" \
709 1.1 kre "$D" 0 "$D is $(printf %#o $D)" # 3 6 9 12 ...
710 1.1 kre done
711 1.1 kre done
712 1.1 kre
713 1.1 kre # Now add a few more tests with less regular u/g/m masks
714 1.1 kre # In here, include tests where umask value has no leading '0'
715 1.1 kre
716 1.1 kre # 10 loops, the same 3 tests in each loop, 30 more subtests
717 1.1 kre # from 193 .. 222
718 1.1 kre
719 1.1 kre # 193 196 199 202 205 208 211 214 217 220
720 1.1 kre for T in 013 047 722 0772 027 123 421 0124 0513 067
721 1.1 kre do
722 1.1 kre D=$(( 0777 & ~ 0$T ))
723 1.1 kre F=$(( $D & ~ 0111 ))
724 1.1 kre
725 1.1 kre { chmod +rwx TF TFT TD; rm -fr TF TFT TD; } 2>/dev/null || :
726 1.1 kre
727 1.1 kre check \
728 1.1 kre "umask $T; > TF; printf %d \$(stat -nf %#Lp TF)" \
729 1.1 kre "$F" 0 "$F is $(printf %#o $F)" # +0
730 1.1 kre
731 1.1 kre check \
732 1.1 kre "umask $T; touch TFT; printf %d \$(stat -nf %#Lp TFT)" \
733 1.1 kre "$F" 0 "$F is $(printf %#o $F)" # +1
734 1.1 kre
735 1.1 kre check \
736 1.1 kre "umask $T; mkdir TD; printf %d \$(stat -nf %#Lp TD)" \
737 1.1 kre "$D" 0 "$D is $(printf %#o $D)" # +2
738 1.1 kre done
739 1.1 kre
740 1.1 kre results
741 1.1 kre }
742 1.1 kre
743 1.1 kre atf_test_case unset
744 1.1 kre unset_head() {
745 1.1 kre atf_set "descr" "Tests the sh builtin 'unset'"
746 1.1 kre }
747 1.1 kre unset_body() {
748 1.1 kre have_builtin unset || return 0
749 1.1 kre }
750 1.1 kre
751 1.1 kre atf_test_case hash
752 1.1 kre hash_head() {
753 1.1 kre atf_set "descr" "Tests the sh builtin 'hash' (ash extension)"
754 1.1 kre }
755 1.1 kre hash_body() {
756 1.1 kre have_builtin hash || return 0
757 1.1 kre }
758 1.1 kre
759 1.1 kre atf_test_case jobid
760 1.1 kre jobid_head() {
761 1.1 kre atf_set "descr" "Tests sh builtin 'jobid' (NetBSD extension)"
762 1.1 kre }
763 1.1 kre jobid_body() {
764 1.1 kre
765 1.1 kre # have_builtin jobid || return 0 No simple jobid command test
766 1.1 kre $TEST_SH -c '(exit 0)& jobid $!' >/dev/null 2>&1 || {
767 1.1 kre atf_skip "${TEST_SH} has no 'jobid' built-in"
768 1.1 kre return 0
769 1.1 kre }
770 1.1 kre }
771 1.1 kre
772 1.1 kre atf_test_case let
773 1.1 kre let_head() {
774 1.1 kre atf_set "descr" "Tests the sh builtin 'let' (common extension from ksh)"
775 1.1 kre }
776 1.1 kre let_body() {
777 1.1 kre have_builtin let "" "" 1 || return 0
778 1.1 kre }
779 1.1 kre
780 1.1 kre atf_test_case local
781 1.1 kre local_head() {
782 1.1 kre atf_set "descr" "Tests the shell builtin 'local' (common extension)"
783 1.1 kre }
784 1.1 kre local_body() {
785 1.1 kre have_builtin local "" "f () {" "X; }; f" || return 0
786 1.1 kre }
787 1.1 kre
788 1.1 kre atf_test_case setvar
789 1.1 kre setvar_head() {
790 1.1 kre atf_set "descr" "Tests the shell builtin 'setvar' (BSD extension)"
791 1.1 kre }
792 1.1 kre setvar_body() {
793 1.1 kre have_builtin setvar || return 0
794 1.1 kre
795 1.1 kre atf_check -s exit:0 -e empty -o inline:foo ${TEST_SH} -c \
796 1.1 kre 'unset PQ && setvar PQ foo; printf %s "${PQ-not set}"'
797 1.1 kre atf_check -s exit:0 -e empty -o inline:abcd ${TEST_SH} -c \
798 1.1 kre 'for x in a b c d; do setvar "$x" "$x"; done;
799 1.1 kre printf %s "$a$b$c$d"'
800 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
801 1.1 kre 'a=1; b=2; c=3; d=4
802 1.1 kre for x in a b c d; do setvar "$x" ""; done;
803 1.1 kre printf %s "$a$b$c$d"'
804 1.1 kre }
805 1.1 kre
806 1.1 kre atf_test_case fdflags
807 1.1 kre fdflags_head() {
808 1.1 kre atf_set "descr" \
809 1.1 kre "Tests basic operation of sh builtin 'fdflags' (NetBSD extension)"
810 1.1 kre }
811 1.1 kre fdflags_body() {
812 1.1 kre have_builtin fdflags || return 0
813 1.1 kre }
814 1.1 kre
815 1.1 kre atf_test_case fdflags__s
816 1.1 kre fdflags__s_head() {
817 1.1 kre atf_set "descr" "Checks setting/clearing flags on file descriptors"
818 1.1 kre }
819 1.1 kre fdflags__s_body() {
820 1.1 kre have_builtin fdflags || return 0
821 1.1 kre }
822 1.1 kre
823 1.1 kre atf_test_case fdflags__v
824 1.1 kre fdflags__v_head() {
825 1.1 kre atf_set "descr" "Checks verbose operation of fdflags"
826 1.1 kre }
827 1.1 kre fdflags__v_body() {
828 1.1 kre have_builtin fdflags || return 0
829 1.1 kre }
830 1.1 kre
831 1.1 kre atf_test_case fdflags__v_s
832 1.1 kre fdflags__v_s_head() {
833 1.1 kre atf_set "descr" "tests verbose operation of fdflags -s"
834 1.1 kre }
835 1.1 kre fdflags__v_s_body() {
836 1.1 kre have_builtin fdflags || return 0
837 1.1 kre }
838 1.1 kre
839 1.1 kre atf_test_case fdflags_multiple_fd
840 1.1 kre fdflags_multiple_fd_head() {
841 1.1 kre atf_set "descr" "Checks operation of fdflags with more than one fd"
842 1.1 kre }
843 1.1 kre fdflags_multiple_fd_body() {
844 1.1 kre have_builtin fdflags || return 0
845 1.1 kre }
846 1.1 kre
847 1.1 kre atf_test_case fdflags_one_flag_at_a_time
848 1.1 kre fdflags_one_flag_at_a_time_head() {
849 1.1 kre atf_set "descr" "Tests all possible fdflags flags, and combinations"
850 1.1 kre }
851 1.1 kre fdflags_one_flag_at_a_time_body() {
852 1.1 kre have_builtin fdflags || return 0
853 1.1 kre }
854 1.1 kre
855 1.1 kre atf_test_case fdflags_save_restore
856 1.1 kre fdflags_save_restore_head() {
857 1.1 kre atf_set "descr" 'Verify that fd flags can be saved and restored'
858 1.1 kre }
859 1.1 kre fdflags_save_restore_body() {
860 1.1 kre have_builtin fdflags || return 0
861 1.1 kre }
862 1.1 kre
863 1.1 kre atf_test_case fdflags_names_abbreviated
864 1.1 kre fdflags_names_abbreviated_head() {
865 1.1 kre atf_set "descr" 'Tests using abbreviated names for fdflags'
866 1.1 kre }
867 1.1 kre fdflags_names_abbreviated_body() {
868 1.1 kre have_builtin fdflags || return 0
869 1.1 kre }
870 1.1 kre
871 1.1 kre atf_test_case fdflags_xx_errors
872 1.1 kre fdflags_xx_errors_head() {
873 1.1 kre atf_set "descr" 'Check various erroneous fdflags uses'
874 1.1 kre }
875 1.1 kre fdflags_xx_errors_body() {
876 1.1 kre have_builtin fdflags || return 0
877 1.1 kre }
878 1.1 kre
879 1.1 kre
880 1.1 kre atf_init_test_cases() {
881 1.1 kre
882 1.1 kre # "standard" builtin commands in sh
883 1.1 kre
884 1.1 kre # no tests of the "very special" (almost syntax) builtins
885 1.1 kre # (break/continue/return) - they're tested enough elsewhere
886 1.1 kre
887 1.1 kre atf_add_test_case cd_pwd
888 1.1 kre atf_add_test_case colon
889 1.1 kre atf_add_test_case echo
890 1.1 kre atf_add_test_case eval
891 1.1 kre atf_add_test_case exec
892 1.1 kre atf_add_test_case export
893 1.1 kre atf_add_test_case getopts
894 1.1 kre atf_add_test_case jobs
895 1.1 kre atf_add_test_case read
896 1.1 kre atf_add_test_case readonly
897 1.1 kre atf_add_test_case true_false
898 1.1 kre atf_add_test_case type
899 1.1 kre atf_add_test_case ulimit
900 1.1 kre atf_add_test_case umask
901 1.1 kre atf_add_test_case unset
902 1.1 kre
903 1.1 kre # exit/wait/set/shift/trap/alias/unalias/. should have their own tests
904 1.1 kre # fc/times/fg/bg/% are too messy to contemplate for now
905 1.1 kre # command ?? (probably should have some tests)
906 1.1 kre
907 1.1 kre # Note that builtin versions of, printf, kill, ... are tested separately
908 1.1 kre # (these are all "optional" builtins)
909 1.1 kre # (echo is tested here because NetBSD sh builtin echo and /bin/echo
910 1.1 kre # are different)
911 1.1 kre
912 1.1 kre atf_add_test_case export_nbsd
913 1.1 kre atf_add_test_case hash
914 1.1 kre atf_add_test_case jobid
915 1.1 kre atf_add_test_case let
916 1.1 kre atf_add_test_case local
917 1.4 kre atf_add_test_case readonly_nbsd
918 1.1 kre atf_add_test_case setvar
919 1.1 kre # inputrc should probably be tested in libedit tests (somehow)
920 1.1 kre
921 1.1 kre # fdflags has a bunch of test cases
922 1.1 kre
923 1.1 kre # Always run one test, so we get at least "skipped" result
924 1.1 kre atf_add_test_case fdflags
925 1.1 kre
926 1.1 kre # but no need to say "skipped" lots more times...
927 1.1 kre have_builtin fdflags available && {
928 1.1 kre atf_add_test_case fdflags__s
929 1.1 kre atf_add_test_case fdflags__v
930 1.1 kre atf_add_test_case fdflags__v_s
931 1.1 kre atf_add_test_case fdflags_multiple_fd
932 1.1 kre atf_add_test_case fdflags_names_abbreviated
933 1.1 kre atf_add_test_case fdflags_one_flag_at_a_time
934 1.1 kre atf_add_test_case fdflags_save_restore
935 1.1 kre atf_add_test_case fdflags_xx_errors
936 1.1 kre }
937 1.1 kre return 0
938 1.1 kre }
939