8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libshell / common / tests / sun_solaris_compound_misc.sh
blob96009acafc2cfd689cfcb4303d77d9334c5d6213
2 # CDDL HEADER START
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]
19 # CDDL HEADER END
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.
32 # test setup
33 function err_exit
35 print -u2 -n "\t"
36 print -u2 -r ${Command}[$1]: "${@:2}"
37 (( Errors < 127 && Errors++ ))
39 alias err_exit='err_exit $LINENO'
41 set -o nounset
42 Command=${0##*/}
43 integer Errors=0
45 # global utility functions
46 compound bracketstat=(
47 integer bopen=0
48 integer bclose=0
51 function count_brackets
53 typeset x="$1"
54 typeset c
56 integer i
57 (( bracketstat.bopen=0 , bracketstat.bclose=0 ))
59 for (( i=0 ; i < ${#x} ; i++ )) ; do
60 c="${x:i:1}"
61 [[ "$c" == "(" ]] && (( bracketstat.bopen++ ))
62 [[ "$c" == ")" ]] && (( bracketstat.bclose++ ))
63 done
65 (( bracketstat.bopen != bracketstat.bclose )) && return 1
67 return 0
71 typeset ocwd
72 typeset tmpdir
74 # create temporary test directory
75 ocwd="$PWD"
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]=( ) ) )
84 compound vy
85 compound -a vy.nodes=( [4]=( ) )
86 compound vz
87 compound -a vz.nodes
88 vz.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"
114 return 0
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]=( ) ) )
122 compound vy
123 compound -A vy.nodes=( [4]=( ) )
124 compound vz
125 compound -A vz.nodes
126 vz.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"
152 return 0
155 # run tests
156 test_compound_indexed_array_init_1
157 test_compound_associative_array_init_1
159 cd "${ocwd}"
160 rmdir "${tmpdir}" || err_exit "Cannot remove temporary directory ${tmpdir}".
162 # tests done
163 exit $((Errors))