1 # $NetBSD: t_expand.sh,v 1.3 2009/10/14 13:02:03 jmmv Exp $
3 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
29 # This file tests the functions in expand.c.
34 while [ $# -gt 0 ]; do
35 if [ -z "${str}" ]; then
45 atf_test_case dollar_at
47 atf_set
"descr" "Somewhere between 2.0.2 and 3.0 the expansion" \
48 "of the \$@ variable had been broken. Check for" \
52 # This one should work everywhere.
53 got
=`echo "" "" | sed 's,$,EOL,'`
54 atf_check_equal
' EOL' '$got'
56 # This code triggered the bug.
58 got
=`echo "$@" | sed 's,$,EOL,'`
59 atf_check_equal
' EOL' '$got'
65 atf_check_equal
'0' '$n_args'
68 atf_test_case dollar_at_with_text
69 dollar_at_with_text_head
() {
70 atf_set
"descr" "Test \$@ expansion when it is surrounded by text" \
71 "within the quotes. PR bin/33956."
73 dollar_at_with_text_body
() {
75 atf_check_equal
'' "$(delim_argv "$@
")"
76 atf_check_equal
'>foobar<' "$(delim_argv "foo$@bar
")"
77 atf_check_equal
'>foo bar<' "$(delim_argv "foo $@ bar
")"
80 atf_check_equal
'>a< >b< >c<' "$(delim_argv "$@
")"
81 atf_check_equal
'>fooa< >b< >cbar<' "$(delim_argv "foo$@bar
")"
82 atf_check_equal
'>foo a< >b< >c bar<' "$(delim_argv "foo $@ bar
")"
87 atf_set
"descr" "Checks that the %% operator works and strips" \
88 "the contents of a variable from the given point" \
92 line
='#define bindir "/usr/bin" /* comment */'
93 stripped
='#define bindir "/usr/bin" '
94 atf_check_equal
'$stripped' '${line%%/\**}'
97 atf_test_case varpattern_backslashes
98 varpattern_backslashes_head
() {
99 atf_set
"descr" "Tests that protecting wildcards with backslashes" \
100 "works in variable patterns."
102 varpattern_backslashes_body
() {
103 line
='/foo/bar/*/baz'
105 atf_check_equal
$stripped ${line%%\**}
108 atf_test_case arithmetic
110 atf_set
"descr" "POSIX requires shell arithmetic to use signed" \
111 "long or a wider type. We use intmax_t, so at" \
112 "least 64 bits should be available. Make sure" \
116 atf_check_equal
'3' '$((1 + 2))'
117 atf_check_equal
'2147483647' '$((0x7fffffff))'
118 atf_check_equal
'9223372036854775807' '$(((1 << 63) - 1))'
121 atf_init_test_cases
() {
122 atf_add_test_case dollar_at
123 atf_add_test_case dollar_at_with_text
124 atf_add_test_case strip
125 atf_add_test_case varpattern_backslashes
126 atf_add_test_case arithmetic