blob: e67d39ad22df6a7e0eecaf59c7dcebe7496e99a3 [file] [log] [blame]
Bram Moolenaar07282f02019-10-10 16:46:17 +02001source shared.vim
Bram Moolenaar3180fe62020-02-02 13:47:06 +01002source term_util.vim
Bram Moolenaar07282f02019-10-10 16:46:17 +02003
Bram Moolenaar7f829ca2020-01-31 22:12:41 +01004command -nargs=1 MissingFeature throw 'Skipped: ' .. <args> .. ' feature missing'
5
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02006" Command to check for the presence of a feature.
7command -nargs=1 CheckFeature call CheckFeature(<f-args>)
8func CheckFeature(name)
Bram Moolenaar79296512020-03-22 16:17:14 +01009 if !has(a:name, 1)
10 throw 'Checking for non-existent feature ' .. a:name
11 endif
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020012 if !has(a:name)
Bram Moolenaar7f829ca2020-01-31 22:12:41 +010013 MissingFeature a:name
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020014 endif
15endfunc
16
Bram Moolenaarfb773a32021-07-03 21:37:59 +020017" Command to check for the absence of a feature.
18command -nargs=1 CheckNotFeature call CheckNotFeature(<f-args>)
19func CheckNotFeature(name)
20 if !has(a:name, 1)
21 throw 'Checking for non-existent feature ' .. a:name
22 endif
23 if has(a:name)
24 throw 'Skipped: ' .. a:name .. ' feature present'
25 endif
26endfunc
27
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020028" Command to check for the presence of a working option.
29command -nargs=1 CheckOption call CheckOption(<f-args>)
30func CheckOption(name)
Bram Moolenaarc5a8fdc2020-03-22 20:13:39 +010031 if !exists('&' .. a:name)
32 throw 'Checking for non-existent option ' .. a:name
33 endif
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020034 if !exists('+' .. a:name)
35 throw 'Skipped: ' .. a:name .. ' option not supported'
36 endif
37endfunc
38
Bram Moolenaar15c47602020-03-26 22:16:48 +010039" Command to check for the presence of a built-in function.
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020040command -nargs=1 CheckFunction call CheckFunction(<f-args>)
41func CheckFunction(name)
Bram Moolenaar15c47602020-03-26 22:16:48 +010042 if !exists('?' .. a:name)
43 throw 'Checking for non-existent function ' .. a:name
44 endif
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020045 if !exists('*' .. a:name)
46 throw 'Skipped: ' .. a:name .. ' function missing'
47 endif
48endfunc
Bram Moolenaar4641a122019-07-29 22:10:23 +020049
Bram Moolenaar8c5a2782019-08-07 23:07:07 +020050" Command to check for the presence of an Ex command
51command -nargs=1 CheckCommand call CheckCommand(<f-args>)
52func CheckCommand(name)
53 if !exists(':' .. a:name)
54 throw 'Skipped: ' .. a:name .. ' command not supported'
55 endif
56endfunc
57
58" Command to check for the presence of a shell command
59command -nargs=1 CheckExecutable call CheckExecutable(<f-args>)
60func CheckExecutable(name)
61 if !executable(a:name)
62 throw 'Skipped: ' .. a:name .. ' program not executable'
63 endif
64endfunc
65
Bram Moolenaara161cb52020-04-30 19:09:35 +020066" Command to check for the presence of python. Argument should have been
67" obtained with PythonProg()
68func CheckPython(name)
69 if a:name == ''
70 throw 'Skipped: python command not available'
71 endif
72endfunc
73
Bram Moolenaar4641a122019-07-29 22:10:23 +020074" Command to check for running on MS-Windows
75command CheckMSWindows call CheckMSWindows()
76func CheckMSWindows()
77 if !has('win32')
78 throw 'Skipped: only works on MS-Windows'
79 endif
80endfunc
81
Bram Moolenaar8c5a2782019-08-07 23:07:07 +020082" Command to check for NOT running on MS-Windows
83command CheckNotMSWindows call CheckNotMSWindows()
84func CheckNotMSWindows()
85 if has('win32')
86 throw 'Skipped: does not work on MS-Windows'
87 endif
88endfunc
89
Bram Moolenaar4641a122019-07-29 22:10:23 +020090" Command to check for running on Unix
91command CheckUnix call CheckUnix()
92func CheckUnix()
93 if !has('unix')
94 throw 'Skipped: only works on Unix'
95 endif
96endfunc
Bram Moolenaar3c8ee622019-08-03 22:55:50 +020097
LemonBoycc766a82022-04-04 15:46:58 +010098" Command to check for running on Linux
Bram Moolenaar6635ae12021-03-10 21:46:39 +010099command CheckLinux call CheckLinux()
100func CheckLinux()
101 if !has('linux')
102 throw 'Skipped: only works on Linux'
103 endif
104endfunc
105
Bram Moolenaar8b9abfd2021-03-29 20:49:05 +0200106" Command to check for not running on a BSD system.
107command CheckNotBSD call CheckNotBSD()
108func CheckNotBSD()
109 if has('bsd')
110 throw 'Skipped: does not work on BSD'
111 endif
112endfunc
113
Bram Moolenaarf8027672022-09-27 15:55:43 +0100114" Command to check for not running on a MacOS
115command CheckNotMac call CheckNotMac()
116func CheckNotMac()
117 if has('mac')
118 throw 'Skipped: does not work on MacOS'
119 endif
120endfunc
121
Bram Moolenaar0056ca72022-09-23 21:26:39 +0100122" Command to check for not running on a MacOS M1 system.
123command CheckNotMacM1 call CheckNotMacM1()
124func CheckNotMacM1()
125 if has('mac') && system('uname -a') =~ '\<arm64\>'
126 throw 'Skipped: does not work on MacOS M1'
127 endif
128endfunc
129
Bram Moolenaar3c8ee622019-08-03 22:55:50 +0200130" Command to check that making screendumps is supported.
131" Caller must source screendump.vim
132command CheckScreendump call CheckScreendump()
133func CheckScreendump()
134 if !CanRunVimInTerminal()
135 throw 'Skipped: cannot make screendumps'
136 endif
137endfunc
138
139" Command to check that we can Run Vim in a terminal window
140command CheckRunVimInTerminal call CheckRunVimInTerminal()
141func CheckRunVimInTerminal()
142 if !CanRunVimInTerminal()
143 throw 'Skipped: cannot run Vim in a terminal window'
144 endif
145endfunc
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200146
147" Command to check that we can run the GUI
148command CheckCanRunGui call CheckCanRunGui()
149func CheckCanRunGui()
150 if !has('gui') || ($DISPLAY == "" && !has('gui_running'))
Bram Moolenaar25143152019-08-09 14:13:57 +0200151 throw 'Skipped: cannot start the GUI'
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200152 endif
153endfunc
154
Bram Moolenaard6fa7bd2021-07-05 14:10:04 +0200155" Command to Check for an environment variable
156command -nargs=1 CheckEnv call CheckEnv(<f-args>)
157func CheckEnv(name)
Bram Moolenaarf6d87792021-07-05 17:49:02 +0200158 if empty(eval('$' .. a:name))
Bram Moolenaard6fa7bd2021-07-05 14:10:04 +0200159 throw 'Skipped: Environment variable ' .. a:name .. ' is not set'
160 endif
161endfunc
162
lilydjwg6e0a18f2024-01-29 20:54:28 +0100163" Command to Check for pure X11 (no Wayland)
164command -nargs=0 CheckX11 call CheckX11()
165func CheckX11()
166 if !empty($WAYLAND_DISPLAY) || empty($DISPLAY)
167 throw 'Skipped: not pure X11 environment'
168 endif
169endfunc
170
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200171" Command to check that we are using the GUI
172command CheckGui call CheckGui()
173func CheckGui()
174 if !has('gui_running')
175 throw 'Skipped: only works in the GUI'
176 endif
177endfunc
178
179" Command to check that not currently using the GUI
180command CheckNotGui call CheckNotGui()
181func CheckNotGui()
182 if has('gui_running')
183 throw 'Skipped: only works in the terminal'
184 endif
185endfunc
Bram Moolenaar07282f02019-10-10 16:46:17 +0200186
187" Command to check that test is not running as root
188command CheckNotRoot call CheckNotRoot()
189func CheckNotRoot()
190 if IsRoot()
191 throw 'Skipped: cannot run test as root'
192 endif
193endfunc
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200194
195" Command to check that the current language is English
196command CheckEnglish call CheckEnglish()
197func CheckEnglish()
198 if v:lang != "C" && v:lang !~ '^[Ee]n'
199 throw 'Skipped: only works in English language environment'
200 endif
201endfunc
202
Bram Moolenaarbfe13cc2020-04-12 17:53:12 +0200203" Command to check that loopback device has IPv6 address
204command CheckIPv6 call CheckIPv6()
205func CheckIPv6()
206 if !has('ipv6')
207 throw 'Skipped: cannot use IPv6 networking'
208 endif
209 if !exists('s:ipv6_loopback')
210 let s:ipv6_loopback = s:CheckIPv6Loopback()
211 endif
212 if !s:ipv6_loopback
213 throw 'Skipped: no IPv6 address for loopback device'
214 endif
215endfunc
216
217func s:CheckIPv6Loopback()
218 if has('win32')
219 return system('netsh interface ipv6 show interface') =~? '\<Loopback\>'
220 elseif filereadable('/proc/net/if_inet6')
221 return (match(readfile('/proc/net/if_inet6'), '\slo$') >= 0)
222 elseif executable('ifconfig')
223 for dev in ['lo0', 'lo', 'loop']
224 " NOTE: On SunOS, need specify address family 'inet6' to get IPv6 info.
225 if system('ifconfig ' .. dev .. ' inet6 2>/dev/null') =~? '\<inet6\>'
226 \ || system('ifconfig ' .. dev .. ' 2>/dev/null') =~? '\<inet6\>'
227 return v:true
228 endif
229 endfor
230 else
231 " TODO: How to check it in other platforms?
232 endif
233 return v:false
234endfunc
235
Bram Moolenaar97202d92021-01-28 18:34:35 +0100236" Command to check for not running under ASAN
237command CheckNotAsan call CheckNotAsan()
238func CheckNotAsan()
239 if execute('version') =~# '-fsanitize=[a-z,]*\<address\>'
240 throw 'Skipped: does not work with ASAN'
241 endif
242endfunc
243
Bram Moolenaarcf801d42022-06-21 18:34:42 +0100244" Command to check for not running under valgrind
245command CheckNotValgrind call CheckNotValgrind()
246func CheckNotValgrind()
247 if RunningWithValgrind()
248 throw 'Skipped: does not work well with valgrind'
249 endif
250endfunc
251
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100252" Command to check for X11 based GUI
253command CheckX11BasedGui call CheckX11BasedGui()
254func CheckX11BasedGui()
255 if !g:x11_based_gui
256 throw 'Skipped: requires X11 based GUI'
257 endif
258endfunc
259
Ernie Rael559f2302022-07-26 14:44:36 +0100260" Command to check that there are two clipboards
261command CheckTwoClipboards call CheckTwoClipboards()
262func CheckTwoClipboards()
263 " avoid changing the clipboard here, only X11 supports both
264 if !has('X11')
265 throw 'Skipped: requires two clipboards'
266 endif
267endfunc
268
Bram Moolenaarf8c52e82021-03-17 12:27:23 +0100269" Command to check for satisfying any of the conditions.
270" e.g. CheckAnyOf Feature:bsd Feature:sun Linux
271command -nargs=+ CheckAnyOf call CheckAnyOf(<f-args>)
272func CheckAnyOf(...)
273 let excp = []
274 for arg in a:000
275 try
276 exe 'Check' .. substitute(arg, ':', ' ', '')
277 return
278 catch /^Skipped:/
279 let excp += [substitute(v:exception, '^Skipped:\s*', '', '')]
280 endtry
281 endfor
282 throw 'Skipped: ' .. join(excp, '; ')
283endfunc
284
285" Command to check for satisfying all of the conditions.
286" e.g. CheckAllOf Unix Gui Option:ballooneval
287command -nargs=+ CheckAllOf call CheckAllOf(<f-args>)
288func CheckAllOf(...)
289 for arg in a:000
290 exe 'Check' .. substitute(arg, ':', ' ', '')
291 endfor
292endfunc
293
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200294" vim: shiftwidth=2 sts=2 expandtab