patch 8.2.4716: memory allocation failure not tested when defining a function
Problem: Memory allocation failure not tested when defining a function.
Solution: Add a test. (Yegappan Lakshmanan, closes #10127)
diff --git a/src/testdir/test_user_func.vim b/src/testdir/test_user_func.vim
index 6eb8a0f..f6e25e3 100644
--- a/src/testdir/test_user_func.vim
+++ b/src/testdir/test_user_func.vim
@@ -499,4 +499,34 @@
bwipe!
endfunc
+" Test for memory allocation failure when defining a new function
+func Test_funcdef_alloc_failure()
+ new
+ let lines =<< trim END
+ func Xtestfunc()
+ return 321
+ endfunc
+ END
+ call setline(1, lines)
+ call test_alloc_fail(GetAllocId('get_func'), 0, 0)
+ call assert_fails('source', 'E342:')
+ call assert_false(exists('*Xtestfunc'))
+ call assert_fails('delfunc Xtestfunc', 'E117:')
+ %d _
+ let lines =<< trim END
+ def g:Xvim9func(): number
+ return 456
+ enddef
+ END
+ call setline(1, lines)
+ call test_alloc_fail(GetAllocId('get_func'), 0, 0)
+ call assert_fails('source', 'E342:')
+ call assert_false(exists('*Xvim9func'))
+ "call test_alloc_fail(GetAllocId('get_func'), 0, 0)
+ "call assert_fails('source', 'E342:')
+ "call assert_false(exists('*Xtestfunc'))
+ "call assert_fails('delfunc Xtestfunc', 'E117:')
+ bw!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 06168e4..9287ed5 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -4071,6 +4071,22 @@
v9.CheckScriptFailure(lines, 'E476:')
enddef
+" Test for memory allocation failure when defining a new lambda
+func Test_lambda_allocation_failure()
+ new
+ let lines =<< trim END
+ vim9script
+ g:Xlambda = (x): number => {
+ return x + 1
+ }
+ END
+ call setline(1, lines)
+ call test_alloc_fail(GetAllocId('get_func'), 0, 0)
+ call assert_fails('source', 'E342:')
+ call assert_false(exists('g:Xlambda'))
+ bw!
+endfunc
+
" The following messes up syntax highlight, keep near the end.
if has('python3')
def Test_python3_command()