4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
27 # This test module contains misc compound tests which do not have
28 # their own module yet.
36 print
-u2 -r ${Command}[$1]: "${@:2}"
37 (( Errors
< 127 && Errors
++ ))
39 alias err_exit
='err_exit $LINENO'
45 # global utility functions
46 compound bracketstat
=(
51 function count_brackets
57 (( bracketstat.bopen
=0 , bracketstat.bclose
=0 ))
59 for (( i
=0 ; i
< ${#x} ; i
++ )) ; do
61 [[ "$c" == "(" ]] && (( bracketstat.bopen
++ ))
62 [[ "$c" == ")" ]] && (( bracketstat.bclose
++ ))
65 (( bracketstat.bopen
!= bracketstat.bclose
)) && return 1
74 # create temporary test directory
76 tmpdir
="$(mktemp -t -d "test_sun_solaris_compound_misc.XXXXXXXX
")" || err_exit
"Cannot create temporary directory"
78 cd "${tmpdir}" || { err_exit "cd ${tmpdir} failed." ; exit $((Errors)) ; }
80 # ksh93 <= ast-ksh.2010-03-09 prints garbage for compound x=( compound -a nodes=( [4]=( ) ) );typeset -p x
81 function test_compound_indexed_array_init_1
83 compound vx=( compound -a nodes=( [4]=( ) ) )
85 compound -a vy.nodes=( [4]=( ) )
90 cx="$
(typeset
-p vx
)" ; cx="${cx//vx/tt}"
91 cy="$
(typeset
-p vy
)" ; cy="${cy//vy/tt}"
92 cz="$
(typeset
-p vz
)" ; cz="${cz//vz/tt}"
93 [[ "$cx" == "$cy" ]] || err_exit "'$cx' != '$cy'"
94 [[ "$cx" == "$cz" ]] || err_exit "'$cx' != '$cz'"
95 [[ "$cy" == "$cz" ]] || err_exit "'$cy' != '$cz'"
97 count_brackets "$cx" || err_exit "Brackets not balanced
for '$cx'"
98 count_brackets "$cy" || err_exit "Brackets not balanced
for '$cy'"
99 count_brackets "$cz" || err_exit "Brackets not balanced
for '$cz'"
100 count_brackets "$
(print
-v vx
)" || err_exit "Brackets not balanced
for '$(print -v vx)'"
101 count_brackets "$
(print
-v vy
)" || err_exit "Brackets not balanced
for '$(print -v vy)'"
102 count_brackets "$
(print
-v vz
)" || err_exit "Brackets not balanced
for '$(print -v vz)'"
103 count_brackets "$
(print
-C vx
)" || err_exit "Brackets not balanced
for '$(print -C vx)'"
104 count_brackets "$
(print
-C vy
)" || err_exit "Brackets not balanced
for '$(print -C vy)'"
105 count_brackets "$
(print
-C vz
)" || err_exit "Brackets not balanced
for '$(print -C vz)'"
107 cx="$
(typeset
+p vx.nodes
)" ; [[ "$cx" == *-C* && "$cx" == *-a* ]] || err_exit "'$cx' lacks
-C/-a attribute
"
108 cy="$
(typeset
+p vy.nodes
)" ; [[ "$cy" == *-C* && "$cy" == *-a* ]] || err_exit "'$cy' lacks
-C/-a attribute
"
109 cz="$
(typeset
+p vz.nodes
)" ; [[ "$cz" == *-C* && "$cz" == *-a* ]] || err_exit "'$cz' lacks
-C/-a attribute
"
110 cx="$
(typeset
+p vx.nodes
[4])" ; [[ "$cx" == *-C* ]] || err_exit "'$cx' lacks
-C attribute
"
111 cy="$
(typeset
+p vy.nodes
[4])" ; [[ "$cy" == *-C* ]] || err_exit "'$cy' lacks
-C attribute
"
112 cz="$
(typeset
+p vz.nodes
[4])" ; [[ "$cz" == *-C* ]] || err_exit "'$cz' lacks
-C attribute
"
117 # ksh93 <= ast-ksh.2010-03-09 prints garbage for compound x=( compound -a nodes=( [4]=( ) ) );typeset -p x
118 # this test is the same as test_compound_indexed_array_init_1 but "-a" was replaced with "-A"
119 function test_compound_associative_array_init_1
121 compound vx=( compound -A nodes=( [4]=( ) ) )
123 compound -A vy.nodes=( [4]=( ) )
128 cx="$
(typeset
-p vx
)" ; cx="${cx//vx/tt}"
129 cy="$
(typeset
-p vy
)" ; cy="${cy//vy/tt}"
130 cz="$
(typeset
-p vz
)" ; cz="${cz//vz/tt}"
131 [[ "$cx" == "$cy" ]] || err_exit "'$cx' != '$cy'"
132 [[ "$cx" == "$cz" ]] || err_exit "'$cx' != '$cz'"
133 [[ "$cy" == "$cz" ]] || err_exit "'$cy' != '$cz'"
135 count_brackets "$cx" || err_exit "Brackets not balanced
for '$cx'"
136 count_brackets "$cy" || err_exit "Brackets not balanced
for '$cy'"
137 count_brackets "$cz" || err_exit "Brackets not balanced
for '$cz'"
138 count_brackets "$
(print
-v vx
)" || err_exit "Brackets not balanced
for '$(print -v vx)'"
139 count_brackets "$
(print
-v vy
)" || err_exit "Brackets not balanced
for '$(print -v vy)'"
140 count_brackets "$
(print
-v vz
)" || err_exit "Brackets not balanced
for '$(print -v vz)'"
141 count_brackets "$
(print
-C vx
)" || err_exit "Brackets not balanced
for '$(print -C vx)'"
142 count_brackets "$
(print
-C vy
)" || err_exit "Brackets not balanced
for '$(print -C vy)'"
143 count_brackets "$
(print
-C vz
)" || err_exit "Brackets not balanced
for '$(print -C vz)'"
145 cx="$
(typeset
+p vx.nodes
)" ; [[ "$cx" == *-C* && "$cx" == *-A* ]] || err_exit "'$cx' lacks
-C/-A attribute
"
146 cy="$
(typeset
+p vy.nodes
)" ; [[ "$cy" == *-C* && "$cy" == *-A* ]] || err_exit "'$cy' lacks
-C/-A attribute
"
147 cz="$
(typeset
+p vz.nodes
)" ; [[ "$cz" == *-C* && "$cz" == *-A* ]] || err_exit "'$cz' lacks
-C/-A attribute
"
148 cx="$
(typeset
+p vx.nodes
[4])" ; [[ "$cx" == *-C* ]] || err_exit "'$cx' lacks
-C attribute
"
149 cy="$
(typeset
+p vy.nodes
[4])" ; [[ "$cy" == *-C* ]] || err_exit "'$cy' lacks
-C attribute
"
150 cz="$
(typeset
+p vz.nodes
[4])" ; [[ "$cz" == *-C* ]] || err_exit "'$cz' lacks
-C attribute
"
156 test_compound_indexed_array_init_1
157 test_compound_associative_array_init_1
160 rmdir "${tmpdir}" || err_exit "Cannot remove temporary directory
${tmpdir}".