t_command.sh revision 1.1.4.2 1 1.1.4.2 christos # $NetBSD: t_command.sh,v 1.1.4.2 2019/06/10 22:10:12 christos Exp $
2 1.1.4.2 christos #
3 1.1.4.2 christos # Copyright (c) 2018 The NetBSD Foundation, Inc.
4 1.1.4.2 christos # All rights reserved.
5 1.1.4.2 christos #
6 1.1.4.2 christos # Redistribution and use in source and binary forms, with or without
7 1.1.4.2 christos # modification, are permitted provided that the following conditions
8 1.1.4.2 christos # are met:
9 1.1.4.2 christos # 1. Redistributions of source code must retain the above copyright
10 1.1.4.2 christos # notice, this list of conditions and the following disclaimer.
11 1.1.4.2 christos # 2. Redistributions in binary form must reproduce the above copyright
12 1.1.4.2 christos # notice, this list of conditions and the following disclaimer in the
13 1.1.4.2 christos # documentation and/or other materials provided with the distribution.
14 1.1.4.2 christos #
15 1.1.4.2 christos # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1.4.2 christos # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1.4.2 christos # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1.4.2 christos # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1.4.2 christos # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1.4.2 christos # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1.4.2 christos # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1.4.2 christos # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1.4.2 christos # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1.4.2 christos # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1.4.2 christos # POSSIBILITY OF SUCH DAMAGE.
26 1.1.4.2 christos #
27 1.1.4.2 christos
28 1.1.4.2 christos # The printf command to test (if not a full path, $PATH will be examined)
29 1.1.4.2 christos # Do not use relative (./ or ../) paths when running under ATF.
30 1.1.4.2 christos : ${TEST_PRINTF:=/usr/bin/printf}
31 1.1.4.2 christos
32 1.1.4.2 christos # This tests an external (filesystem) printf command
33 1.1.4.2 christos
34 1.1.4.2 christos # For the actual code/tests see printf.sh
35 1.1.4.2 christos # (shared with tests for the shell builtin printf
36 1.1.4.2 christos
37 1.1.4.2 christos # These tests are designed to be able to be run by ATF, or standalone
38 1.1.4.2 christos #
39 1.1.4.2 christos # That is, either
40 1.1.4.2 christos # atf_run t_command | atf-report (or whatever is needed)
41 1.1.4.2 christos # or
42 1.1.4.2 christos # sh t_command [sub_test]... ( default is to run all sub_tests )
43 1.1.4.2 christos #
44 1.1.4.2 christos # nb: for standalone runs, do not attempt ./t_builtin as the #! line
45 1.1.4.2 christos # added will force ATF which will complain about the incorrect method
46 1.1.4.2 christos # of running the test. Instead use some Bourne shell compatible shell
47 1.1.4.2 christos # (any will do, caveat any bugs it might have), and run the script explicitly.
48 1.1.4.2 christos
49 1.1.4.2 christos do_printf()
50 1.1.4.2 christos {
51 1.1.4.2 christos $Running_under_ATF && atf_require_prog "${PRINTF%% *}"
52 1.1.4.2 christos
53 1.1.4.2 christos unset LANG LC_ALL LC_NUMERIC LC_CTYPE LC_MESSAGES
54 1.1.4.2 christos
55 1.1.4.2 christos ${PRINTF} "$@"
56 1.1.4.2 christos }
57 1.1.4.2 christos
58 1.1.4.2 christos No_command()
59 1.1.4.2 christos {
60 1.1.4.2 christos setmsg No_command
61 1.1.4.2 christos
62 1.1.4.2 christos case "${TEST_PRINTF%% *}" in
63 1.1.4.2 christos ( '' )
64 1.1.4.2 christos msg='Configuration error: check $TEST_PRINTF'
65 1.1.4.2 christos ;;
66 1.1.4.2 christos ( /* | ./* | ../* )
67 1.1.4.2 christos msg="Cannot find/execute ${TEST_PRINTF%% *}"
68 1.1.4.2 christos ;;
69 1.1.4.2 christos ( * )
70 1.1.4.2 christos msg="No '${TEST_PRINTF%% *}' found in "'$PATH'
71 1.1.4.2 christos ;;
72 1.1.4.2 christos esac
73 1.1.4.2 christos atf_skip "${msg}"
74 1.1.4.2 christos
75 1.1.4.2 christos return $RVAL
76 1.1.4.2 christos }
77 1.1.4.2 christos
78 1.1.4.2 christos # See if we have a "printf" command in $PATH to test - pick the first
79 1.1.4.2 christos
80 1.1.4.2 christos setup()
81 1.1.4.2 christos {
82 1.1.4.2 christos saveIFS="${IFS-UnSet}"
83 1.1.4.2 christos saveOPTS="$(set +o)"
84 1.1.4.2 christos
85 1.1.4.2 christos unset PRINTF
86 1.1.4.2 christos
87 1.1.4.2 christos case "${TEST_PRINTF%% *}" in
88 1.1.4.2 christos ( /* ) PRINTF="${TEST_PRINTF}" ;;
89 1.1.4.2 christos ( ./* | ../* ) PRINTF="${PWD}/${TEST_PRINTF}" ;;
90 1.1.4.2 christos (*)
91 1.1.4.2 christos set -f
92 1.1.4.2 christos IFS=:
93 1.1.4.2 christos for P in $PATH
94 1.1.4.2 christos do
95 1.1.4.2 christos case "$P" in
96 1.1.4.2 christos ('' | . ) D="${PWD}";;
97 1.1.4.2 christos ( /* ) D="${P}" ;;
98 1.1.4.2 christos ( * ) D="${PWD}/${P}";;
99 1.1.4.2 christos esac
100 1.1.4.2 christos
101 1.1.4.2 christos test -x "${D}/${TEST_PRINTF%% *}" || continue
102 1.1.4.2 christos
103 1.1.4.2 christos PRINTF="${D}/${TEST_PRINTF}"
104 1.1.4.2 christos break
105 1.1.4.2 christos done
106 1.1.4.2 christos unset IFS
107 1.1.4.2 christos eval "${saveOPTS}"
108 1.1.4.2 christos
109 1.1.4.2 christos case "${saveIFS}" in
110 1.1.4.2 christos (UnSet) unset IFS;;
111 1.1.4.2 christos (*) IFS="${saveIFS}";;
112 1.1.4.2 christos esac
113 1.1.4.2 christos ;;
114 1.1.4.2 christos esac
115 1.1.4.2 christos
116 1.1.4.2 christos test -x "${PRINTF%% *}" || PRINTF=
117 1.1.4.2 christos
118 1.1.4.2 christos case "${PRINTF}" in
119 1.1.4.2 christos
120 1.1.4.2 christos ('') Tests=
121 1.1.4.2 christos define No_command 'Dummy test to skip no printf command'
122 1.1.4.2 christos return 1
123 1.1.4.2 christos ;;
124 1.1.4.2 christos
125 1.1.4.2 christos ( * )
126 1.1.4.2 christos # nothing here, it all happens below.
127 1.1.4.2 christos ;;
128 1.1.4.2 christos
129 1.1.4.2 christos esac
130 1.1.4.2 christos
131 1.1.4.2 christos return 0
132 1.1.4.2 christos }
133 1.1.4.2 christos
134 1.1.4.2 christos setmsg()
135 1.1.4.2 christos {
136 1.1.4.2 christos MSG="${PRINTF}"
137 1.1.4.2 christos CurrentTest="$1"
138 1.1.4.2 christos RVAL=0
139 1.1.4.2 christos }
140 1.1.4.2 christos
141 1.1.4.2 christos BUILTIN_TEST=false
142 1.1.4.2 christos
143 1.1.4.2 christos # All the code to actually run the test comes from printf.sh ...
144 1.1.4.2 christos
145