blob: 6190399e5d6aba2fccf04a76632dc1211682c31c [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
17" Command to check for the presence of a working option.
18command -nargs=1 CheckOption call CheckOption(<f-args>)
19func CheckOption(name)
Bram Moolenaarc5a8fdc2020-03-22 20:13:39 +010020 if !exists('&' .. a:name)
21 throw 'Checking for non-existent option ' .. a:name
22 endif
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020023 if !exists('+' .. a:name)
24 throw 'Skipped: ' .. a:name .. ' option not supported'
25 endif
26endfunc
27
Bram Moolenaar15c47602020-03-26 22:16:48 +010028" Command to check for the presence of a built-in function.
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020029command -nargs=1 CheckFunction call CheckFunction(<f-args>)
30func CheckFunction(name)
Bram Moolenaar15c47602020-03-26 22:16:48 +010031 if !exists('?' .. a:name)
32 throw 'Checking for non-existent function ' .. a:name
33 endif
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020034 if !exists('*' .. a:name)
35 throw 'Skipped: ' .. a:name .. ' function missing'
36 endif
37endfunc
Bram Moolenaar4641a122019-07-29 22:10:23 +020038
Bram Moolenaar8c5a2782019-08-07 23:07:07 +020039" Command to check for the presence of an Ex command
40command -nargs=1 CheckCommand call CheckCommand(<f-args>)
41func CheckCommand(name)
42 if !exists(':' .. a:name)
43 throw 'Skipped: ' .. a:name .. ' command not supported'
44 endif
45endfunc
46
47" Command to check for the presence of a shell command
48command -nargs=1 CheckExecutable call CheckExecutable(<f-args>)
49func CheckExecutable(name)
50 if !executable(a:name)
51 throw 'Skipped: ' .. a:name .. ' program not executable'
52 endif
53endfunc
54
Bram Moolenaara161cb52020-04-30 19:09:35 +020055" Command to check for the presence of python. Argument should have been
56" obtained with PythonProg()
57func CheckPython(name)
58 if a:name == ''
59 throw 'Skipped: python command not available'
60 endif
61endfunc
62
Bram Moolenaar4641a122019-07-29 22:10:23 +020063" Command to check for running on MS-Windows
64command CheckMSWindows call CheckMSWindows()
65func CheckMSWindows()
66 if !has('win32')
67 throw 'Skipped: only works on MS-Windows'
68 endif
69endfunc
70
Bram Moolenaar8c5a2782019-08-07 23:07:07 +020071" Command to check for NOT running on MS-Windows
72command CheckNotMSWindows call CheckNotMSWindows()
73func CheckNotMSWindows()
74 if has('win32')
75 throw 'Skipped: does not work on MS-Windows'
76 endif
77endfunc
78
Bram Moolenaar4641a122019-07-29 22:10:23 +020079" Command to check for running on Unix
80command CheckUnix call CheckUnix()
81func CheckUnix()
82 if !has('unix')
83 throw 'Skipped: only works on Unix'
84 endif
85endfunc
Bram Moolenaar3c8ee622019-08-03 22:55:50 +020086
Bram Moolenaar6635ae12021-03-10 21:46:39 +010087" Command to check for running on Linix
88command CheckLinux call CheckLinux()
89func CheckLinux()
90 if !has('linux')
91 throw 'Skipped: only works on Linux'
92 endif
93endfunc
94
Bram Moolenaar3c8ee622019-08-03 22:55:50 +020095" Command to check that making screendumps is supported.
96" Caller must source screendump.vim
97command CheckScreendump call CheckScreendump()
98func CheckScreendump()
99 if !CanRunVimInTerminal()
100 throw 'Skipped: cannot make screendumps'
101 endif
102endfunc
103
104" Command to check that we can Run Vim in a terminal window
105command CheckRunVimInTerminal call CheckRunVimInTerminal()
106func CheckRunVimInTerminal()
107 if !CanRunVimInTerminal()
108 throw 'Skipped: cannot run Vim in a terminal window'
109 endif
110endfunc
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200111
112" Command to check that we can run the GUI
113command CheckCanRunGui call CheckCanRunGui()
114func CheckCanRunGui()
115 if !has('gui') || ($DISPLAY == "" && !has('gui_running'))
Bram Moolenaar25143152019-08-09 14:13:57 +0200116 throw 'Skipped: cannot start the GUI'
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200117 endif
118endfunc
119
120" Command to check that we are using the GUI
121command CheckGui call CheckGui()
122func CheckGui()
123 if !has('gui_running')
124 throw 'Skipped: only works in the GUI'
125 endif
126endfunc
127
128" Command to check that not currently using the GUI
129command CheckNotGui call CheckNotGui()
130func CheckNotGui()
131 if has('gui_running')
132 throw 'Skipped: only works in the terminal'
133 endif
134endfunc
Bram Moolenaar07282f02019-10-10 16:46:17 +0200135
136" Command to check that test is not running as root
137command CheckNotRoot call CheckNotRoot()
138func CheckNotRoot()
139 if IsRoot()
140 throw 'Skipped: cannot run test as root'
141 endif
142endfunc
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200143
144" Command to check that the current language is English
145command CheckEnglish call CheckEnglish()
146func CheckEnglish()
147 if v:lang != "C" && v:lang !~ '^[Ee]n'
148 throw 'Skipped: only works in English language environment'
149 endif
150endfunc
151
Bram Moolenaarbfe13cc2020-04-12 17:53:12 +0200152" Command to check that loopback device has IPv6 address
153command CheckIPv6 call CheckIPv6()
154func CheckIPv6()
155 if !has('ipv6')
156 throw 'Skipped: cannot use IPv6 networking'
157 endif
158 if !exists('s:ipv6_loopback')
159 let s:ipv6_loopback = s:CheckIPv6Loopback()
160 endif
161 if !s:ipv6_loopback
162 throw 'Skipped: no IPv6 address for loopback device'
163 endif
164endfunc
165
166func s:CheckIPv6Loopback()
167 if has('win32')
168 return system('netsh interface ipv6 show interface') =~? '\<Loopback\>'
169 elseif filereadable('/proc/net/if_inet6')
170 return (match(readfile('/proc/net/if_inet6'), '\slo$') >= 0)
171 elseif executable('ifconfig')
172 for dev in ['lo0', 'lo', 'loop']
173 " NOTE: On SunOS, need specify address family 'inet6' to get IPv6 info.
174 if system('ifconfig ' .. dev .. ' inet6 2>/dev/null') =~? '\<inet6\>'
175 \ || system('ifconfig ' .. dev .. ' 2>/dev/null') =~? '\<inet6\>'
176 return v:true
177 endif
178 endfor
179 else
180 " TODO: How to check it in other platforms?
181 endif
182 return v:false
183endfunc
184
Bram Moolenaar97202d92021-01-28 18:34:35 +0100185" Command to check for not running under ASAN
186command CheckNotAsan call CheckNotAsan()
187func CheckNotAsan()
188 if execute('version') =~# '-fsanitize=[a-z,]*\<address\>'
189 throw 'Skipped: does not work with ASAN'
190 endif
191endfunc
192
Bram Moolenaarf8c52e82021-03-17 12:27:23 +0100193" Command to check for satisfying any of the conditions.
194" e.g. CheckAnyOf Feature:bsd Feature:sun Linux
195command -nargs=+ CheckAnyOf call CheckAnyOf(<f-args>)
196func CheckAnyOf(...)
197 let excp = []
198 for arg in a:000
199 try
200 exe 'Check' .. substitute(arg, ':', ' ', '')
201 return
202 catch /^Skipped:/
203 let excp += [substitute(v:exception, '^Skipped:\s*', '', '')]
204 endtry
205 endfor
206 throw 'Skipped: ' .. join(excp, '; ')
207endfunc
208
209" Command to check for satisfying all of the conditions.
210" e.g. CheckAllOf Unix Gui Option:ballooneval
211command -nargs=+ CheckAllOf call CheckAllOf(<f-args>)
212func CheckAllOf(...)
213 for arg in a:000
214 exe 'Check' .. substitute(arg, ':', ' ', '')
215 endfor
216endfunc
217
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200218" vim: shiftwidth=2 sts=2 expandtab