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 'Checking for non-existent option ' .. a:name 22 endif 23 if !exists('+' .. a:name) 24 throw 'Skipped: ' .. a:name .. ' option not supported' 25 endif 26endfunc 27 28" Command to check for the presence of a built-in function. 29command -nargs=1 CheckFunction call CheckFunction(<f-args>) 30func CheckFunction(name) 31 if !exists('?' .. a:name) 32 throw 'Checking for non-existent function ' .. a:name 33 endif 34 if !exists('*' .. a:name) 35 throw 'Skipped: ' .. a:name .. ' function missing' 36 endif 37endfunc 38 39" 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 55" 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 63" 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 71" 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 79" 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 86 87" 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 95" Command to check for not running on a BSD system. 96command CheckNotBSD call CheckNotBSD() 97func CheckNotBSD() 98 if has('bsd') 99 throw 'Skipped: does not work on BSD' 100 endif 101endfunc 102 103" Command to check that making screendumps is supported. 104" Caller must source screendump.vim 105command CheckScreendump call CheckScreendump() 106func CheckScreendump() 107 if !CanRunVimInTerminal() 108 throw 'Skipped: cannot make screendumps' 109 endif 110endfunc 111 112" Command to check that we can Run Vim in a terminal window 113command CheckRunVimInTerminal call CheckRunVimInTerminal() 114func CheckRunVimInTerminal() 115 if !CanRunVimInTerminal() 116 throw 'Skipped: cannot run Vim in a terminal window' 117 endif 118endfunc 119 120" Command to check that we can run the GUI 121command CheckCanRunGui call CheckCanRunGui() 122func CheckCanRunGui() 123 if !has('gui') || ($DISPLAY == "" && !has('gui_running')) 124 throw 'Skipped: cannot start the GUI' 125 endif 126endfunc 127 128" Command to check that we are using the GUI 129command CheckGui call CheckGui() 130func CheckGui() 131 if !has('gui_running') 132 throw 'Skipped: only works in the GUI' 133 endif 134endfunc 135 136" Command to check that not currently using the GUI 137command CheckNotGui call CheckNotGui() 138func CheckNotGui() 139 if has('gui_running') 140 throw 'Skipped: only works in the terminal' 141 endif 142endfunc 143 144" Command to check that test is not running as root 145command CheckNotRoot call CheckNotRoot() 146func CheckNotRoot() 147 if IsRoot() 148 throw 'Skipped: cannot run test as root' 149 endif 150endfunc 151 152" Command to check that the current language is English 153command CheckEnglish call CheckEnglish() 154func CheckEnglish() 155 if v:lang != "C" && v:lang !~ '^[Ee]n' 156 throw 'Skipped: only works in English language environment' 157 endif 158endfunc 159 160" Command to check that loopback device has IPv6 address 161command CheckIPv6 call CheckIPv6() 162func CheckIPv6() 163 if !has('ipv6') 164 throw 'Skipped: cannot use IPv6 networking' 165 endif 166 if !exists('s:ipv6_loopback') 167 let s:ipv6_loopback = s:CheckIPv6Loopback() 168 endif 169 if !s:ipv6_loopback 170 throw 'Skipped: no IPv6 address for loopback device' 171 endif 172endfunc 173 174func s:CheckIPv6Loopback() 175 if has('win32') 176 return system('netsh interface ipv6 show interface') =~? '\<Loopback\>' 177 elseif filereadable('/proc/net/if_inet6') 178 return (match(readfile('/proc/net/if_inet6'), '\slo$') >= 0) 179 elseif executable('ifconfig') 180 for dev in ['lo0', 'lo', 'loop'] 181 " NOTE: On SunOS, need specify address family 'inet6' to get IPv6 info. 182 if system('ifconfig ' .. dev .. ' inet6 2>/dev/null') =~? '\<inet6\>' 183 \ || system('ifconfig ' .. dev .. ' 2>/dev/null') =~? '\<inet6\>' 184 return v:true 185 endif 186 endfor 187 else 188 " TODO: How to check it in other platforms? 189 endif 190 return v:false 191endfunc 192 193" Command to check for not running under ASAN 194command CheckNotAsan call CheckNotAsan() 195func CheckNotAsan() 196 if execute('version') =~# '-fsanitize=[a-z,]*\<address\>' 197 throw 'Skipped: does not work with ASAN' 198 endif 199endfunc 200 201" Command to check for satisfying any of the conditions. 202" e.g. CheckAnyOf Feature:bsd Feature:sun Linux 203command -nargs=+ CheckAnyOf call CheckAnyOf(<f-args>) 204func CheckAnyOf(...) 205 let excp = [] 206 for arg in a:000 207 try 208 exe 'Check' .. substitute(arg, ':', ' ', '') 209 return 210 catch /^Skipped:/ 211 let excp += [substitute(v:exception, '^Skipped:\s*', '', '')] 212 endtry 213 endfor 214 throw 'Skipped: ' .. join(excp, '; ') 215endfunc 216 217" Command to check for satisfying all of the conditions. 218" e.g. CheckAllOf Unix Gui Option:ballooneval 219command -nargs=+ CheckAllOf call CheckAllOf(<f-args>) 220func CheckAllOf(...) 221 for arg in a:000 222 exe 'Check' .. substitute(arg, ':', ' ', '') 223 endfor 224endfunc 225 226" vim: shiftwidth=2 sts=2 expandtab 227