Mercurial > vim
view src/testdir/test_system.vim @ 34379:37b4c89ba420 v9.1.0116
patch 9.1.0116: win_split_ins may not check available room
Commit: https://github.com/vim/vim/commit/0fd44a5ad81ade342cb54d8984965bdedd2272c8
Author: Sean Dewar <6256228+seandewar@users.noreply.github.com>
Date: Tue Feb 20 20:28:15 2024 +0100
patch 9.1.0116: win_split_ins may not check available room
Problem: win_split_ins has no check for E36 when moving an existing
window
Solution: check for room and fix the issues in f_win_splitmove()
(Sean Dewar)
win_split_ins has no check for E36 when moving an existing window,
allowing for layouts with many overlapping zero-sized windows to be
created (which may also cause drawing issues with tablines and such).
f_win_splitmove also has some bugs.
So check for room and fix the issues in f_win_splitmove. Handle failure
in the two relevant win_split_ins callers by restoring the original
layout, and factor the common logic into win_splitmove.
Don't check for room when opening an autocommand window, as it's a
temporary window that's rarely interacted with or drawn anyhow, and is
rather important for some autocommands.
Issues fixed in f_win_splitmove:
- Error if splitting is disallowed.
- Fix heap-use-after-frees if autocommands fired from switching to "targetwin"
close "wp" or "oldwin".
- Fix splitting the wrong window if autocommands fired from switching to
"targetwin" switch to a different window.
- Ensure -1 is returned for all errors.
Also handle allocation failure a bit earlier in make_snapshot (callers,
except win_splitmove, don't really care if a snapshot can't be made, so
just ignore the return value).
Note: Test_smoothscroll_in_zero_width_window failed after these changes with
E36, as it was using the previous behaviour to create a zero-width window.
I've fixed the test such that it fails with UBSAN as expected when v9.0.1367 is
reverted (and simplified it too).
related: #14042
Signed-off-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 20 Feb 2024 22:30:04 +0100 |
parents | ae10b91ac6b3 |
children |
line wrap: on
line source
" Tests for system() and systemlist() source shared.vim source check.vim func Test_System() if !has('win32') call assert_equal("123\n", system('echo 123')) call assert_equal(['123'], systemlist('echo 123')) call assert_equal('123', system('cat', '123')) call assert_equal(['123'], systemlist('cat', '123')) call assert_equal(["as\<NL>df"], systemlist('cat', ["as\<NL>df"])) else call assert_equal("123\n", system('echo 123')) call assert_equal(["123\r"], systemlist('echo 123')) call assert_equal("123\n", system('more.com', '123')) call assert_equal(["123\r"], systemlist('more.com', '123')) call assert_equal(["as\r", "df\r"], systemlist('more.com', ["as\<NL>df"])) endif new Xdummy call setline(1, ['asdf', "pw\<NL>er", 'xxxx']) if executable('wc') let out = system('wc -l', bufnr('%')) " On OS/X we get leading spaces let out = substitute(out, '^ *', '', '') call assert_equal("3\n", out) let out = systemlist('wc -l', bufnr('%')) " On Windows we may get a trailing CR. if out != ["3\r"] " On OS/X we get leading spaces if type(out) == v:t_list let out[0] = substitute(out[0], '^ *', '', '') endif call assert_equal(['3'], out) endif endif if !has('win32') let out = systemlist('cat', bufnr('%')) call assert_equal(['asdf', "pw\<NL>er", 'xxxx'], out) else let out = systemlist('more.com', bufnr('%')) call assert_equal(["asdf\r", "pw\r", "er\r", "xxxx\r"], out) endif bwipe! call assert_fails('call system("wc -l", 99999)', 'E86:') endfunc func Test_system_exmode() if has('unix') " echo $? only works on Unix let cmd = ' -es -c "source Xscript" +q; echo "result=$?"' " Need to put this in a script, "catch" isn't found after an unknown " function. call writefile(['try', 'call doesnotexist()', 'catch', 'endtry'], 'Xscript', 'D') let a = system(GetVimCommand() . cmd) call assert_match('result=0', a) call assert_equal(0, v:shell_error) endif " Error before try does set error flag. call writefile(['call nosuchfunction()', 'try', 'call doesnotexist()', 'catch', 'endtry'], 'Xscript') if has('unix') " echo $? only works on Unix let a = system(GetVimCommand() . cmd) call assert_notequal('0', a[0]) endif let cmd = ' -es -c "source Xscript" +q' let a = system(GetVimCommand() . cmd) call assert_notequal(0, v:shell_error) if has('unix') " echo $? only works on Unix let cmd = ' -es -c "call doesnotexist()" +q; echo $?' let a = system(GetVimCommand() . cmd) call assert_notequal(0, a[0]) endif let cmd = ' -es -c "call doesnotexist()" +q' let a = system(GetVimCommand(). cmd) call assert_notequal(0, v:shell_error) if has('unix') " echo $? only works on Unix let cmd = ' -es -c "call doesnotexist()|let a=1" +q; echo $?' let a = system(GetVimCommand() . cmd) call assert_notequal(0, a[0]) endif let cmd = ' -es -c "call doesnotexist()|let a=1" +q' let a = system(GetVimCommand() . cmd) call assert_notequal(0, v:shell_error) endfunc func Test_system_with_shell_quote() CheckMSWindows call mkdir('Xdir with spaces', 'p') call system('copy "%COMSPEC%" "Xdir with spaces\cmd.exe"') let shell_save = &shell let shellxquote_save = &shellxquote try " Set 'shell' always needs noshellslash. let shellslash_save = &shellslash set noshellslash let shell_tests = [ \ expand('$COMSPEC'), \ '"' . fnamemodify('Xdir with spaces\cmd.exe', ':p') . '"', \] let &shellslash = shellslash_save let sxq_tests = ['', '(', '"'] " Matrix tests: 'shell' * 'shellxquote' for shell in shell_tests let &shell = shell for sxq in sxq_tests let &shellxquote = sxq let msg = printf('shell=%s shellxquote=%s', &shell, &shellxquote) try let out = 'echo 123'->system() catch call assert_report(printf('%s: %s', msg, v:exception)) continue endtry " On Windows we may get a trailing space and CR. if out != "123 \n" call assert_equal("123\n", out, msg) endif endfor endfor finally let &shell = shell_save let &shellxquote = shellxquote_save call delete('Xdir with spaces', 'rf') endtry endfunc " vim: shiftwidth=2 sts=2 expandtab