1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
# function-y.tst: yash-specific test of functions
(
posix="true"
test_Oe -e 2 'function keyword (-o posix)'
function foo() { echo foo; }
__IN__
syntax error: `function' cannot be used as a command name
__ERR__
#'
#`
test_Oe -e 2 'invalid character - in function name'
a-b() { echo foo; }
__IN__
syntax error: invalid function name
__ERR__
)
test_oE 'function definition w/ function keyword w/ parentheses, grouping'
function foo(){ echo bar; }
echo $?
foo
__IN__
0
bar
__OUT__
test_oE 'function definition w/ function keyword w/o parentheses, grouping'
function foo { echo bar; }
echo $?
foo
__IN__
0
bar
__OUT__
test_oE 'function definition w/ function keyword w/ parentheses, subshell'
function foo()(echo bar)
echo $?
foo
__IN__
0
bar
__OUT__
test_oE 'function definition w/ function keyword w/o parentheses, subshell, single line'
function foo(echo bar)
echo $?
foo
__IN__
0
bar
__OUT__
test_oE 'function definition w/ function keyword w/o parentheses, subshell, multi-line'
function foo(
echo bar)
echo $?
foo
__IN__
0
bar
__OUT__
test_oE 'function definition w/ function keyword w/o parentheses, subshell, single line'
function foo(echo bar)
echo $?
foo
__IN__
0
bar
__OUT__
test_oE 'function definition with whitespaces in between'
function foo ( ) { echo bar; }
echo $?
foo
__IN__
0
bar
__OUT__
test_oE 'function definition w/ function keyword w/ parentheses, linebreak'
function foo ( )
{ echo bar; }
echo $?
foo
__IN__
0
bar
__OUT__
test_oE 'function definition w/ function keyword w/o parentheses, linebreak'
function foo
{ echo bar; }
echo $?
foo
__IN__
0
bar
__OUT__
test_oE 'quotes and expansions in function name'
HOME=/a H=h
function ~/b/c"d\$e"f$(echo g)$((1+1))${H}i { echo foo; }
command -f '/a/b/cd$efg2hi'
__IN__
foo
__OUT__
test_oE 'redefining function'
func() { echo initial; }
func
func() { func() { echo redefined; } }
func
echo ---
func
__IN__
initial
---
redefined
__OUT__
test_o 'effect of redefining read-only function'
func() { echo foo; }
readonly -f func
func() { echo not reached; }
func
__IN__
foo
__OUT__
test_x -d -e 2 'error message and exit status of redefining read-only function'
func() { echo foo; }
readonly -f func
func() { :; }
__IN__
test_Oe -e 2 'simple command as function body (w/o function keyword)'
foo() echo >/dev/null
__IN__
syntax error: a function body must be a compound command
__ERR__
#'
#`
test_Oe -e 2 'simple command as function body (w/ function keyword)'
function foo() echo >/dev/null
__IN__
syntax error: a function body must be a compound command
__ERR__
#'
#`
test_Oe -e 2 'function definition as function body'
foo() bar() { :; }
__IN__
syntax error: a function body must be a compound command
__ERR__
test_Oe -e 2 'function followed by EOF'
function
__IN__
syntax error: a word is required after `function'
syntax error: a function body must be a compound command
__ERR__
#'
#`
test_Oe -e 2 'function followed by symbol'
function |
__IN__
syntax error: a word is required after `function'
syntax error: a function body must be a compound command
__ERR__
#'
#`
test_Oe -e 2 'function followed by newline'
function ###
foo() { :; }
__IN__
syntax error: a word is required after `function'
syntax error: a function body must be a compound command
__ERR__
#'
#`
test_oE 'function as function name'
function function () {
echo foo
}
\function
__IN__
foo
__OUT__
test_Oe -e 2 'function name followed by EOF (w/ function keyword)'
function foo
__IN__
syntax error: a function body must be a compound command
__ERR__
test_Oe -e 2 'parentheses followed by EOF (w/ function keyword)'
function foo()
__IN__
syntax error: a function body must be a compound command
__ERR__
test_Oe -e 2 'parentheses followed by EOF (w/o function keyword)'
foo()
__IN__
syntax error: a function body must be a compound command
__ERR__
test_Oe -e 2 'unpaired parenthesis (w/o function keyword)'
foo(
__IN__
syntax error: `(' must be followed by `)' in a function definition
__ERR__
#'
#`
#'
#`
# vim: set ft=sh ts=8 sts=4 sw=4 et:
|