summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_buffer.vim
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2022-04-02 21:46:19 +0100
committerBram Moolenaar <Bram@vim.org>2022-04-02 21:46:19 +0100
commit0dac1ab5791819ee9a496273eea38f69a217ac45 (patch)
treea2bb44a0706e1a71b70115646ea6864e142468fa /src/testdir/test_buffer.vim
parent5018a836c030988944a9bbe2fd2e538bf5261a72 (diff)
patch 8.2.4668: buffer allocation failures insufficiently testedv8.2.4668
Problem: Buffer allocation failures insufficiently tested. Solution: Add tests for memory allocation failures. (Yegappan Lakshmanan, closes #10064)
Diffstat (limited to 'src/testdir/test_buffer.vim')
-rw-r--r--src/testdir/test_buffer.vim70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/testdir/test_buffer.vim b/src/testdir/test_buffer.vim
index 0d871383fa..fd96c618c0 100644
--- a/src/testdir/test_buffer.vim
+++ b/src/testdir/test_buffer.vim
@@ -430,4 +430,74 @@ func Test_buffer_maxmem()
set maxmem& maxmemtot&
endfunc
+" Test for a allocation failure when adding a new buffer
+func Test_buflist_alloc_failure()
+ %bw!
+
+ edit Xfile1
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('edit Xfile2', 'E342:')
+
+ " test for bufadd()
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('call bufadd("Xbuffer")', 'E342:')
+
+ " test for setting the arglist
+ edit Xfile2
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('next Xfile3', 'E342:')
+
+ " test for setting the alternate buffer name when writing a file
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('write Xother', 'E342:')
+ call delete('Xother')
+
+ " test for creating a buffer using bufnr()
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails("call bufnr('Xnewbuf', v:true)", 'E342:')
+
+ " test for renaming buffer using :file
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('file Xnewfile', 'E342:')
+
+ " test for creating a buffer for a popup window
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('call popup_create("mypop", {})', 'E342:')
+
+ if has('terminal')
+ " test for creating a buffer for a terminal window
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('call term_start(&shell)', 'E342:')
+ %bw!
+ endif
+
+ " test for loading a new buffer after wiping out all the buffers
+ edit Xfile4
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('%bw!', 'E342:')
+
+ " test for :checktime loading the buffer
+ call writefile(['one'], 'Xfile5')
+ if has('unix')
+ edit Xfile5
+ " sleep for some time to make sure the timestamp is different
+ sleep 200m
+ call writefile(['two'], 'Xfile5')
+ set autoread
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('checktime', 'E342:')
+ set autoread&
+ bw!
+ endif
+
+ " test for :vimgrep loading a dummy buffer
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('vimgrep two Xfile5', 'E342:')
+ call delete('Xfile5')
+
+ " test for quickfix command loading a buffer
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('cexpr "Xfile6:10:Line10"', 'E342:')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab