1da2e3ebdSchin######################################################################## 2da2e3ebdSchin# # 3da2e3ebdSchin# This software is part of the ast package # 4*3e14f97fSRoger A. Faulkner# Copyright (c) 1982-2010 AT&T Intellectual Property # 5da2e3ebdSchin# and is licensed under the # 6da2e3ebdSchin# Common Public License, Version 1.0 # 77c2fbfb3SApril Chin# by AT&T Intellectual Property # 8da2e3ebdSchin# # 9da2e3ebdSchin# A copy of the License is available at # 10da2e3ebdSchin# http://www.opensource.org/licenses/cpl1.0.txt # 11da2e3ebdSchin# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # 12da2e3ebdSchin# # 13da2e3ebdSchin# Information and Software Systems Research # 14da2e3ebdSchin# AT&T Research # 15da2e3ebdSchin# Florham Park NJ # 16da2e3ebdSchin# # 17da2e3ebdSchin# David Korn <dgk@research.att.com> # 18da2e3ebdSchin# # 19da2e3ebdSchin######################################################################## 20da2e3ebdSchinfunction err_exit 21da2e3ebdSchin{ 22da2e3ebdSchin print -u2 -n "\t" 23da2e3ebdSchin print -u2 -r ${Command}[$1]: "${@:2}" 24da2e3ebdSchin let Errors+=1 25da2e3ebdSchin} 26da2e3ebdSchinalias err_exit='err_exit $LINENO' 27da2e3ebdSchin 28da2e3ebdSchinCommand=${0##*/} 29da2e3ebdSchininteger Errors=0 30da2e3ebdSchin{ 31da2e3ebdSchinx=abc 32da2e3ebdSchinx+=def ;} 2> /dev/null 33da2e3ebdSchinif [[ $x != abcdef ]] 34da2e3ebdSchinthen err_exit 'abc+def != abcdef' 35da2e3ebdSchinfi 36da2e3ebdSchininteger i=3 37da2e3ebdSchin{ i+=4;} 2> /dev/null 38da2e3ebdSchinif (( i != 7 )) 39da2e3ebdSchinthen err_exit '3+4!=7' 40da2e3ebdSchinfi 41da2e3ebdSchiniarray=( one two three ) 42da2e3ebdSchin{ iarray+= (four five six) ;} 2> /dev/null 43da2e3ebdSchinif [[ ${iarray[@]} != 'one two three four five six' ]] 44da2e3ebdSchinthen err_exit 'index array append fails' 45da2e3ebdSchinfi 46da2e3ebdSchinunset iarray 47da2e3ebdSchiniarray=one 48da2e3ebdSchin{ iarray+= (four five six) ;} 2> /dev/null 49da2e3ebdSchinif [[ ${iarray[@]} != 'one four five six' ]] 50da2e3ebdSchinthen err_exit 'index array append to scalar fails' 51da2e3ebdSchinfi 52da2e3ebdSchintypeset -A aarray 53da2e3ebdSchinaarray=( [1]=1 [3]=4 [xyz]=xyz ) 54da2e3ebdSchinaarray+=( [2]=2 [3]=3 [foo]=bar ) 55da2e3ebdSchinif [[ ${aarray[3]} != 3 ]] 56da2e3ebdSchinthen err_exit 'associative array append fails' 57da2e3ebdSchinfi 58da2e3ebdSchinif [[ ${#aarray[@]} != 5 ]] 59da2e3ebdSchinthen err_exit 'number of elements of associative array append fails' 60da2e3ebdSchinfi 61da2e3ebdSchinpoint=(x=1 y=2) 62da2e3ebdSchinpoint+=( y=3 z=4) 63da2e3ebdSchinif [[ ${point.y} != 3 ]] 64da2e3ebdSchinthen err_exit 'compound append fails' 65da2e3ebdSchinfi 667c2fbfb3SApril Chinif [[ ${point.x} != 1 ]] 677c2fbfb3SApril Chinthen err_exit 'compound append to compound variable unsets existing variables' 687c2fbfb3SApril Chinfi 69da2e3ebdSchinunset foo 70da2e3ebdSchinfoo=one 71da2e3ebdSchinfoo+=(two) 72da2e3ebdSchinif [[ ${foo[@]} != 'one two' ]] 73da2e3ebdSchinthen err_exit 'array append to non array variable fails' 74da2e3ebdSchinfi 757c2fbfb3SApril Chinunset foo 767c2fbfb3SApril Chinfoo[0]=(x=3) 777c2fbfb3SApril Chinfoo+=(x=4) 787c2fbfb3SApril Chin[[ ${foo[1].x} == 4 ]] || err_exit 'compound append to index array not working' 797c2fbfb3SApril Chin[[ ${foo[0].x} == 3 ]] || err_exit 'compound append to index array unsets existing variables' 80da2e3ebdSchinexit $((Errors)) 81