tools/llvm: Do not build with symbols
[minix3.git] / tests / lib / libc / stdlib / t_getopt.sh
blobcc10f65254323637e9366d59befdca0373a2ffd8
1 # $NetBSD: t_getopt.sh,v 1.1 2011/01/01 23:56:49 pgoyette Exp $
3 # Copyright (c) 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 h_getopt()
30 atf_check -e save:stderr -x "$(atf_get_srcdir)/h_getopt" <<EOF
31 load: $1
32 args: $2
33 result: $3
34 EOF
35 cat stderr
36 rm -f stderr
39 h_getopt_long()
41 atf_check -e save:stderr -x "$(atf_get_srcdir)/h_getopt_long" <<EOF
43 args: $2
44 result: $3
45 EOF
46 cat stderr
47 rm -f stderr
50 atf_test_case getopt
51 getopt_head()
53 atf_set "descr" "Checks getopt(3)"
55 getopt_body()
57 load="c:d"
59 h_getopt "${load}" "foo -c 1 -d foo" "c=1,d|1"
60 h_getopt "${load}" "foo -d foo bar" "d|2"
61 h_getopt "${load}" "foo -c 2 foo bar" "c=2|2"
62 h_getopt "${load}" "foo -e 1 foo bar" "!?|3"
63 h_getopt "${load}" "foo -d -- -c 1" "d|2"
64 h_getopt "${load}" "foo -c- 1" "c=-|1"
65 h_getopt "${load}" "foo -d - 1" "d|2"
68 atf_test_case getopt_long
69 getopt_long_head()
71 atf_set "descr" "Checks getopt_long(3)"
73 getopt_long_body()
75 # GNU libc tests with these
76 load="optstring: abc:
77 longopts: 5
78 longopt: required, required_argument, , 'r'
79 longopt: optional, optional_argument, , 'o'
80 longopt: none, no_argument, , 'n'
81 longopt: color, no_argument, , 'C'
82 longopt: colour, no_argument, , 'C'"
84 h_getopt_long "${load}" "foo --req foobar" "-required=foobar|0"
85 h_getopt_long "${load}" "foo --opt=bazbug" "-optional=bazbug|0"
87 # This is problematic
89 # GNU libc 2.1.3 this fails with ambiguous result
90 # h_getopt_long "${load}" "foo --col" "!?|0"
92 # GNU libc 2.2 >= this works
93 h_getopt_long "${load}" "foo --col" "-color|0"
95 h_getopt_long "${load}" "foo --colour" "-colour|0"
97 # This is the real GNU libc test!
98 args="foo -a -b -cfoobar --required foobar --optional=bazbug --none random --col --color --colour"
99 # GNU libc 2.1.3 this fails with ambiguous
100 #result="a,b,c=foobar,-required=foobar,-optional=bazbug,-none,!?,-color,-colour|1"
102 # GNU libc 2.2 >= this works
103 result="a,b,c=foobar,-required=foobar,-optional=bazbug,-none,-color,-color,-colour|1"
104 h_getopt_long "${load}" "${args}" "${result}"
107 # The order of long options in the long option array should not matter.
108 # An exact match should never be treated as ambiguous.
110 load="optstring: fgl
111 longopts: 3
112 longopt: list-foobar, no_argument, lopt, 'f'
113 longopt: list-goobar, no_argument, lopt, 'g'
114 longopt: list, no_argument, lopt, 'l'"
115 h_getopt_long "${load}" "foo --list" "-list|0"
119 atf_init_test_cases()
121 atf_add_test_case getopt
122 atf_add_test_case getopt_long