changeset 17657:0da9bc55c31a v8.1.1826

patch 8.1.1826: tests use hand coded feature and option checks commit https://github.com/vim/vim/commit/8c5a278fc508da6dfe50e69b6ee734451aa4eafb Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 7 23:07:07 2019 +0200 patch 8.1.1826: tests use hand coded feature and option checks Problem: Tests use hand coded feature and option checks. Solution: Use the commands from check.vim in more tests.
author Bram Moolenaar <Bram@vim.org>
date Wed, 07 Aug 2019 23:15:07 +0200
parents 2adce9da20d8
children 0d763089ba7f
files src/testdir/check.vim src/testdir/shared.vim src/testdir/test_autochdir.vim src/testdir/test_autocmd.vim src/testdir/test_balloon.vim src/testdir/test_breakindent.vim src/testdir/test_bufline.vim src/testdir/test_cdo.vim src/testdir/test_channel.vim src/testdir/test_clientserver.vim src/testdir/test_conceal.vim src/testdir/test_cscope.vim src/testdir/test_debugger.vim src/testdir/test_filechanged.vim src/testdir/test_fold.vim src/testdir/test_functions.vim src/testdir/test_gui.vim src/testdir/test_gui_init.vim src/testdir/test_highlight.vim src/testdir/test_mapping.vim src/testdir/test_match.vim src/testdir/test_memory_usage.vim src/testdir/test_options.vim src/testdir/test_paste.vim src/testdir/test_popup.vim src/testdir/test_search.vim src/testdir/test_signals.vim src/testdir/test_startup.vim src/testdir/test_syntax.vim src/testdir/test_termcodes.vim src/testdir/test_terminal.vim src/testdir/test_timers.vim src/testdir/test_vimscript.vim src/version.c
diffstat 34 files changed, 196 insertions(+), 187 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/check.vim
+++ b/src/testdir/check.vim
@@ -22,6 +22,22 @@ func CheckFunction(name)
   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()
@@ -30,6 +46,14 @@ 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()
@@ -54,3 +78,27 @@ func CheckRunVimInTerminal()
     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
--- a/src/testdir/shared.vim
+++ b/src/testdir/shared.vim
@@ -323,10 +323,6 @@ func RunVimPiped(before, after, argument
   return 1
 endfunc
 
-func CanRunGui()
-  return has('gui') && ($DISPLAY != "" || has('gui_running'))
-endfunc
-
 func WorkingClipboard()
   if !has('clipboard')
     return 0
--- a/src/testdir/test_autochdir.vim
+++ b/src/testdir/test_autochdir.vim
@@ -1,8 +1,7 @@
 " Test 'autochdir' behavior
 
-if !exists("+autochdir")
-  throw 'Skipped: autochdir feature missing'
-endif
+source check.vim
+CheckOption autochdir
 
 func Test_set_filename()
   let cwd = getcwd()
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -1,6 +1,7 @@
 " Tests for autocommands
 
 source shared.vim
+source check.vim
 
 func s:cleanup_buffers() abort
   for bnr in range(1, bufnr('$'))
@@ -1861,9 +1862,9 @@ func Test_TextChangedI_with_setline()
 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})
--- a/src/testdir/test_balloon.vim
+++ b/src/testdir/test_balloon.vim
@@ -1,17 +1,12 @@
 " 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"])
--- a/src/testdir/test_breakindent.vim
+++ b/src/testdir/test_breakindent.vim
@@ -4,9 +4,8 @@
 " 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
 
--- a/src/testdir/test_bufline.vim
+++ b/src/testdir/test_bufline.vim
@@ -2,6 +2,7 @@
 
 source shared.vim
 source screendump.vim
+source check.vim
 
 func Test_setbufline_getbufline()
   new
@@ -147,9 +148,8 @@ func Test_deletebufline()
 endfunc
 
 func Test_appendbufline_redraw()
-  if !CanRunVimInTerminal()
-    throw 'Skipped: cannot make screendumps'
-  endif
+  CheckScreendump
+
   let lines =<< trim END
     new foo
     let winnr=bufwinnr('foo')
--- a/src/testdir/test_cdo.vim
+++ b/src/testdir/test_cdo.vim
@@ -1,8 +1,7 @@
 " 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()
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -855,9 +855,8 @@ func Test_pipe_from_buffer_nr()
 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
@@ -1014,9 +1013,8 @@ func Test_pipe_io_one_buffer()
 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))
@@ -1536,9 +1534,8 @@ func Test_using_freed_memory()
 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
@@ -1550,9 +1547,8 @@ func Test_collapse_buffers()
 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, '$'))})
@@ -1585,9 +1581,7 @@ func Test_cmd_parsing()
 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
--- a/src/testdir/test_clientserver.vim
+++ b/src/testdir/test_clientserver.vim
@@ -1,8 +1,8 @@
 " 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
 
--- a/src/testdir/test_conceal.vim
+++ b/src/testdir/test_conceal.vim
@@ -1,14 +1,11 @@
 " 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]
--- a/src/testdir/test_cscope.vim
+++ b/src/testdir/test_cscope.vim
@@ -3,10 +3,7 @@
 source check.vim
 CheckFeature cscope
 CheckFeature quickfix
-
-if !executable('cscope')
-  throw 'Skipped: cscope program missing'
-endif
+CheckExecutable cscope
 
 func CscopeSetupOrClean(setup)
     if a:setup
--- a/src/testdir/test_debugger.vim
+++ b/src/testdir/test_debugger.vim
@@ -2,6 +2,7 @@
 
 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.
@@ -21,9 +22,7 @@ endfunc
 
 " 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
--- a/src/testdir/test_filechanged.vim
+++ b/src/testdir/test_filechanged.vim
@@ -1,9 +1,10 @@
 " 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
@@ -91,9 +92,8 @@ func Test_FileChangedShell_reload()
 endfunc
 
 func Test_file_changed_dialog()
-  if !has('unix') || has('gui_running')
-    return
-  endif
+  CheckUnix
+  CheckNotGui
   au! FileChangedShell
 
   new Xchanged_d
--- a/src/testdir/test_fold.vim
+++ b/src/testdir/test_fold.vim
@@ -1,5 +1,6 @@
 " Test for folding
 
+source check.vim
 source view_util.vim
 source screendump.vim
 
@@ -707,9 +708,7 @@ func Test_fold_last_line_with_pagedown()
 endfunc
 
 func Test_folds_with_rnu()
-  if !CanRunVimInTerminal()
-    throw 'Skipped: cannot make screendumps'
-  endif
+  CheckScreendump
 
   call writefile([
 	\ 'set fdm=marker rnu foldcolumn=2',
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -1,5 +1,6 @@
 " 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()
@@ -1376,9 +1377,8 @@ endfunc
 
 " 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')
--- a/src/testdir/test_gui.vim
+++ b/src/testdir/test_gui.vim
@@ -1,9 +1,8 @@
 " Tests specifically for the GUI
 
 source shared.vim
-if !CanRunGui()
-  throw 'Skipped: cannot run GUI'
-endif
+source check.vim
+CheckCanRunGui
 
 source setup_gui.vim
 
--- a/src/testdir/test_gui_init.vim
+++ b/src/testdir/test_gui_init.vim
@@ -2,9 +2,8 @@
 " 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
 
--- a/src/testdir/test_highlight.vim
+++ b/src/testdir/test_highlight.vim
@@ -2,6 +2,7 @@
 
 source view_util.vim
 source screendump.vim
+source check.vim
 
 func Test_highlight()
   " basic test if ":highlight" doesn't crash
@@ -532,9 +533,7 @@ func Test_termguicolors()
 endfunc
 
 func Test_cursorline_after_yank()
-  if !CanRunVimInTerminal()
-    throw 'Skipped: cannot make screendumps'
-  endif
+  CheckScreendump
 
   call writefile([
 	\ 'set cul rnu',
@@ -554,9 +553,7 @@ func Test_cursorline_after_yank()
 endfunc
 
 func Test_cursorline_with_visualmode()
-  if !CanRunVimInTerminal()
-    throw 'Skipped: cannot make screendumps'
-  endif
+  CheckScreendump
 
   call writefile([
 	\ 'set cul',
@@ -574,9 +571,7 @@ func Test_cursorline_with_visualmode()
 endfunc
 
 func Test_wincolor()
-  if !CanRunVimInTerminal()
-    throw 'Skipped: cannot make screendumps'
-  endif
+  CheckScreendump
 
   let lines =<< trim END
 	set cursorline cursorcolumn rnu
--- a/src/testdir/test_mapping.vim
+++ b/src/testdir/test_mapping.vim
@@ -1,6 +1,7 @@
 " Tests for mappings and abbreviations
 
 source shared.vim
+source check.vim
 
 func Test_abbreviation()
   " abbreviation with 0x80 should work
@@ -399,7 +400,9 @@ func Test_motionforce_omap()
 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
 
--- a/src/testdir/test_match.vim
+++ b/src/testdir/test_match.vim
@@ -2,6 +2,7 @@
 " matchaddpos(), matcharg(), matchdelete(), and setmatches().
 
 source screendump.vim
+source check.vim
 
 function Test_match()
   highlight MyGroup1 term=bold ctermbg=red guibg=red
@@ -267,9 +268,8 @@ func OtherWindowCommon()
 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', {})
--- a/src/testdir/test_memory_usage.vim
+++ b/src/testdir/test_memory_usage.vim
@@ -2,10 +2,8 @@
 
 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.
--- a/src/testdir/test_options.vim
+++ b/src/testdir/test_options.vim
@@ -1,5 +1,7 @@
 " Test for options
 
+source check.vim
+
 func Test_whichwrap()
   set whichwrap=b,s
   call assert_equal('b,s', &whichwrap)
@@ -296,9 +298,8 @@ endfunc
 
 " 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)
 
@@ -310,34 +311,35 @@ func Test_000_term_option_verbose()
 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
+  CheckUnix
+  CheckNotGui
 
-    " 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
+  " 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
 
-    set ttytype&
-    call assert_equal(&ttytype, &term)
-  endif
+  " 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()
--- a/src/testdir/test_paste.vim
+++ b/src/testdir/test_paste.vim
@@ -1,12 +1,10 @@
 " 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
--- a/src/testdir/test_popup.vim
+++ b/src/testdir/test_popup.vim
@@ -2,6 +2,7 @@
 
 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 = ''
@@ -663,9 +664,9 @@ func Test_complete_CTRLN_startofbuffer()
 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
@@ -918,9 +919,9 @@ func Test_complete_o_tab()
 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
--- a/src/testdir/test_search.vim
+++ b/src/testdir/test_search.vim
@@ -2,6 +2,7 @@
 
 source shared.vim
 source screendump.vim
+source check.vim
 
 func Test_search_cmdline()
   if !exists('+incsearch')
@@ -575,12 +576,13 @@ endfunc
 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
@@ -702,9 +704,10 @@ func Test_search_cmdline_incsearch_highl
 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
--- a/src/testdir/test_signals.vim
+++ b/src/testdir/test_signals.vim
@@ -1,8 +1,7 @@
 " Test signal handling.
 
-if !has('unix')
-  throw 'Skipped: not on Unix'
-endif
+source check.vim
+CheckUnix
 
 source shared.vim
 
@@ -14,8 +13,9 @@ endfunc
 
 " 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.
--- a/src/testdir/test_startup.vim
+++ b/src/testdir/test_startup.vim
@@ -2,6 +2,7 @@
 
 source shared.vim
 source screendump.vim
+source check.vim
 
 " Check that loading startup.vim works.
 func Test_startup_script()
@@ -262,10 +263,9 @@ endfunc
 
 " 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)
 
@@ -395,10 +395,9 @@ func Test_A_F_H_arg()
 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")
@@ -599,10 +598,9 @@ func Test_progpath()
 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')
@@ -610,10 +608,9 @@ func Test_silent_ex_mode()
 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'
@@ -649,10 +646,9 @@ func Test_zzz_startinsert()
 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)
--- a/src/testdir/test_syntax.vim
+++ b/src/testdir/test_syntax.vim
@@ -413,9 +413,8 @@ func Test_highlight_invalid_arg()
 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
--- a/src/testdir/test_termcodes.vim
+++ b/src/testdir/test_termcodes.vim
@@ -1,12 +1,9 @@
 " 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
 
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -1788,9 +1788,7 @@ endfunc
 
 " 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:')
@@ -1810,9 +1808,7 @@ func Test_zz1_terminal_in_gui()
 endfunc
 
 func Test_zz2_terminal_guioptions_bang()
-  if !has('gui_running')
-    return
-  endif
+  CheckGui
   set guioptions+=!
 
   let filename = 'Xtestscript'
--- a/src/testdir/test_timers.vim
+++ b/src/testdir/test_timers.vim
@@ -239,9 +239,9 @@ func Interrupt(timer)
 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()
@@ -251,8 +251,7 @@ endfunc
 
 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.
--- a/src/testdir/test_vimscript.vim
+++ b/src/testdir/test_vimscript.vim
@@ -1,6 +1,8 @@
 " Test various aspects of the Vim script language.
 " Most of this was formerly in test49.
 
+source check.vim
+
 "-------------------------------------------------------------------------------
 " Test environment							    {{{1
 "-------------------------------------------------------------------------------
@@ -1677,10 +1679,7 @@ func Test_funccall_garbage_collect()
 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
--- a/src/version.c
+++ b/src/version.c
@@ -770,6 +770,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1826,
+/**/
     1825,
 /**/
     1824,