xref: /onnv-gate/usr/src/lib/libshell/common/tests/treemove.sh (revision 10898:1883b621b3ea)
1*10898Sroland.mainz@nrubsig.org#
2*10898Sroland.mainz@nrubsig.org# CDDL HEADER START
3*10898Sroland.mainz@nrubsig.org#
4*10898Sroland.mainz@nrubsig.org# The contents of this file are subject to the terms of the
5*10898Sroland.mainz@nrubsig.org# Common Development and Distribution License (the "License").
6*10898Sroland.mainz@nrubsig.org# You may not use this file except in compliance with the License.
7*10898Sroland.mainz@nrubsig.org#
8*10898Sroland.mainz@nrubsig.org# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*10898Sroland.mainz@nrubsig.org# or http://www.opensolaris.org/os/licensing.
10*10898Sroland.mainz@nrubsig.org# See the License for the specific language governing permissions
11*10898Sroland.mainz@nrubsig.org# and limitations under the License.
12*10898Sroland.mainz@nrubsig.org#
13*10898Sroland.mainz@nrubsig.org# When distributing Covered Code, include this CDDL HEADER in each
14*10898Sroland.mainz@nrubsig.org# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*10898Sroland.mainz@nrubsig.org# If applicable, add the following below this CDDL HEADER, with the
16*10898Sroland.mainz@nrubsig.org# fields enclosed by brackets "[]" replaced with your own identifying
17*10898Sroland.mainz@nrubsig.org# information: Portions Copyright [yyyy] [name of copyright owner]
18*10898Sroland.mainz@nrubsig.org#
19*10898Sroland.mainz@nrubsig.org# CDDL HEADER END
20*10898Sroland.mainz@nrubsig.org#
21*10898Sroland.mainz@nrubsig.org
22*10898Sroland.mainz@nrubsig.org#
23*10898Sroland.mainz@nrubsig.org# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*10898Sroland.mainz@nrubsig.org# Use is subject to license terms.
25*10898Sroland.mainz@nrubsig.org#
26*10898Sroland.mainz@nrubsig.org
27*10898Sroland.mainz@nrubsig.org#
28*10898Sroland.mainz@nrubsig.org# This test checks whether "typeset -m" correctly moves local variables
29*10898Sroland.mainz@nrubsig.org# into a global variable tree.
30*10898Sroland.mainz@nrubsig.org#
31*10898Sroland.mainz@nrubsig.org# This was reported as CR #XXXXXXXX ("XXXX"):
32*10898Sroland.mainz@nrubsig.org# -- snip --
33*10898Sroland.mainz@nrubsig.org#XXXX
34*10898Sroland.mainz@nrubsig.org# -- snip --
35*10898Sroland.mainz@nrubsig.org#
36*10898Sroland.mainz@nrubsig.org
37*10898Sroland.mainz@nrubsig.orgfunction err_exit
38*10898Sroland.mainz@nrubsig.org{
39*10898Sroland.mainz@nrubsig.org	print -u2 -n "\t"
40*10898Sroland.mainz@nrubsig.org	print -u2 -r ${Command}[$1]: "${@:2}"
41*10898Sroland.mainz@nrubsig.org	(( Errors+=1 ))
42*10898Sroland.mainz@nrubsig.org}
43*10898Sroland.mainz@nrubsig.org
44*10898Sroland.mainz@nrubsig.orgalias err_exit='err_exit $LINENO'
45*10898Sroland.mainz@nrubsig.org
46*10898Sroland.mainz@nrubsig.orginteger Errors=0
47*10898Sroland.mainz@nrubsig.org
48*10898Sroland.mainz@nrubsig.org## test start
49*10898Sroland.mainz@nrubsig.orgtypeset -C tree1 tree2
50*10898Sroland.mainz@nrubsig.org
51*10898Sroland.mainz@nrubsig.org# add node to tree which uses "typeset -m" to move a local variable
52*10898Sroland.mainz@nrubsig.org# into tree1.subtree["a_node"]
53*10898Sroland.mainz@nrubsig.orgfunction f1
54*10898Sroland.mainz@nrubsig.org{
55*10898Sroland.mainz@nrubsig.org	nameref tr=$1
56*10898Sroland.mainz@nrubsig.org	typeset -A tr.subtree
57*10898Sroland.mainz@nrubsig.org	typeset -C node
58*10898Sroland.mainz@nrubsig.org	node.one="hello"
59*10898Sroland.mainz@nrubsig.org	node.two="world"
60*10898Sroland.mainz@nrubsig.org	# move local note into the array
61*10898Sroland.mainz@nrubsig.orgfalse
62*10898Sroland.mainz@nrubsig.org	typeset -m tr.subtree["a_node"]=node
63*10898Sroland.mainz@nrubsig.org	return 0
64*10898Sroland.mainz@nrubsig.org}
65*10898Sroland.mainz@nrubsig.org
66*10898Sroland.mainz@nrubsig.org# Alternative version which uses "nameref" instead of "typeset -m"
67*10898Sroland.mainz@nrubsig.orgfunction f2
68*10898Sroland.mainz@nrubsig.org{
69*10898Sroland.mainz@nrubsig.org	nameref tr=$1
70*10898Sroland.mainz@nrubsig.org	typeset -A tr.subtree
71*10898Sroland.mainz@nrubsig.org	nameref node=tr.subtree["a_node"]
72*10898Sroland.mainz@nrubsig.org	node.one="hello"
73*10898Sroland.mainz@nrubsig.org	node.two="world"
74*10898Sroland.mainz@nrubsig.org	return 0
75*10898Sroland.mainz@nrubsig.org}
76*10898Sroland.mainz@nrubsig.org
77*10898Sroland.mainz@nrubsig.orgf1 tree1
78*10898Sroland.mainz@nrubsig.orgf2 tree2
79*10898Sroland.mainz@nrubsig.org
80*10898Sroland.mainz@nrubsig.org[[ "${tree1.subtree["a_node"].one}" == "hello" ]] || err_exit "expected tree1.subtree[\"a_node\"].one == 'hello', got ${tree1.subtree["a_node"].one}"
81*10898Sroland.mainz@nrubsig.org[[ "${tree1.subtree["a_node"].two}" == "world" ]] || err_exit "expected tree1.subtree[\"a_node\"].two == 'world', got ${tree1.subtree["a_node"].two}"
82*10898Sroland.mainz@nrubsig.org[[ "${tree1}" == "${tree2}" ]] || err_exit "tree1 and tree2 differ:$'\n'"
83*10898Sroland.mainz@nrubsig.org
84*10898Sroland.mainz@nrubsig.org# tests done
85*10898Sroland.mainz@nrubsig.orgexit $((Errors))
86