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