xref: /vim-8.2.3635/src/testdir/check.vim (revision 7929651e)
1source shared.vim
2source term_util.vim
3
4command -nargs=1 MissingFeature throw 'Skipped: ' .. <args> .. ' feature missing'
5
6" Command to check for the presence of a feature.
7command -nargs=1 CheckFeature call CheckFeature(<f-args>)
8func CheckFeature(name)
9  if !has(a:name, 1)
10    throw 'Checking for non-existent feature ' .. a:name
11  endif
12  if !has(a:name)
13    MissingFeature a:name
14  endif
15endfunc
16
17" Command to check for the presence of a working option.
18command -nargs=1 CheckOption call CheckOption(<f-args>)
19func CheckOption(name)
20  if !exists('+' .. a:name)
21    throw 'Skipped: ' .. a:name .. ' option not supported'
22  endif
23endfunc
24
25" Command to check for the presence of a function.
26command -nargs=1 CheckFunction call CheckFunction(<f-args>)
27func CheckFunction(name)
28  if !exists('*' .. a:name)
29    throw 'Skipped: ' .. a:name .. ' function missing'
30  endif
31endfunc
32
33" Command to check for the presence of an Ex command
34command -nargs=1 CheckCommand call CheckCommand(<f-args>)
35func CheckCommand(name)
36  if !exists(':' .. a:name)
37    throw 'Skipped: ' .. a:name .. ' command not supported'
38  endif
39endfunc
40
41" Command to check for the presence of a shell command
42command -nargs=1 CheckExecutable call CheckExecutable(<f-args>)
43func CheckExecutable(name)
44  if !executable(a:name)
45    throw 'Skipped: ' .. a:name .. ' program not executable'
46  endif
47endfunc
48
49" Command to check for running on MS-Windows
50command CheckMSWindows call CheckMSWindows()
51func CheckMSWindows()
52  if !has('win32')
53    throw 'Skipped: only works on MS-Windows'
54  endif
55endfunc
56
57" Command to check for NOT running on MS-Windows
58command CheckNotMSWindows call CheckNotMSWindows()
59func CheckNotMSWindows()
60  if has('win32')
61    throw 'Skipped: does not work on MS-Windows'
62  endif
63endfunc
64
65" Command to check for running on Unix
66command CheckUnix call CheckUnix()
67func CheckUnix()
68  if !has('unix')
69    throw 'Skipped: only works on Unix'
70  endif
71endfunc
72
73" Command to check for not running on a BSD system.
74" TODO: using this checks should not be needed
75command CheckNotBSD call CheckNotBSD()
76func CheckNotBSD()
77  if has('bsd')
78    throw 'Skipped: does not work on BSD'
79  endif
80endfunc
81
82" Command to check that making screendumps is supported.
83" Caller must source screendump.vim
84command CheckScreendump call CheckScreendump()
85func CheckScreendump()
86  if !CanRunVimInTerminal()
87    throw 'Skipped: cannot make screendumps'
88  endif
89endfunc
90
91" Command to check that we can Run Vim in a terminal window
92command CheckRunVimInTerminal call CheckRunVimInTerminal()
93func CheckRunVimInTerminal()
94  if !CanRunVimInTerminal()
95    throw 'Skipped: cannot run Vim in a terminal window'
96  endif
97endfunc
98
99" Command to check that we can run the GUI
100command CheckCanRunGui call CheckCanRunGui()
101func CheckCanRunGui()
102  if !has('gui') || ($DISPLAY == "" && !has('gui_running'))
103    throw 'Skipped: cannot start the GUI'
104  endif
105endfunc
106
107" Command to check that we are using the GUI
108command CheckGui call CheckGui()
109func CheckGui()
110  if !has('gui_running')
111    throw 'Skipped: only works in the GUI'
112  endif
113endfunc
114
115" Command to check that not currently using the GUI
116command CheckNotGui call CheckNotGui()
117func CheckNotGui()
118  if has('gui_running')
119    throw 'Skipped: only works in the terminal'
120  endif
121endfunc
122
123" Command to check that test is not running as root
124command CheckNotRoot call CheckNotRoot()
125func CheckNotRoot()
126  if IsRoot()
127    throw 'Skipped: cannot run test as root'
128  endif
129endfunc
130