Problem: Tests use hand coded feature and option checks.
Solution: Use the commands from check.vim in more tests.
endif
endfunc
+" Command to check for the presence of an Ex command
+command -nargs=1 CheckCommand call CheckCommand(<f-args>)
+func CheckCommand(name)
+ if !exists(':' .. a:name)
+ throw 'Skipped: ' .. a:name .. ' command not supported'
+ endif
+endfunc
+
+" Command to check for the presence of a shell command
+command -nargs=1 CheckExecutable call CheckExecutable(<f-args>)
+func CheckExecutable(name)
+ if !executable(a:name)
+ throw 'Skipped: ' .. a:name .. ' program not executable'
+ endif
+endfunc
+
" Command to check for running on MS-Windows
command CheckMSWindows call CheckMSWindows()
func CheckMSWindows()
endif
endfunc
+" Command to check for NOT running on MS-Windows
+command CheckNotMSWindows call CheckNotMSWindows()
+func CheckNotMSWindows()
+ if has('win32')
+ throw 'Skipped: does not work on MS-Windows'
+ endif
+endfunc
+
" Command to check for running on Unix
command CheckUnix call CheckUnix()
func CheckUnix()
throw 'Skipped: cannot run Vim in a terminal window'
endif
endfunc
+
+" Command to check that we can run the GUI
+command CheckCanRunGui call CheckCanRunGui()
+func CheckCanRunGui()
+ if !has('gui') || ($DISPLAY == "" && !has('gui_running'))
+ throw 'Skipped: cannot run start the GUI'
+ endif
+endfunc
+
+" Command to check that we are using the GUI
+command CheckGui call CheckGui()
+func CheckGui()
+ if !has('gui_running')
+ throw 'Skipped: only works in the GUI'
+ endif
+endfunc
+
+" Command to check that not currently using the GUI
+command CheckNotGui call CheckNotGui()
+func CheckNotGui()
+ if has('gui_running')
+ throw 'Skipped: only works in the terminal'
+ endif
+endfunc
return 1
endfunc
-func CanRunGui()
- return has('gui') && ($DISPLAY != "" || has('gui_running'))
-endfunc
-
func WorkingClipboard()
if !has('clipboard')
return 0
" Test 'autochdir' behavior
-if !exists("+autochdir")
- throw 'Skipped: autochdir feature missing'
-endif
+source check.vim
+CheckOption autochdir
func Test_set_filename()
let cwd = getcwd()
" Tests for autocommands
source shared.vim
+source check.vim
func s:cleanup_buffers() abort
for bnr in range(1, bufnr('$'))
endfunc
func Test_Changed_FirstTime()
- if !has('terminal') || has('gui_running')
- return
- endif
+ CheckFeature terminal
+ CheckNotGui
+
" Prepare file for TextChanged event.
call writefile([''], 'Xchanged.txt')
let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': 3})
" Tests for 'balloonevalterm'.
" A few tests only work in the terminal.
-if has('gui_running')
- throw 'Skipped: only work in the terminal'
-endif
-
source check.vim
+CheckNotGui
CheckFeature balloon_eval_term
source screendump.vim
-if !CanRunVimInTerminal()
- throw 'Skipped: cannot make screendumps'
-endif
+CheckScreendump
let s:common_script =<< trim [CODE]
call setline(1, ["one one one", "two tXo two", "three three three"])
" while the test is run, the breakindent cacheing gets in its way.
" It helps to change the tabstop setting and force a redraw (e.g. see
" Test_breakindent08())
-if !exists('+breakindent')
- throw 'Skipped: breakindent option not supported'
-endif
+source check.vim
+CheckOption breakindent
source view_util.vim
source shared.vim
source screendump.vim
+source check.vim
func Test_setbufline_getbufline()
new
endfunc
func Test_appendbufline_redraw()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot make screendumps'
- endif
+ CheckScreendump
+
let lines =<< trim END
new foo
let winnr=bufwinnr('foo')
" Tests for the :cdo, :cfdo, :ldo and :lfdo commands
-if !has('quickfix')
- throw 'Skipped: quickfix feature missing'
-endif
+source check.vim
+CheckFeature quickfix
" Create the files used by the tests
function SetUp()
endfunc
func Run_pipe_through_sort(all, use_buffer)
- if !executable('sort')
- throw 'Skipped: sort program not found'
- endif
+ CheckExecutable sort
+
let options = {'out_io': 'buffer', 'out_name': 'sortout'}
if a:use_buffer
split sortin
endfunc
func Test_write_to_buffer_and_scroll()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot make screendumps'
- endif
+ CheckScreendump
+
let lines =<< trim END
new Xscrollbuffer
call setline(1, range(1, 200))
endfunc
func Test_collapse_buffers()
- if !executable('cat')
- throw 'Skipped: cat program not found'
- endif
+ CheckExecutable cat
+
sp test_channel.vim
let g:linecount = line('$')
close
endfunc
func Test_write_to_deleted_buffer()
- if !executable('echo')
- throw 'Skipped: echo program not found'
- endif
+ CheckExecutable echo
+
let job = job_start('echo hello', {'out_io': 'buffer', 'out_name': 'test_buffer', 'out_msg': 0})
let bufnr = bufnr('test_buffer')
call WaitForAssert({-> assert_equal(['hello'], getbufline(bufnr, 1, '$'))})
endfunc
func Test_raw_passes_nul()
- if !executable('cat')
- throw 'Skipped: cat program not found'
- endif
+ CheckExecutable cat
" Test lines from the job containing NUL are stored correctly in a buffer.
new
" Tests for the +clientserver feature.
-if !has('job') || !has('clientserver')
- throw 'Skipped: job and/or clientserver feature missing'
-endif
+source check.vim
+CheckFeature job
+CheckFeature clientserver
source shared.vim
" Tests for 'conceal'.
" Also see test88.in (should be converted to a test function here).
-if !has('conceal')
- throw 'Skipped: conceal feature missing'
-endif
+source check.vim
+CheckFeature conceal
source screendump.vim
-if !CanRunVimInTerminal()
- throw 'Skipped: cannot make screendumps'
-endif
+CheckScreendump
func Test_conceal_two_windows()
let code =<< trim [CODE]
source check.vim
CheckFeature cscope
CheckFeature quickfix
-
-if !executable('cscope')
- throw 'Skipped: cscope program missing'
-endif
+CheckExecutable cscope
func CscopeSetupOrClean(setup)
if a:setup
source shared.vim
source screendump.vim
+source check.vim
" Run a Vim debugger command
" If the expected output argument is supplied, then check for it.
" Debugger tests
func Test_Debugger()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
" Create a Vim script with some functions
let lines =<< trim END
" Tests for when a file was changed outside of Vim.
+source check.vim
+
func Test_FileChangedShell_reload()
- if !has('unix')
- return
- endif
+ CheckUnix
+
augroup testreload
au FileChangedShell Xchanged_r let g:reason = v:fcs_reason | let v:fcs_choice = 'reload'
augroup END
endfunc
func Test_file_changed_dialog()
- if !has('unix') || has('gui_running')
- return
- endif
+ CheckUnix
+ CheckNotGui
au! FileChangedShell
new Xchanged_d
" Test for folding
+source check.vim
source view_util.vim
source screendump.vim
endfunc
func Test_folds_with_rnu()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot make screendumps'
- endif
+ CheckScreendump
call writefile([
\ 'set fdm=marker rnu foldcolumn=2',
" Tests for various functions.
source shared.vim
+source check.vim
" Must be done first, since the alternate buffer must be unset.
func Test_00_bufexists()
" Test confirm({msg} [, {choices} [, {default} [, {type}]]])
func Test_confirm()
- if !has('unix') || has('gui_running')
- return
- endif
+ CheckUnix
+ CheckNotGui
call feedkeys('o', 'L')
let a = confirm('Press O to proceed')
" Tests specifically for the GUI
source shared.vim
-if !CanRunGui()
- throw 'Skipped: cannot run GUI'
-endif
+source check.vim
+CheckCanRunGui
source setup_gui.vim
" startup to take effect at runtime.
source shared.vim
-if !CanRunGui()
- throw 'Skipped: cannot run GUI'
-endif
+source check.vim
+CheckCanRunGui
source setup_gui.vim
source view_util.vim
source screendump.vim
+source check.vim
func Test_highlight()
" basic test if ":highlight" doesn't crash
endfunc
func Test_cursorline_after_yank()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot make screendumps'
- endif
+ CheckScreendump
call writefile([
\ 'set cul rnu',
endfunc
func Test_cursorline_with_visualmode()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot make screendumps'
- endif
+ CheckScreendump
call writefile([
\ 'set cul',
endfunc
func Test_wincolor()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot make screendumps'
- endif
+ CheckScreendump
let lines =<< trim END
set cursorline cursorcolumn rnu
" Tests for mappings and abbreviations
source shared.vim
+source check.vim
func Test_abbreviation()
" abbreviation with 0x80 should work
endfunc
func Test_error_in_map_expr()
- if !has('terminal') || (has('win32') && has('gui_running'))
+ " Unlike CheckRunVimInTerminal this does work in a win32 console
+ CheckFeature terminal
+ if has('win32') && has('gui_running')
throw 'Skipped: cannot run Vim in a terminal window'
endif
" matchaddpos(), matcharg(), matchdelete(), and setmatches().
source screendump.vim
+source check.vim
function Test_match()
highlight MyGroup1 term=bold ctermbg=red guibg=red
endfunc
func Test_matchdelete_other_window()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot make screendumps'
- endif
+ CheckScreendump
+
let buf = OtherWindowCommon()
call term_sendkeys(buf, ":call matchdelete(mid, winid)\<CR>")
call VerifyScreenDump(buf, 'Test_matchdelete_1', {})
source check.vim
CheckFeature terminal
+CheckNotGui
-if has('gui_running')
- throw 'Skipped: does not work in GUI'
-endif
if execute('version') =~# '-fsanitize=[a-z,]*\<address\>'
" Skip tests on Travis CI ASAN build because it's difficult to estimate
" memory usage.
" Test for options
+source check.vim
+
func Test_whichwrap()
set whichwrap=b,s
call assert_equal('b,s', &whichwrap)
" Must be executed before other tests that set 'term'.
func Test_000_term_option_verbose()
- if has('gui_running')
- return
- endif
+ CheckNotGui
+
let verb_cm = execute('verbose set t_cm')
call assert_notmatch('Last set from', verb_cm)
endfunc
func Test_set_ttytype()
- if !has('gui_running') && has('unix')
- " Setting 'ttytype' used to cause a double-free when exiting vim and
- " when vim is compiled with -DEXITFREE.
- set ttytype=ansi
- call assert_equal('ansi', &ttytype)
- call assert_equal(&ttytype, &term)
- set ttytype=xterm
- call assert_equal('xterm', &ttytype)
- call assert_equal(&ttytype, &term)
- " "set ttytype=" gives E522 instead of E529
- " in travis on some builds. Why? Catch both for now
- try
- set ttytype=
- call assert_report('set ttytype= did not fail')
- catch /E529\|E522/
- endtry
-
- " Some systems accept any terminal name and return dumb settings,
- " check for failure of finding the entry and for missing 'cm' entry.
- try
- set ttytype=xxx
- call assert_report('set ttytype=xxx did not fail')
- catch /E522\|E437/
- endtry
-
- set ttytype&
- call assert_equal(&ttytype, &term)
- endif
+ CheckUnix
+ CheckNotGui
+
+ " Setting 'ttytype' used to cause a double-free when exiting vim and
+ " when vim is compiled with -DEXITFREE.
+ set ttytype=ansi
+ call assert_equal('ansi', &ttytype)
+ call assert_equal(&ttytype, &term)
+ set ttytype=xterm
+ call assert_equal('xterm', &ttytype)
+ call assert_equal(&ttytype, &term)
+ " "set ttytype=" gives E522 instead of E529
+ " in travis on some builds. Why? Catch both for now
+ try
+ set ttytype=
+ call assert_report('set ttytype= did not fail')
+ catch /E529\|E522/
+ endtry
+
+ " Some systems accept any terminal name and return dumb settings,
+ " check for failure of finding the entry and for missing 'cm' entry.
+ try
+ set ttytype=xxx
+ call assert_report('set ttytype=xxx did not fail')
+ catch /E522\|E437/
+ endtry
+
+ set ttytype&
+ call assert_equal(&ttytype, &term)
endfunc
func Test_set_all()
" Tests for bracketed paste and other forms of pasting.
" Bracketed paste only works with "xterm". Not in GUI or Windows console.
-if has('win32')
- throw 'Skipped: does not work on MS-Windows'
-endif
-if has('gui_running')
- throw 'Skipped: does not work in the GUI'
-endif
+source check.vim
+CheckNotMSWindows
+CheckNotGui
+
set term=xterm
source shared.vim
source shared.vim
source screendump.vim
+source check.vim
let g:months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
let g:setting = ''
endfunc
func Test_popup_and_window_resize()
- if !has('terminal') || has('gui_running')
- return
- endif
+ CheckFeature terminal
+ CheckNotGui
+
let h = winheight(0)
if h < 15
return
endfunc
func Test_menu_only_exists_in_terminal()
- if !exists(':tlmenu') || has('gui_running')
- return
- endif
+ CheckCommand tlmenu
+ CheckNotGui
+
tlnoremenu &Edit.&Paste<Tab>"+gP <C-W>"+
aunmenu *
try
source shared.vim
source screendump.vim
+source check.vim
func Test_search_cmdline()
if !exists('+incsearch')
func Test_search_cmdline8()
" Highlighting is cleared in all windows
" since hls applies to all windows
- if !exists('+incsearch') || !has('terminal') || has('gui_running') || winwidth(0) < 30
- return
- endif
+ CheckOption incsearch
+ CheckFeature terminal
+ CheckNotGui
if has("win32")
throw "Skipped: Bug with sending <ESC> to terminal window not fixed yet"
endif
+
let h = winheight(0)
if h < 3
return
endfunc
func Test_search_cmdline_incsearch_highlight_attr()
- if !exists('+incsearch') || !has('terminal') || has('gui_running')
- return
- endif
+ CheckOption incsearch
+ CheckFeature terminal
+ CheckNotGui
+
let h = winheight(0)
if h < 3
return
" Test signal handling.
-if !has('unix')
- throw 'Skipped: not on Unix'
-endif
+source check.vim
+CheckUnix
source shared.vim
" Test signal WINCH (window resize signal)
func Test_signal_WINCH()
- if has('gui_running') || !HasSignal('WINCH')
- return
+ CheckNotGui
+ if !HasSignal('WINCH')
+ throw 'Skipped: WINCH signal not supported'
endif
" We do not actually want to change the size of the terminal.
source shared.vim
source screendump.vim
+source check.vim
" Check that loading startup.vim works.
func Test_startup_script()
" Test the -V[N] argument to set the 'verbose' option to [N]
func Test_V_arg()
- if has('gui_running')
- " Can't catch the output of gvim.
- return
- endif
+ " Can't catch the output of gvim.
+ CheckNotGui
+
let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq')
call assert_equal(" verbose=0\n", out)
endfunc
func Test_invalid_args()
- if !has('unix') || has('gui_running')
- " can't get output of Vim.
- return
- endif
+ " must be able to get the output of Vim.
+ CheckUnix
+ CheckNotGui
for opt in ['-Y', '--does-not-exist']
let out = split(system(GetVimCommand() .. ' ' .. opt), "\n")
endfunc
func Test_silent_ex_mode()
- if !has('unix') || has('gui_running')
- " can't get output of Vim.
- return
- endif
+ " must be able to get the output of Vim.
+ CheckUnix
+ CheckNotGui
" This caused an ml_get error.
let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq')
endfunc
func Test_default_term()
- if !has('unix') || has('gui_running')
- " can't get output of Vim.
- return
- endif
+ " must be able to get the output of Vim.
+ CheckUnix
+ CheckNotGui
let save_term = $TERM
let $TERM = 'unknownxxx'
endfunc
func Test_issue_3969()
- if has('gui_running')
- " Can't catch the output of gvim.
- return
- endif
+ " Can't catch the output of gvim.
+ CheckNotGui
+
" Check that message is not truncated.
let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq')
call assert_equal('hello', out)
endfunc
func Test_bg_detection()
- if has('gui_running')
- return
- endif
+ CheckNotGui
+
" auto-detection of &bg, make sure sure it isn't set anywhere before
" this test
hi Normal ctermbg=0
" Tests for decoding escape sequences sent by the terminal.
" This only works for Unix in a terminal
-if has('gui_running')
- throw 'Skipped: does not work in the GUI'
-endif
-if !has('unix')
- throw 'Skipped: not on Unix'
-endif
+source check.vim
+CheckNotGui
+CheckUnix
source shared.vim
" must be nearly the last, we can't go back from GUI to terminal
func Test_zz1_terminal_in_gui()
- if !CanRunGui()
- return
- endif
+ CheckCanRunGui
" Ignore the "failed to create input context" error.
call test_ignore_error('E285:')
endfunc
func Test_zz2_terminal_guioptions_bang()
- if !has('gui_running')
- return
- endif
+ CheckGui
set guioptions+=!
let filename = 'Xtestscript'
endfunc
func Test_peek_and_get_char()
- if !has('unix') && !has('gui_running')
- return
- endif
+ CheckUnix
+ CheckGui
+
call timer_start(0, 'FeedAndPeek')
let intr = timer_start(100, 'Interrupt')
let c = getchar()
func Test_getchar_zero()
if has('win32') && !has('gui_running')
- " Console: no low-level input
- return
+ throw 'Skipped: cannot get low-level input'
endif
" Measure the elapsed time to avoid a hang when it fails.
" Test various aspects of the Vim script language.
" Most of this was formerly in test49.
+source check.vim
+
"-------------------------------------------------------------------------------
" Test environment {{{1
"-------------------------------------------------------------------------------
endfunc
func Test_function_defined_line()
- if has('gui_running')
- " Can't catch the output of gvim.
- return
- endif
+ CheckNotGui
let lines =<< trim [CODE]
" F1
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1826,
/**/
1825,
/**/