Home | History | Annotate | Line # | Download | only in sh
t_varquote.sh revision 1.2.2.2
      1  1.2.2.2  yamt # $NetBSD: t_varquote.sh,v 1.2.2.2 2012/04/17 00:09:02 yamt Exp $
      2  1.2.2.2  yamt #
      3  1.2.2.2  yamt # Copyright (c) 2007 The NetBSD Foundation, Inc.
      4  1.2.2.2  yamt # All rights reserved.
      5  1.2.2.2  yamt #
      6  1.2.2.2  yamt # Redistribution and use in source and binary forms, with or without
      7  1.2.2.2  yamt # modification, are permitted provided that the following conditions
      8  1.2.2.2  yamt # are met:
      9  1.2.2.2  yamt # 1. Redistributions of source code must retain the above copyright
     10  1.2.2.2  yamt #    notice, this list of conditions and the following disclaimer.
     11  1.2.2.2  yamt # 2. Redistributions in binary form must reproduce the above copyright
     12  1.2.2.2  yamt #    notice, this list of conditions and the following disclaimer in the
     13  1.2.2.2  yamt #    documentation and/or other materials provided with the distribution.
     14  1.2.2.2  yamt #
     15  1.2.2.2  yamt # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16  1.2.2.2  yamt # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17  1.2.2.2  yamt # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18  1.2.2.2  yamt # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19  1.2.2.2  yamt # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20  1.2.2.2  yamt # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21  1.2.2.2  yamt # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22  1.2.2.2  yamt # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23  1.2.2.2  yamt # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24  1.2.2.2  yamt # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  1.2.2.2  yamt # POSSIBILITY OF SUCH DAMAGE.
     26  1.2.2.2  yamt #
     27  1.2.2.2  yamt 
     28  1.2.2.2  yamt # Variable quoting test.
     29  1.2.2.2  yamt 
     30  1.2.2.2  yamt check() {
     31  1.2.2.2  yamt 	if [ "$1" != "$2" ]
     32  1.2.2.2  yamt 	then
     33  1.2.2.2  yamt 		atf_fail "expected [$2], found [$1]" 1>&2
     34  1.2.2.2  yamt 	fi
     35  1.2.2.2  yamt }
     36  1.2.2.2  yamt 
     37  1.2.2.2  yamt atf_test_case all
     38  1.2.2.2  yamt all_head() {
     39  1.2.2.2  yamt 	atf_set "descr" "Basic checks for variable quoting"
     40  1.2.2.2  yamt }
     41  1.2.2.2  yamt all_body() {
     42  1.2.2.2  yamt 	foo='${a:-foo}'
     43  1.2.2.2  yamt 	check "$foo" '${a:-foo}'
     44  1.2.2.2  yamt 
     45  1.2.2.2  yamt 	foo="${a:-foo}"
     46  1.2.2.2  yamt 	check "$foo" "foo"
     47  1.2.2.2  yamt 
     48  1.2.2.2  yamt 	foo=${a:-"'{}'"}
     49  1.2.2.2  yamt 	check "$foo" "'{}'"
     50  1.2.2.2  yamt 
     51  1.2.2.2  yamt 	foo=${a:-${b:-"'{}'"}}
     52  1.2.2.2  yamt 	check "$foo" "'{}'"
     53  1.2.2.2  yamt 
     54  1.2.2.2  yamt 	foo="${a:-"'{}'"}"
     55  1.2.2.2  yamt 	check "$foo" "'{}'"
     56  1.2.2.2  yamt 
     57  1.2.2.2  yamt 	foo="${a:-${b:-"${c:-${d:-"x}"}}y}"}}z}"
     58  1.2.2.2  yamt 	#   "                                z*"
     59  1.2.2.2  yamt 	#    ${a:-                          }
     60  1.2.2.2  yamt 	#         ${b:-                    }
     61  1.2.2.2  yamt 	#              "                y*"
     62  1.2.2.2  yamt 	#               ${c:-          }
     63  1.2.2.2  yamt 	#                    ${d:-    }
     64  1.2.2.2  yamt 	#                         "x*"
     65  1.2.2.2  yamt 	check "$foo" "x}y}z}"
     66  1.2.2.2  yamt }
     67  1.2.2.2  yamt 
     68  1.2.2.2  yamt atf_test_case nested_quotes_multiword
     69  1.2.2.2  yamt nested_quotes_multiword_head() {
     70  1.2.2.2  yamt 	atf_set "descr" "Tests that having nested quoting in a multi-word" \
     71  1.2.2.2  yamt 	    "string works (PR bin/43597)"
     72  1.2.2.2  yamt }
     73  1.2.2.2  yamt nested_quotes_multiword_body() {
     74  1.2.2.2  yamt 	atf_check -s eq:0 -o match:"first-word second-word" -e empty \
     75  1.2.2.2  yamt 	    /bin/sh -c 'echo "${foo:="first-word"} second-word"'
     76  1.2.2.2  yamt }
     77  1.2.2.2  yamt 
     78  1.2.2.2  yamt atf_init_test_cases() {
     79  1.2.2.2  yamt 	atf_add_test_case all
     80  1.2.2.2  yamt 	atf_add_test_case nested_quotes_multiword
     81  1.2.2.2  yamt }
     82