Sync usage with man page.
[netbsd-mini2440.git] / tests / util / id / t_id.sh
blobc8d56e1f40e595ff9895c6bcbb1528bfb8a7be5f
1 # $NetBSD: t_id.sh,v 1.3 2008/04/30 13:11:00 martin Exp $
3 # Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
4 # All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
28 create_run_id() {
29 cat >run_id.sh <<EOF
30 #! /bin/sh
31 [ -f ./id ] || ln -s $(atf_get_srcdir)/h_id ./id
32 ./id "\${@}"
33 EOF
34 chmod +x run_id.sh
37 atf_test_case default
38 default_head() {
39 atf_set "descr" "Checks that the output without options is correct"
41 default_body() {
42 create_run_id
44 echo "uid=100(test) gid=100(users) groups=100(users),0(wheel)" >expout
45 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh
46 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh 100
47 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh test
49 echo "uid=0(root) gid=0(wheel) groups=0(wheel)" >expout
50 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh 0
51 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh root
53 export LIBFAKE_EGID_ROOT=1 LIBFAKE_EUID_ROOT=1
54 echo "uid=100(test) gid=100(users) euid=0(root) egid=0(wheel) groups=100(users),0(wheel)" >expout
55 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh
56 unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT
58 echo 'id: nonexistent: No such user' >experr
59 atf_check -s eq:1 -o empty -e file:experr ./run_id.sh nonexistent
61 atf_check -s eq:1 -o empty -e save:stderr ./run_id.sh root nonexistent
62 atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr
65 atf_test_case primaries
66 primaries_head() {
67 atf_set "descr" "Checks that giving multiple primaries" \
68 "simultaneously provides an error"
70 primaries_body() {
71 create_run_id
73 for p1 in -G -g -p -u; do
74 for p2 in -G -g -p -u; do
75 if [ ${p1} != ${p2} ]; then
76 atf_check -s eq:1 -o empty -e save:stderr \
77 ./run_id.sh ${p1} ${p2}
78 atf_check -s eq:0 -o ignore -e empty \
79 grep ^usage: stderr
81 done
82 done
85 atf_test_case Gflag
86 Gflag_head() {
87 atf_set "descr" "Checks that the -G primary flag works"
89 Gflag_body() {
90 create_run_id
92 echo "100 0" >expout
93 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G
94 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G 100
95 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G test
97 echo "users wheel" >expout
98 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n
99 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n 100
100 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n test
102 echo "0" >expout
103 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G 0
104 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G root
106 echo "wheel" >expout
107 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n 0
108 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n root
110 echo 'id: nonexistent: No such user' >experr
111 atf_check -s eq:1 -o empty -e file:experr ./run_id.sh -G nonexistent
113 atf_check -s eq:1 -o empty -e save:stderr ./run_id.sh -G root nonexistent
114 atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr
117 atf_test_case gflag
118 gflag_head() {
119 atf_set "descr" "Checks that the -g primary flag works"
121 gflag_body() {
122 create_run_id
124 echo "100" >expout
125 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g
126 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g 100
127 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g test
129 echo "users" >expout
130 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n
131 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n 100
132 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n test
134 echo "0" >expout
135 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g 0
136 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g root
138 echo "wheel" >expout
139 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n 0
140 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n root
142 echo "100" >expout
143 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r
145 echo "users" >expout
146 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n
148 echo "100" >expout
149 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r 100
150 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r test
152 echo "users" >expout
153 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n 100
154 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n test
156 export LIBFAKE_EGID_ROOT=1 LIBFAKE_EUID_ROOT=1
158 echo "0" >expout
159 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g
161 echo "wheel" >expout
162 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n
164 echo "100" >expout
165 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r
167 echo "users" >expout
168 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n
170 echo "100" >expout
171 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r 100
172 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r test
174 echo "users" >expout
175 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n 100
176 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n test
178 unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT
180 echo 'id: nonexistent: No such user' >experr
181 atf_check -s eq:1 -o empty -e file:experr ./run_id.sh -g nonexistent
183 atf_check -s eq:1 -o empty -e save:stderr ./run_id.sh -g root nonexistent
184 atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr
187 atf_test_case pflag
188 pflag_head() {
189 atf_set "descr" "Checks that the -p primary flag works"
191 pflag_body() {
192 create_run_id
194 cat >expout <<EOF
195 uid test
196 groups users wheel
198 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p
199 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p 100
200 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p test
202 cat >expout <<EOF
203 uid root
204 groups wheel
206 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p 0
207 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p root
209 export LIBFAKE_EGID_ROOT=1 LIBFAKE_EUID_ROOT=1
210 cat >expout <<EOF
211 uid test
212 euid root
213 rgid users
214 groups users wheel
216 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p
217 unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT
219 echo 'id: nonexistent: No such user' >experr
220 atf_check -s eq:1 -o empty -e file:experr ./run_id.sh -p nonexistent
222 atf_check -s eq:1 -o empty -e save:stderr ./run_id.sh -p root nonexistent
223 atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr
226 atf_test_case uflag
227 uflag_head() {
228 atf_set "descr" "Checks that the -u primary flag works"
230 uflag_body() {
231 create_run_id
233 echo "100" >expout
234 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u
235 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u 100
236 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u test
238 echo "test" >expout
239 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n
240 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n 100
241 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n test
243 echo "0" >expout
244 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u 0
245 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u root
247 echo "root" >expout
248 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n 0
249 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n root
251 echo "100" >expout
252 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r
254 echo "test" >expout
255 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n
257 echo "100" >expout
258 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r 100
259 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r test
261 echo "test" >expout
262 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n 100
263 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n test
265 export LIBFAKE_EGID_ROOT=1 LIBFAKE_EUID_ROOT=1
267 echo "0" >expout
268 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u
270 echo "root" >expout
271 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n
273 echo "100" >expout
274 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r
276 echo "test" >expout
277 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n
279 echo "100" >expout
280 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r 100
281 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r test
283 echo "test" >expout
284 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n 100
285 atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n test
287 unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT
289 echo 'id: nonexistent: No such user' >experr
290 atf_check -s eq:1 -o empty -e file:experr ./run_id.sh -u nonexistent
292 atf_check -s eq:1 -o empty -e save:stderr \
293 ./run_id.sh -u root nonexistent
294 atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr
297 atf_init_test_cases()
299 atf_add_test_case default
300 atf_add_test_case primaries
301 atf_add_test_case Gflag
302 atf_add_test_case gflag
303 atf_add_test_case pflag
304 atf_add_test_case uflag