18462SApril.Chin@Sun.COM#
28462SApril.Chin@Sun.COM# CDDL HEADER START
38462SApril.Chin@Sun.COM#
48462SApril.Chin@Sun.COM# The contents of this file are subject to the terms of the
58462SApril.Chin@Sun.COM# Common Development and Distribution License (the "License").
68462SApril.Chin@Sun.COM# You may not use this file except in compliance with the License.
78462SApril.Chin@Sun.COM#
88462SApril.Chin@Sun.COM# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
98462SApril.Chin@Sun.COM# or http://www.opensolaris.org/os/licensing.
108462SApril.Chin@Sun.COM# See the License for the specific language governing permissions
118462SApril.Chin@Sun.COM# and limitations under the License.
128462SApril.Chin@Sun.COM#
138462SApril.Chin@Sun.COM# When distributing Covered Code, include this CDDL HEADER in each
148462SApril.Chin@Sun.COM# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
158462SApril.Chin@Sun.COM# If applicable, add the following below this CDDL HEADER, with the
168462SApril.Chin@Sun.COM# fields enclosed by brackets "[]" replaced with your own identifying
178462SApril.Chin@Sun.COM# information: Portions Copyright [yyyy] [name of copyright owner]
188462SApril.Chin@Sun.COM#
198462SApril.Chin@Sun.COM# CDDL HEADER END
208462SApril.Chin@Sun.COM#
218462SApril.Chin@Sun.COM
228462SApril.Chin@Sun.COM#
23*12068SRoger.Faulkner@Oracle.COM# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
248462SApril.Chin@Sun.COM#
258462SApril.Chin@Sun.COM
2610898Sroland.mainz@nrubsig.org# test setup
278462SApril.Chin@Sun.COMfunction err_exit
288462SApril.Chin@Sun.COM{
298462SApril.Chin@Sun.COM	print -u2 -n "\t"
308462SApril.Chin@Sun.COM	print -u2 -r ${Command}[$1]: "${@:2}"
31*12068SRoger.Faulkner@Oracle.COM	(( Errors < 127 && Errors++ ))
328462SApril.Chin@Sun.COM}
338462SApril.Chin@Sun.COMalias err_exit='err_exit $LINENO'
348462SApril.Chin@Sun.COM
3510898Sroland.mainz@nrubsig.org# "nounset" disabled for now
3610898Sroland.mainz@nrubsig.org#set -o nounset
3710898Sroland.mainz@nrubsig.orgCommand=${0##*/}
3810898Sroland.mainz@nrubsig.orginteger Errors=0
3910898Sroland.mainz@nrubsig.org
4010898Sroland.mainz@nrubsig.orgcompound bracketstat=(
418462SApril.Chin@Sun.COM	integer bopen=0
428462SApril.Chin@Sun.COM	integer bclose=0
438462SApril.Chin@Sun.COM)
448462SApril.Chin@Sun.COM
458462SApril.Chin@Sun.COMfunction count_brackets
468462SApril.Chin@Sun.COM{
478462SApril.Chin@Sun.COM	typeset x="$1"
488462SApril.Chin@Sun.COM	typeset c
498462SApril.Chin@Sun.COM
508462SApril.Chin@Sun.COM	integer i
518462SApril.Chin@Sun.COM	(( bracketstat.bopen=0 , bracketstat.bclose=0 ))
528462SApril.Chin@Sun.COM
538462SApril.Chin@Sun.COM	for (( i=0 ; i < ${#x} ; i++ )) ; do
548462SApril.Chin@Sun.COM	        c="${x:i:1}"
558462SApril.Chin@Sun.COM		[[ "$c" == "(" ]] && (( bracketstat.bopen++ ))
568462SApril.Chin@Sun.COM		[[ "$c" == ")" ]] && (( bracketstat.bclose++ ))
578462SApril.Chin@Sun.COM	done
588462SApril.Chin@Sun.COM
598462SApril.Chin@Sun.COM	(( bracketstat.bopen != bracketstat.bclose )) && return 1
608462SApril.Chin@Sun.COM
618462SApril.Chin@Sun.COM	return 0
628462SApril.Chin@Sun.COM}
638462SApril.Chin@Sun.COM
6410898Sroland.mainz@nrubsig.org# compound variable "cat" nr.1, using $ print "%B\n" ... #
6510898Sroland.mainz@nrubsig.orgfunction cpvcat1
6610898Sroland.mainz@nrubsig.org{
6710898Sroland.mainz@nrubsig.org	set -o errexit
6810898Sroland.mainz@nrubsig.org	compound tmp
6910898Sroland.mainz@nrubsig.org
7010898Sroland.mainz@nrubsig.org	while read -C tmp ; do printf "%B\n" tmp ; done
7110898Sroland.mainz@nrubsig.org	return 0
7210898Sroland.mainz@nrubsig.org}
7310898Sroland.mainz@nrubsig.org
7410898Sroland.mainz@nrubsig.org# compound variable "cat" nr.2, using $ print "%#B\n" ... #
7510898Sroland.mainz@nrubsig.orgfunction cpvcat2
7610898Sroland.mainz@nrubsig.org{
7710898Sroland.mainz@nrubsig.org	set -o errexit
7810898Sroland.mainz@nrubsig.org	compound tmp
7910898Sroland.mainz@nrubsig.org
8010898Sroland.mainz@nrubsig.org	while read -C tmp ; do printf "%#B\n" tmp ; done
8110898Sroland.mainz@nrubsig.org	return 0
8210898Sroland.mainz@nrubsig.org}
8310898Sroland.mainz@nrubsig.org
8410898Sroland.mainz@nrubsig.org# compound variable "cat" nr.3, using $ print -C ... #
8510898Sroland.mainz@nrubsig.orgfunction cpvcat3
8610898Sroland.mainz@nrubsig.org{
8710898Sroland.mainz@nrubsig.org	set -o errexit
8810898Sroland.mainz@nrubsig.org	compound tmp
8910898Sroland.mainz@nrubsig.org
9010898Sroland.mainz@nrubsig.org	while read -C tmp ; do print -C tmp ; done
9110898Sroland.mainz@nrubsig.org	return 0
9210898Sroland.mainz@nrubsig.org}
9310898Sroland.mainz@nrubsig.org
9410898Sroland.mainz@nrubsig.org# compound variable "cat" nr.4, using $ print -v ... #
9510898Sroland.mainz@nrubsig.orgfunction cpvcat4
9610898Sroland.mainz@nrubsig.org{
9710898Sroland.mainz@nrubsig.org	set -o errexit
9810898Sroland.mainz@nrubsig.org	compound tmp
9910898Sroland.mainz@nrubsig.org
10010898Sroland.mainz@nrubsig.org	while read -C tmp ; do print -v tmp ; done
10110898Sroland.mainz@nrubsig.org	return 0
10210898Sroland.mainz@nrubsig.org}
1038462SApril.Chin@Sun.COM
1048462SApril.Chin@Sun.COMtypeset s
1058462SApril.Chin@Sun.COM
1068462SApril.Chin@Sun.COM# Test 1:
1078462SApril.Chin@Sun.COM# Check whether "read -C" leaves the file pointer at the next line
1088462SApril.Chin@Sun.COM# (and does not read beyond that point).
1098462SApril.Chin@Sun.COM# Data layout is:
1108462SApril.Chin@Sun.COM# -- snip --
1118462SApril.Chin@Sun.COM# <compound var>
1128462SApril.Chin@Sun.COM# hello
1138462SApril.Chin@Sun.COM# -- snip --
1148462SApril.Chin@Sun.COM# (additionally we test some extra stuff like bracket count)
1158462SApril.Chin@Sun.COMs=${
11610898Sroland.mainz@nrubsig.org	compound x=(
1178462SApril.Chin@Sun.COM		a=1 b=2
1188462SApril.Chin@Sun.COM		typeset -a myarray=( 1 2 3 4 5 6 7 8 9 10 )
1198462SApril.Chin@Sun.COM		typeset -A myarray2=( [a]=1 [b]=2 ["c d"]=3 [e]=4 ["f"]=5 [g]=6 [h]=7 [i]=8 [j]=9 [k]=10 )
1208462SApril.Chin@Sun.COM		typeset -A myarray3=(
1218462SApril.Chin@Sun.COM			[a]=(
1228462SApril.Chin@Sun.COM				float m1=0.5
1238462SApril.Chin@Sun.COM				float m2=0.6
1248462SApril.Chin@Sun.COM				foo="hello"
1258462SApril.Chin@Sun.COM			)
1268462SApril.Chin@Sun.COM			[b]=(
1278462SApril.Chin@Sun.COM				foo="bar"
1288462SApril.Chin@Sun.COM			)
1298462SApril.Chin@Sun.COM			["c d"]=(
1308462SApril.Chin@Sun.COM				integer at=90
1318462SApril.Chin@Sun.COM			)
1328462SApril.Chin@Sun.COM			[e]=(
13310898Sroland.mainz@nrubsig.org				compound nested_cpv=(
1348462SApril.Chin@Sun.COM					typeset -a myarray=( 1 2 3 4 5 6 7 8 9 10 )
1358462SApril.Chin@Sun.COM					typeset str=$'a \'string'
1368462SApril.Chin@Sun.COM				)
1378462SApril.Chin@Sun.COM			)
1388462SApril.Chin@Sun.COM			[f]=(
1398462SApril.Chin@Sun.COM				typeset g="f"
1408462SApril.Chin@Sun.COM			)
14110898Sroland.mainz@nrubsig.org			[a_nan]=(
14210898Sroland.mainz@nrubsig.org				float my_nan=-nan
14310898Sroland.mainz@nrubsig.org			)
14410898Sroland.mainz@nrubsig.org			[a_hexfloat]=(
14510898Sroland.mainz@nrubsig.org			       typeset -X my_hexfloat=1.1
14610898Sroland.mainz@nrubsig.org			)
1478462SApril.Chin@Sun.COM		)
1488462SApril.Chin@Sun.COM	)
1498462SApril.Chin@Sun.COM
1508462SApril.Chin@Sun.COM	{
1518462SApril.Chin@Sun.COM		printf "%B\n" x
1528462SApril.Chin@Sun.COM		print "hello"
15310898Sroland.mainz@nrubsig.org	} | cpvcat1 | cpvcat2 | cpvcat3 | cpvcat4 | {
1548462SApril.Chin@Sun.COM		read -C y
1558462SApril.Chin@Sun.COM		read s
1568462SApril.Chin@Sun.COM	}
1578462SApril.Chin@Sun.COM	print "x${s}x"
1588462SApril.Chin@Sun.COM} || err_exit "test returned exit code $?"
1598462SApril.Chin@Sun.COM
1608462SApril.Chin@Sun.COM[[ "${s}" == "xhellox" ]] || err_exit "Expected 'xhellox', got ${s}"
1618462SApril.Chin@Sun.COMcount_brackets "$y" || err_exit "y: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
16210898Sroland.mainz@nrubsig.orgcount_brackets "$(print -v y)" || err_exit "y: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
16310898Sroland.mainz@nrubsig.orgcount_brackets "$(print -C y)" || err_exit "y: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
1648462SApril.Chin@Sun.COM
1658462SApril.Chin@Sun.COM# cleanup
1668462SApril.Chin@Sun.COMunset x y || err_exit "unset failed"
1678462SApril.Chin@Sun.COM[[ "$x" == "" ]] || err_exit "cleanup failed for x"
1688462SApril.Chin@Sun.COM[[ "$y" == "" ]] || err_exit "cleanup failed for y"
1698462SApril.Chin@Sun.COM
1708462SApril.Chin@Sun.COM
1718462SApril.Chin@Sun.COM# Test 2:
1728462SApril.Chin@Sun.COM# Same as test 1 except one more compound var following the "hello"
1738462SApril.Chin@Sun.COM# line.
1748462SApril.Chin@Sun.COM# Data layout is:
1758462SApril.Chin@Sun.COM# -- snip --
1768462SApril.Chin@Sun.COM# <compound var>
1778462SApril.Chin@Sun.COM# hello
1788462SApril.Chin@Sun.COM# <compound var>
1798462SApril.Chin@Sun.COM# -- snip --
1808462SApril.Chin@Sun.COMs=${
18110898Sroland.mainz@nrubsig.org	compound x=(
1828462SApril.Chin@Sun.COM		a=1 b=2
1838462SApril.Chin@Sun.COM		typeset -a myarray=( 1 2 3 4 5 6 7 8 9 10 )
1848462SApril.Chin@Sun.COM		typeset -A myarray2=( [a]=1 [b]=2 ["c d"]=3 [e]=4 ["f"]=5 [g]=6 [h]=7 [i]=8 [j]=9 [k]=10 )
18510898Sroland.mainz@nrubsig.org		compound -A myarray3=(
1868462SApril.Chin@Sun.COM			[a]=(
1878462SApril.Chin@Sun.COM				float m1=0.5
1888462SApril.Chin@Sun.COM				float m2=0.6
1898462SApril.Chin@Sun.COM				foo="hello"
1908462SApril.Chin@Sun.COM			)
1918462SApril.Chin@Sun.COM			[b]=(
1928462SApril.Chin@Sun.COM				foo="bar"
1938462SApril.Chin@Sun.COM			)
1948462SApril.Chin@Sun.COM			["c d"]=(
1958462SApril.Chin@Sun.COM				integer at=90
1968462SApril.Chin@Sun.COM			)
1978462SApril.Chin@Sun.COM			[e]=(
19810898Sroland.mainz@nrubsig.org				compound nested_cpv=(
1998462SApril.Chin@Sun.COM					typeset -a myarray=( 1 2 3 4 5 6 7 8 9 10 )
2008462SApril.Chin@Sun.COM					typeset str=$'a \'string'
2018462SApril.Chin@Sun.COM				)
2028462SApril.Chin@Sun.COM			)
2038462SApril.Chin@Sun.COM			[f]=(
2048462SApril.Chin@Sun.COM				typeset g="f"
2058462SApril.Chin@Sun.COM			)
20610898Sroland.mainz@nrubsig.org			[a_nan]=(
20710898Sroland.mainz@nrubsig.org				float my_nan=-nan
20810898Sroland.mainz@nrubsig.org			)
20910898Sroland.mainz@nrubsig.org			[a_hexfloat]=(
21010898Sroland.mainz@nrubsig.org			       typeset -X my_hexfloat=1.1
21110898Sroland.mainz@nrubsig.org			)
2128462SApril.Chin@Sun.COM		)
2138462SApril.Chin@Sun.COM	)
2148462SApril.Chin@Sun.COM
2158462SApril.Chin@Sun.COM	{
2168462SApril.Chin@Sun.COM		printf "%B\n" x
2178462SApril.Chin@Sun.COM		print "hello"
2188462SApril.Chin@Sun.COM		printf "%B\n" x
21910898Sroland.mainz@nrubsig.org	} | cpvcat1 | cpvcat2 | cpvcat3 | cpvcat4 | {
2208462SApril.Chin@Sun.COM		read -C y1
2218462SApril.Chin@Sun.COM		read s
2228462SApril.Chin@Sun.COM		read -C y2
2238462SApril.Chin@Sun.COM	}
2248462SApril.Chin@Sun.COM
2258462SApril.Chin@Sun.COM	print "x${s}x"
2268462SApril.Chin@Sun.COM} || err_exit "test returned exit code $?"
2278462SApril.Chin@Sun.COM
2288462SApril.Chin@Sun.COM[[ "${s}" == "xhellox" ]] || err_exit "Expected 'xhellox', got ${s}."
22910898Sroland.mainz@nrubsig.org[[ "${y1.myarray3[b].foo}" == "bar" ]] || err_exit "y1.myarray3[b].foo != bar"
23010898Sroland.mainz@nrubsig.org[[ "${y2.myarray3[b].foo}" == "bar" ]] || err_exit "y2.myarray3[b].foo != bar"
2318462SApril.Chin@Sun.COM[[ "$y1" != "" ]] || err_exit "y1 is empty"
2328462SApril.Chin@Sun.COM[[ "$y2" != "" ]] || err_exit "y2 is empty"
23310898Sroland.mainz@nrubsig.org(( ${#y1.myarray3[e].nested_cpv.myarray[@]} == 10 )) || err_exit "Expected 10 elements in y1.myarray3[e].nested_cpv, got ${#y1.myarray3[e].nested_cpv[@]}"
23410898Sroland.mainz@nrubsig.org(( ${#y2.myarray3[e].nested_cpv.myarray[@]} == 10 )) || err_exit "Expected 10 elements in y2.myarray3[e].nested_cpv, got ${#y2.myarray3[e].nested_cpv[@]}"
23510898Sroland.mainz@nrubsig.org(( isnan(y1.myarray3[a_nan].my_nan) ))   || err_exit "y1.myarray3[a_nan].my_nan not a NaN"
23610898Sroland.mainz@nrubsig.org(( isnan(y2.myarray3[a_nan].my_nan) ))   || err_exit "y2.myarray3[a_nan].my_nan not a NaN"
23710898Sroland.mainz@nrubsig.org(( signbit(y1.myarray3[a_nan].my_nan) )) || err_exit "y1.myarray3[a_nan].my_nan not negative"
23810898Sroland.mainz@nrubsig.org(( signbit(y2.myarray3[a_nan].my_nan) )) || err_exit "y2.myarray3[a_nan].my_nan not negative"
2398462SApril.Chin@Sun.COMcount_brackets "$y1" || err_exit "y1: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
24010898Sroland.mainz@nrubsig.orgcount_brackets "$(print -v y1)" || err_exit "y1: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
24110898Sroland.mainz@nrubsig.orgcount_brackets "$(print -C y1)" || err_exit "y1: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
2428462SApril.Chin@Sun.COMcount_brackets "$y2" || err_exit "y2: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
24310898Sroland.mainz@nrubsig.orgcount_brackets "$(print -v y2)" || err_exit "y2: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
24410898Sroland.mainz@nrubsig.orgcount_brackets "$(print -C y2)" || err_exit "y2: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
2458462SApril.Chin@Sun.COM[[ "$y1" == "$y2" ]] || err_exit "Expected $(printf "%q\n" "${y1}") == $(printf "%q\n" "${y2}")."
2468462SApril.Chin@Sun.COM[[ "$x"  == "$y1" ]] || err_exit "Expected $(printf "%q\n" "${x}") == $(printf "%q\n" "${y}")."
2478462SApril.Chin@Sun.COM
2488462SApril.Chin@Sun.COM# cleanup
2498462SApril.Chin@Sun.COMunset x y1 y2 || err_exit "unset failed"
2508462SApril.Chin@Sun.COM[[ "$x" == "" ]]  || err_exit "cleanup failed for x"
2518462SApril.Chin@Sun.COM[[ "$y1" == "" ]] || err_exit "cleanup failed for y1"
2528462SApril.Chin@Sun.COM[[ "$y2" == "" ]] || err_exit "cleanup failed for y2"
2538462SApril.Chin@Sun.COM
2548462SApril.Chin@Sun.COM
2558462SApril.Chin@Sun.COM# Test 3: Test compound variable copy operator vs. "read -C"
25610898Sroland.mainz@nrubsig.orgcompound x=(
2578462SApril.Chin@Sun.COM	a=1 b=2
2588462SApril.Chin@Sun.COM	typeset -a myarray=( 1 2 3 4 5 6 7 8 9 10 )
2598462SApril.Chin@Sun.COM	typeset -A myarray2=( [a]=1 [b]=2 ["c d"]=3 [e]=4 ["f"]=5 [g]=6 [h]=7 [i]=8 [j]=9 [k]=10 )
26010898Sroland.mainz@nrubsig.org	compound -A myarray3=(
2618462SApril.Chin@Sun.COM		[a]=(
2628462SApril.Chin@Sun.COM			float m1=0.5
2638462SApril.Chin@Sun.COM			float m2=0.6
2648462SApril.Chin@Sun.COM			foo="hello"
2658462SApril.Chin@Sun.COM		)
2668462SApril.Chin@Sun.COM		[b]=(
2678462SApril.Chin@Sun.COM			foo="bar"
2688462SApril.Chin@Sun.COM		)
2698462SApril.Chin@Sun.COM		["c d"]=(
2708462SApril.Chin@Sun.COM			integer at=90
2718462SApril.Chin@Sun.COM		)
2728462SApril.Chin@Sun.COM		[e]=(
27310898Sroland.mainz@nrubsig.org			compound nested_cpv=(
2748462SApril.Chin@Sun.COM				typeset -a myarray=( 1 2 3 4 5 6 7 8 9 10 )
2758462SApril.Chin@Sun.COM				typeset str=$'a \'string'
2768462SApril.Chin@Sun.COM			)
2778462SApril.Chin@Sun.COM		)
2788462SApril.Chin@Sun.COM		[f]=(
2798462SApril.Chin@Sun.COM			typeset g="f"
2808462SApril.Chin@Sun.COM		)
28110898Sroland.mainz@nrubsig.org		[a_nan]=(
28210898Sroland.mainz@nrubsig.org			float my_nan=-nan
28310898Sroland.mainz@nrubsig.org		)
28410898Sroland.mainz@nrubsig.org		[a_hexfloat]=(
28510898Sroland.mainz@nrubsig.org		       typeset -X my_hexfloat=1.1
28610898Sroland.mainz@nrubsig.org		)
2878462SApril.Chin@Sun.COM	)
2888462SApril.Chin@Sun.COM)
2898462SApril.Chin@Sun.COM
29010898Sroland.mainz@nrubsig.orgcompound x_copy=x || err_exit "x_copy copy failed"
2918462SApril.Chin@Sun.COM[[ "${x_copy}" != "" ]] || err_exit "x_copy should not be empty"
2928462SApril.Chin@Sun.COMcount_brackets "${x_copy}" || err_exit "x_copy: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
29310898Sroland.mainz@nrubsig.orgcount_brackets "$(print -v x_copy)" || err_exit "x_copy: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
29410898Sroland.mainz@nrubsig.orgcount_brackets "$(print -C x_copy)" || err_exit "x_copy: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
2958462SApril.Chin@Sun.COM
29610898Sroland.mainz@nrubsig.orgcompound nested_cpv_copy
2978462SApril.Chin@Sun.COM
2988462SApril.Chin@Sun.COMnested_cpv_copy=x.myarray3[e].nested_cpv || err_exit "x.myarray3[e].nested_cpv copy failed"
29910898Sroland.mainz@nrubsig.org(( ${#nested_cpv_copy.myarray[@]} == 10 )) || err_exit "Expected 10 elements in nested_cpv_copy.myarray, got ${#nested_cpv_copy.myarray[@]}"
3008462SApril.Chin@Sun.COM
3018462SApril.Chin@Sun.COM# unset branch "x.myarray3[e].nested_cpv" of the variable tree "x" ...
3028462SApril.Chin@Sun.COMunset x.myarray3[e].nested_cpv || err_exit "unset x.myarray3[e].nested_cpv failed"
3038462SApril.Chin@Sun.COM[[ "${x.myarray3[e].nested_cpv}" == "" ]] || err_exit "x.myarray3[e].nested_cpv still has a value"
3048462SApril.Chin@Sun.COM
3058462SApril.Chin@Sun.COM# ... and restore it from the saved copy
30610898Sroland.mainz@nrubsig.orgprintf "%B\n" nested_cpv_copy | cpvcat1 | cpvcat2 | cpvcat3 | cpvcat4 | read -C x.myarray3[e].nested_cpv || err_exit "read failed"
3078462SApril.Chin@Sun.COM
3088462SApril.Chin@Sun.COM# compare copy of the original tree and the modified one
3098462SApril.Chin@Sun.COM[[ "${x}" == "${x_copy}" ]] || err_exit "x != x_copy"
3108462SApril.Chin@Sun.COMcount_brackets "${x}" || err_exit "x: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
31110898Sroland.mainz@nrubsig.orgcount_brackets "$(print -v x)" || err_exit "x: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
31210898Sroland.mainz@nrubsig.orgcount_brackets "$(print -C x)" || err_exit "x: bracket open ${bracketstat.bopen} != bracket close ${bracketstat.bclose}"
31310898Sroland.mainz@nrubsig.org(( ${#x.myarray3[e].nested_cpv.myarray[@]} == 10 )) || err_exit "Expected 10 elements in x.myarray3[e].nested_cpv, got ${#x.myarray3[e].nested_cpv[@]}"
31410898Sroland.mainz@nrubsig.org(( isnan(x.myarray3[a_nan].my_nan) ))   || err_exit "x.myarray3[a_nan].my_nan not a NaN"
31510898Sroland.mainz@nrubsig.org(( signbit(x.myarray3[a_nan].my_nan) )) || err_exit "x.myarray3[a_nan].my_nan not negative"
3168462SApril.Chin@Sun.COM
3178462SApril.Chin@Sun.COM# cleanup
3188462SApril.Chin@Sun.COMunset x x_copy nested_cpv_copy || err_exit "unset failed"
3198462SApril.Chin@Sun.COM
3208462SApril.Chin@Sun.COM
3218462SApril.Chin@Sun.COM# Test 4: Test "read -C" failure for missing bracket at the end
3228462SApril.Chin@Sun.COMtypeset s
32310898Sroland.mainz@nrubsig.orgs=$($SHELL -c 'compound myvar ; print "( unfinished=1" | read -C myvar 2>/dev/null || print "error $?"') || err_exit "shell failed"
3248462SApril.Chin@Sun.COM[[ "$s" == "error 3" ]] || err_exit "compound_read: expected error 3, got ${s}"
3258462SApril.Chin@Sun.COM
3268462SApril.Chin@Sun.COM
3278462SApril.Chin@Sun.COM# Test 5: Test "read -C" failure for missing bracket at the beginning
3288462SApril.Chin@Sun.COMtypeset s
32910898Sroland.mainz@nrubsig.orgs=$($SHELL -c 'compound myvar ; print "  unfinished=1 )" | read -C myvar 2>/dev/null || print "error $?"') || err_exit "shell failed"
3308462SApril.Chin@Sun.COM[[ "$s" == "error 3" ]] || err_exit "compound_read: expected error 3, got ${s}"
3318462SApril.Chin@Sun.COM
33210898Sroland.mainz@nrubsig.org
3338462SApril.Chin@Sun.COM# tests done
3348462SApril.Chin@Sun.COMexit $((Errors))
335