blob: aa8eceb620c63cf3f47ac46b9838bdee07b5b34e [file] [log] [blame]
Christian Brabandteb380b92025-07-07 20:53:55 +02001source util/shared.vim
2source util/term_util.vim
Bram Moolenaar07282f02019-10-10 16:46:17 +02003
Christian Brabandtb0905e22025-07-07 20:39:29 +02004" uses line-continuation
5let s:cpo_save = &cpo
6set cpo&vim
7
Bram Moolenaar7f829ca2020-01-31 22:12:41 +01008command -nargs=1 MissingFeature throw 'Skipped: ' .. <args> .. ' feature missing'
9
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020010" Command to check for the presence of a feature.
11command -nargs=1 CheckFeature call CheckFeature(<f-args>)
12func CheckFeature(name)
Bram Moolenaar79296512020-03-22 16:17:14 +010013 if !has(a:name, 1)
14 throw 'Checking for non-existent feature ' .. a:name
15 endif
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020016 if !has(a:name)
Bram Moolenaar7f829ca2020-01-31 22:12:41 +010017 MissingFeature a:name
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020018 endif
19endfunc
20
Bram Moolenaarfb773a32021-07-03 21:37:59 +020021" Command to check for the absence of a feature.
22command -nargs=1 CheckNotFeature call CheckNotFeature(<f-args>)
23func CheckNotFeature(name)
24 if !has(a:name, 1)
25 throw 'Checking for non-existent feature ' .. a:name
26 endif
27 if has(a:name)
28 throw 'Skipped: ' .. a:name .. ' feature present'
29 endif
30endfunc
31
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020032" Command to check for the presence of a working option.
33command -nargs=1 CheckOption call CheckOption(<f-args>)
34func CheckOption(name)
Bram Moolenaarc5a8fdc2020-03-22 20:13:39 +010035 if !exists('&' .. a:name)
36 throw 'Checking for non-existent option ' .. a:name
37 endif
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020038 if !exists('+' .. a:name)
39 throw 'Skipped: ' .. a:name .. ' option not supported'
40 endif
41endfunc
42
Bram Moolenaar15c47602020-03-26 22:16:48 +010043" Command to check for the presence of a built-in function.
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020044command -nargs=1 CheckFunction call CheckFunction(<f-args>)
45func CheckFunction(name)
Bram Moolenaar15c47602020-03-26 22:16:48 +010046 if !exists('?' .. a:name)
47 throw 'Checking for non-existent function ' .. a:name
48 endif
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020049 if !exists('*' .. a:name)
50 throw 'Skipped: ' .. a:name .. ' function missing'
51 endif
52endfunc
Bram Moolenaar4641a122019-07-29 22:10:23 +020053
Bram Moolenaar8c5a2782019-08-07 23:07:07 +020054" Command to check for the presence of an Ex command
55command -nargs=1 CheckCommand call CheckCommand(<f-args>)
56func CheckCommand(name)
57 if !exists(':' .. a:name)
58 throw 'Skipped: ' .. a:name .. ' command not supported'
59 endif
60endfunc
61
62" Command to check for the presence of a shell command
63command -nargs=1 CheckExecutable call CheckExecutable(<f-args>)
64func CheckExecutable(name)
65 if !executable(a:name)
66 throw 'Skipped: ' .. a:name .. ' program not executable'
67 endif
68endfunc
69
Bram Moolenaara161cb52020-04-30 19:09:35 +020070" Command to check for the presence of python. Argument should have been
71" obtained with PythonProg()
72func CheckPython(name)
73 if a:name == ''
74 throw 'Skipped: python command not available'
75 endif
76endfunc
77
Bram Moolenaar4641a122019-07-29 22:10:23 +020078" Command to check for running on MS-Windows
79command CheckMSWindows call CheckMSWindows()
80func CheckMSWindows()
81 if !has('win32')
82 throw 'Skipped: only works on MS-Windows'
83 endif
84endfunc
85
Bram Moolenaar8c5a2782019-08-07 23:07:07 +020086" Command to check for NOT running on MS-Windows
87command CheckNotMSWindows call CheckNotMSWindows()
88func CheckNotMSWindows()
89 if has('win32')
90 throw 'Skipped: does not work on MS-Windows'
91 endif
92endfunc
93
Bram Moolenaar4641a122019-07-29 22:10:23 +020094" Command to check for running on Unix
95command CheckUnix call CheckUnix()
96func CheckUnix()
97 if !has('unix')
98 throw 'Skipped: only works on Unix'
99 endif
100endfunc
Bram Moolenaar3c8ee622019-08-03 22:55:50 +0200101
LemonBoycc766a82022-04-04 15:46:58 +0100102" Command to check for running on Linux
Bram Moolenaar6635ae12021-03-10 21:46:39 +0100103command CheckLinux call CheckLinux()
104func CheckLinux()
105 if !has('linux')
106 throw 'Skipped: only works on Linux'
107 endif
108endfunc
109
Bram Moolenaar8b9abfd2021-03-29 20:49:05 +0200110" Command to check for not running on a BSD system.
111command CheckNotBSD call CheckNotBSD()
112func CheckNotBSD()
113 if has('bsd')
114 throw 'Skipped: does not work on BSD'
115 endif
116endfunc
117
Bram Moolenaarf8027672022-09-27 15:55:43 +0100118" Command to check for not running on a MacOS
119command CheckNotMac call CheckNotMac()
120func CheckNotMac()
121 if has('mac')
122 throw 'Skipped: does not work on MacOS'
123 endif
124endfunc
125
Bram Moolenaar0056ca72022-09-23 21:26:39 +0100126" Command to check for not running on a MacOS M1 system.
127command CheckNotMacM1 call CheckNotMacM1()
128func CheckNotMacM1()
129 if has('mac') && system('uname -a') =~ '\<arm64\>'
130 throw 'Skipped: does not work on MacOS M1'
131 endif
132endfunc
133
Drew Vogelea67ba72025-05-07 22:05:17 +0200134func SetupWindowSizeToForVisualDumps()
135 " The dumps used as reference in these tests were created with a terminal
136 " width of 75 columns. The vim window that uses the remainder of the GUI
137 " window width must be at least 3 columns. In theory this means we need the
138 " GUI shell to provide 78+ columns. However the GTK3 resize logic is flaky,
139 " sometimes resulting in X11 Configure events that are narrower than
140 " expected by a number of pixels equal to 2 column widths. Therefore
141 " setting 80 columns ensures that the GUI shell can still provide 78+
142 " columns. This is very likely papering over a GTK3 resize bug but one that
143 " has existed for a very long time. Establishing this workaround is meant to
144 " get the GTK3 code working under CI so that we can focus on removing this
145 " over the long term.
146 if &columns != 80
147 set columns=80
148 endif
149 " Without resetting lines, some GTK3 resize events can carry over between
150 " tests, which invalidate assumptions in the scrollbar offset calculations.
151 if &lines != 25
152 set lines=25
153 endif
154endfunc
155
Bram Moolenaar3c8ee622019-08-03 22:55:50 +0200156" Command to check that making screendumps is supported.
Christian Brabandteb380b92025-07-07 20:53:55 +0200157" Caller must source util/screendump.vim
Bram Moolenaar3c8ee622019-08-03 22:55:50 +0200158command CheckScreendump call CheckScreendump()
159func CheckScreendump()
Drew Vogelea67ba72025-05-07 22:05:17 +0200160 let g:check_screendump_called = v:true
Bram Moolenaar3c8ee622019-08-03 22:55:50 +0200161 if !CanRunVimInTerminal()
162 throw 'Skipped: cannot make screendumps'
163 endif
Drew Vogelea67ba72025-05-07 22:05:17 +0200164 if has('gui_running')
165 call SetupWindowSizeToForVisualDumps()
166 endif
Bram Moolenaar3c8ee622019-08-03 22:55:50 +0200167endfunc
168
169" Command to check that we can Run Vim in a terminal window
170command CheckRunVimInTerminal call CheckRunVimInTerminal()
171func CheckRunVimInTerminal()
172 if !CanRunVimInTerminal()
173 throw 'Skipped: cannot run Vim in a terminal window'
174 endif
175endfunc
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200176
177" Command to check that we can run the GUI
178command CheckCanRunGui call CheckCanRunGui()
179func CheckCanRunGui()
180 if !has('gui') || ($DISPLAY == "" && !has('gui_running'))
Bram Moolenaar25143152019-08-09 14:13:57 +0200181 throw 'Skipped: cannot start the GUI'
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200182 endif
183endfunc
184
Bram Moolenaard6fa7bd2021-07-05 14:10:04 +0200185" Command to Check for an environment variable
186command -nargs=1 CheckEnv call CheckEnv(<f-args>)
187func CheckEnv(name)
Bram Moolenaarf6d87792021-07-05 17:49:02 +0200188 if empty(eval('$' .. a:name))
Bram Moolenaard6fa7bd2021-07-05 14:10:04 +0200189 throw 'Skipped: Environment variable ' .. a:name .. ' is not set'
190 endif
191endfunc
192
lilydjwg6e0a18f2024-01-29 20:54:28 +0100193" Command to Check for pure X11 (no Wayland)
194command -nargs=0 CheckX11 call CheckX11()
195func CheckX11()
196 if !empty($WAYLAND_DISPLAY) || empty($DISPLAY)
197 throw 'Skipped: not pure X11 environment'
198 endif
199endfunc
200
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200201" Command to check that we are using the GUI
202command CheckGui call CheckGui()
203func CheckGui()
204 if !has('gui_running')
205 throw 'Skipped: only works in the GUI'
206 endif
207endfunc
208
209" Command to check that not currently using the GUI
210command CheckNotGui call CheckNotGui()
211func CheckNotGui()
212 if has('gui_running')
213 throw 'Skipped: only works in the terminal'
214 endif
215endfunc
Bram Moolenaar07282f02019-10-10 16:46:17 +0200216
217" Command to check that test is not running as root
218command CheckNotRoot call CheckNotRoot()
219func CheckNotRoot()
220 if IsRoot()
221 throw 'Skipped: cannot run test as root'
222 endif
223endfunc
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200224
225" Command to check that the current language is English
226command CheckEnglish call CheckEnglish()
227func CheckEnglish()
228 if v:lang != "C" && v:lang !~ '^[Ee]n'
229 throw 'Skipped: only works in English language environment'
230 endif
231endfunc
232
Bram Moolenaarbfe13cc2020-04-12 17:53:12 +0200233" Command to check that loopback device has IPv6 address
234command CheckIPv6 call CheckIPv6()
235func CheckIPv6()
236 if !has('ipv6')
237 throw 'Skipped: cannot use IPv6 networking'
238 endif
239 if !exists('s:ipv6_loopback')
240 let s:ipv6_loopback = s:CheckIPv6Loopback()
241 endif
242 if !s:ipv6_loopback
243 throw 'Skipped: no IPv6 address for loopback device'
244 endif
245endfunc
246
247func s:CheckIPv6Loopback()
248 if has('win32')
249 return system('netsh interface ipv6 show interface') =~? '\<Loopback\>'
250 elseif filereadable('/proc/net/if_inet6')
251 return (match(readfile('/proc/net/if_inet6'), '\slo$') >= 0)
252 elseif executable('ifconfig')
253 for dev in ['lo0', 'lo', 'loop']
254 " NOTE: On SunOS, need specify address family 'inet6' to get IPv6 info.
255 if system('ifconfig ' .. dev .. ' inet6 2>/dev/null') =~? '\<inet6\>'
256 \ || system('ifconfig ' .. dev .. ' 2>/dev/null') =~? '\<inet6\>'
257 return v:true
258 endif
259 endfor
260 else
261 " TODO: How to check it in other platforms?
262 endif
263 return v:false
264endfunc
265
Bram Moolenaar97202d92021-01-28 18:34:35 +0100266" Command to check for not running under ASAN
267command CheckNotAsan call CheckNotAsan()
268func CheckNotAsan()
269 if execute('version') =~# '-fsanitize=[a-z,]*\<address\>'
270 throw 'Skipped: does not work with ASAN'
271 endif
272endfunc
273
Bram Moolenaarcf801d42022-06-21 18:34:42 +0100274" Command to check for not running under valgrind
275command CheckNotValgrind call CheckNotValgrind()
276func CheckNotValgrind()
277 if RunningWithValgrind()
278 throw 'Skipped: does not work well with valgrind'
279 endif
280endfunc
281
Bram Moolenaar40bd5a12021-10-16 21:58:27 +0100282" Command to check for X11 based GUI
283command CheckX11BasedGui call CheckX11BasedGui()
284func CheckX11BasedGui()
285 if !g:x11_based_gui
286 throw 'Skipped: requires X11 based GUI'
287 endif
288endfunc
289
Ernie Rael559f2302022-07-26 14:44:36 +0100290" Command to check that there are two clipboards
291command CheckTwoClipboards call CheckTwoClipboards()
292func CheckTwoClipboards()
293 " avoid changing the clipboard here, only X11 supports both
294 if !has('X11')
295 throw 'Skipped: requires two clipboards'
296 endif
297endfunc
298
Bram Moolenaarf8c52e82021-03-17 12:27:23 +0100299" Command to check for satisfying any of the conditions.
300" e.g. CheckAnyOf Feature:bsd Feature:sun Linux
301command -nargs=+ CheckAnyOf call CheckAnyOf(<f-args>)
302func CheckAnyOf(...)
303 let excp = []
304 for arg in a:000
305 try
306 exe 'Check' .. substitute(arg, ':', ' ', '')
307 return
308 catch /^Skipped:/
309 let excp += [substitute(v:exception, '^Skipped:\s*', '', '')]
310 endtry
311 endfor
312 throw 'Skipped: ' .. join(excp, '; ')
313endfunc
314
315" Command to check for satisfying all of the conditions.
316" e.g. CheckAllOf Unix Gui Option:ballooneval
317command -nargs=+ CheckAllOf call CheckAllOf(<f-args>)
318func CheckAllOf(...)
319 for arg in a:000
320 exe 'Check' .. substitute(arg, ':', ' ', '')
321 endfor
322endfunc
323
Christian Brabandt6f14ef42025-02-09 17:05:21 +0100324" Check if running under Github Actions
325command CheckGithubActions call CheckGithubActions()
326func CheckGithubActions()
327 if expand('$GITHUB_ACTIONS') ==# 'true'
328 throw "Skipped: FIXME: this test doesn't work on Github Actions CI"
329 endif
330endfunc
Christian Brabandtb0905e22025-07-07 20:39:29 +0200331
332let &cpo = s:cpo_save
333unlet s:cpo_save
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200334" vim: shiftwidth=2 sts=2 expandtab