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