Mercurial > vim
diff src/testdir/test_mapping.vim @ 17184:a5c3d374e1d3 v8.1.1591
patch 8.1.1591: on error garbage collection may free memory in use
commit https://github.com/vim/vim/commit/7d491c425334d9477637372a4ebec64c228c8430
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jun 25 06:28:02 2019 +0200
patch 8.1.1591: on error garbage collection may free memory in use
Problem: On error garbage collection may free memory in use.
Solution: Reset may_garbage_collect when evaluating expression mapping.
Add tests. (Ozaki Kiichi, closes #4579)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 25 Jun 2019 06:30:09 +0200 |
parents | fb7cf38a1c7a |
children | fceb0977275a |
line wrap: on
line diff
--- a/src/testdir/test_mapping.vim +++ b/src/testdir/test_mapping.vim @@ -397,3 +397,39 @@ func Test_motionforce_omap() delfunc Select delfunc GetCommand endfunc + +func Test_error_in_map_expr() + if !has('terminal') || (has('win32') && has('gui_running')) + throw 'Skipped: cannot run Vim in a terminal window' + endif + + let lines =<< trim [CODE] + func Func() + " fail to create list + let x = [ + endfunc + nmap <expr> ! Func() + set updatetime=50 + [CODE] + call writefile(lines, 'Xtest.vim') + + let buf = term_start(GetVimCommandClean() .. ' -S Xtest.vim', {'term_rows': 8}) + let job = term_getjob(buf) + call WaitForAssert({-> assert_notequal('', term_getline(buf, 8))}) + + " GC must not run during map-expr processing, which can make Vim crash. + call term_sendkeys(buf, '!') + call term_wait(buf, 100) + call term_sendkeys(buf, "\<CR>") + call term_wait(buf, 100) + call assert_equal('run', job_status(job)) + + call term_sendkeys(buf, ":qall!\<CR>") + call WaitFor({-> job_status(job) ==# 'dead'}) + if has('unix') + call assert_equal('', job_info(job).termsig) + endif + + call delete('Xtest.vim') + exe buf .. 'bwipe!' +endfunc