Bram Moolenaar | 07282f0 | 2019-10-10 16:46:17 +0200 | [diff] [blame] | 1 | source shared.vim |
Bram Moolenaar | 3180fe6 | 2020-02-02 13:47:06 +0100 | [diff] [blame] | 2 | source term_util.vim |
Bram Moolenaar | 07282f0 | 2019-10-10 16:46:17 +0200 | [diff] [blame] | 3 | |
Bram Moolenaar | 7f829ca | 2020-01-31 22:12:41 +0100 | [diff] [blame] | 4 | command -nargs=1 MissingFeature throw 'Skipped: ' .. <args> .. ' feature missing' |
| 5 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 6 | " Command to check for the presence of a feature. |
| 7 | command -nargs=1 CheckFeature call CheckFeature(<f-args>) |
| 8 | func CheckFeature(name) |
Bram Moolenaar | 7929651 | 2020-03-22 16:17:14 +0100 | [diff] [blame] | 9 | if !has(a:name, 1) |
| 10 | throw 'Checking for non-existent feature ' .. a:name |
| 11 | endif |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 12 | if !has(a:name) |
Bram Moolenaar | 7f829ca | 2020-01-31 22:12:41 +0100 | [diff] [blame] | 13 | MissingFeature a:name |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 14 | endif |
| 15 | endfunc |
| 16 | |
Bram Moolenaar | fb773a3 | 2021-07-03 21:37:59 +0200 | [diff] [blame] | 17 | " Command to check for the absence of a feature. |
| 18 | command -nargs=1 CheckNotFeature call CheckNotFeature(<f-args>) |
| 19 | func 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 |
| 26 | endfunc |
| 27 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 28 | " Command to check for the presence of a working option. |
| 29 | command -nargs=1 CheckOption call CheckOption(<f-args>) |
| 30 | func CheckOption(name) |
Bram Moolenaar | c5a8fdc | 2020-03-22 20:13:39 +0100 | [diff] [blame] | 31 | if !exists('&' .. a:name) |
| 32 | throw 'Checking for non-existent option ' .. a:name |
| 33 | endif |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 34 | if !exists('+' .. a:name) |
| 35 | throw 'Skipped: ' .. a:name .. ' option not supported' |
| 36 | endif |
| 37 | endfunc |
| 38 | |
Bram Moolenaar | 15c4760 | 2020-03-26 22:16:48 +0100 | [diff] [blame] | 39 | " Command to check for the presence of a built-in function. |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 40 | command -nargs=1 CheckFunction call CheckFunction(<f-args>) |
| 41 | func CheckFunction(name) |
Bram Moolenaar | 15c4760 | 2020-03-26 22:16:48 +0100 | [diff] [blame] | 42 | if !exists('?' .. a:name) |
| 43 | throw 'Checking for non-existent function ' .. a:name |
| 44 | endif |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 45 | if !exists('*' .. a:name) |
| 46 | throw 'Skipped: ' .. a:name .. ' function missing' |
| 47 | endif |
| 48 | endfunc |
Bram Moolenaar | 4641a12 | 2019-07-29 22:10:23 +0200 | [diff] [blame] | 49 | |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 50 | " Command to check for the presence of an Ex command |
| 51 | command -nargs=1 CheckCommand call CheckCommand(<f-args>) |
| 52 | func CheckCommand(name) |
| 53 | if !exists(':' .. a:name) |
| 54 | throw 'Skipped: ' .. a:name .. ' command not supported' |
| 55 | endif |
| 56 | endfunc |
| 57 | |
| 58 | " Command to check for the presence of a shell command |
| 59 | command -nargs=1 CheckExecutable call CheckExecutable(<f-args>) |
| 60 | func CheckExecutable(name) |
| 61 | if !executable(a:name) |
| 62 | throw 'Skipped: ' .. a:name .. ' program not executable' |
| 63 | endif |
| 64 | endfunc |
| 65 | |
Bram Moolenaar | a161cb5 | 2020-04-30 19:09:35 +0200 | [diff] [blame] | 66 | " Command to check for the presence of python. Argument should have been |
| 67 | " obtained with PythonProg() |
| 68 | func CheckPython(name) |
| 69 | if a:name == '' |
| 70 | throw 'Skipped: python command not available' |
| 71 | endif |
| 72 | endfunc |
| 73 | |
Bram Moolenaar | 4641a12 | 2019-07-29 22:10:23 +0200 | [diff] [blame] | 74 | " Command to check for running on MS-Windows |
| 75 | command CheckMSWindows call CheckMSWindows() |
| 76 | func CheckMSWindows() |
| 77 | if !has('win32') |
| 78 | throw 'Skipped: only works on MS-Windows' |
| 79 | endif |
| 80 | endfunc |
| 81 | |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 82 | " Command to check for NOT running on MS-Windows |
| 83 | command CheckNotMSWindows call CheckNotMSWindows() |
| 84 | func CheckNotMSWindows() |
| 85 | if has('win32') |
| 86 | throw 'Skipped: does not work on MS-Windows' |
| 87 | endif |
| 88 | endfunc |
| 89 | |
Bram Moolenaar | 4641a12 | 2019-07-29 22:10:23 +0200 | [diff] [blame] | 90 | " Command to check for running on Unix |
| 91 | command CheckUnix call CheckUnix() |
| 92 | func CheckUnix() |
| 93 | if !has('unix') |
| 94 | throw 'Skipped: only works on Unix' |
| 95 | endif |
| 96 | endfunc |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 97 | |
Bram Moolenaar | 6635ae1 | 2021-03-10 21:46:39 +0100 | [diff] [blame] | 98 | " Command to check for running on Linix |
| 99 | command CheckLinux call CheckLinux() |
| 100 | func CheckLinux() |
| 101 | if !has('linux') |
| 102 | throw 'Skipped: only works on Linux' |
| 103 | endif |
| 104 | endfunc |
| 105 | |
Bram Moolenaar | 8b9abfd | 2021-03-29 20:49:05 +0200 | [diff] [blame] | 106 | " Command to check for not running on a BSD system. |
| 107 | command CheckNotBSD call CheckNotBSD() |
| 108 | func CheckNotBSD() |
| 109 | if has('bsd') |
| 110 | throw 'Skipped: does not work on BSD' |
| 111 | endif |
| 112 | endfunc |
| 113 | |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 114 | " Command to check that making screendumps is supported. |
| 115 | " Caller must source screendump.vim |
| 116 | command CheckScreendump call CheckScreendump() |
| 117 | func CheckScreendump() |
| 118 | if !CanRunVimInTerminal() |
| 119 | throw 'Skipped: cannot make screendumps' |
| 120 | endif |
| 121 | endfunc |
| 122 | |
| 123 | " Command to check that we can Run Vim in a terminal window |
| 124 | command CheckRunVimInTerminal call CheckRunVimInTerminal() |
| 125 | func CheckRunVimInTerminal() |
| 126 | if !CanRunVimInTerminal() |
| 127 | throw 'Skipped: cannot run Vim in a terminal window' |
| 128 | endif |
| 129 | endfunc |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 130 | |
| 131 | " Command to check that we can run the GUI |
| 132 | command CheckCanRunGui call CheckCanRunGui() |
| 133 | func CheckCanRunGui() |
| 134 | if !has('gui') || ($DISPLAY == "" && !has('gui_running')) |
Bram Moolenaar | 2514315 | 2019-08-09 14:13:57 +0200 | [diff] [blame] | 135 | throw 'Skipped: cannot start the GUI' |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 136 | endif |
| 137 | endfunc |
| 138 | |
Bram Moolenaar | d6fa7bd | 2021-07-05 14:10:04 +0200 | [diff] [blame^] | 139 | " Command to Check for an environment variable |
| 140 | command -nargs=1 CheckEnv call CheckEnv(<f-args>) |
| 141 | func CheckEnv(name) |
| 142 | if empty('$' .. a:name) |
| 143 | throw 'Skipped: Environment variable ' .. a:name .. ' is not set' |
| 144 | endif |
| 145 | endfunc |
| 146 | |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 147 | " Command to check that we are using the GUI |
| 148 | command CheckGui call CheckGui() |
| 149 | func CheckGui() |
| 150 | if !has('gui_running') |
| 151 | throw 'Skipped: only works in the GUI' |
| 152 | endif |
| 153 | endfunc |
| 154 | |
| 155 | " Command to check that not currently using the GUI |
| 156 | command CheckNotGui call CheckNotGui() |
| 157 | func CheckNotGui() |
| 158 | if has('gui_running') |
| 159 | throw 'Skipped: only works in the terminal' |
| 160 | endif |
| 161 | endfunc |
Bram Moolenaar | 07282f0 | 2019-10-10 16:46:17 +0200 | [diff] [blame] | 162 | |
| 163 | " Command to check that test is not running as root |
| 164 | command CheckNotRoot call CheckNotRoot() |
| 165 | func CheckNotRoot() |
| 166 | if IsRoot() |
| 167 | throw 'Skipped: cannot run test as root' |
| 168 | endif |
| 169 | endfunc |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 170 | |
| 171 | " Command to check that the current language is English |
| 172 | command CheckEnglish call CheckEnglish() |
| 173 | func CheckEnglish() |
| 174 | if v:lang != "C" && v:lang !~ '^[Ee]n' |
| 175 | throw 'Skipped: only works in English language environment' |
| 176 | endif |
| 177 | endfunc |
| 178 | |
Bram Moolenaar | bfe13cc | 2020-04-12 17:53:12 +0200 | [diff] [blame] | 179 | " Command to check that loopback device has IPv6 address |
| 180 | command CheckIPv6 call CheckIPv6() |
| 181 | func 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 |
| 191 | endfunc |
| 192 | |
| 193 | func 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 |
| 210 | endfunc |
| 211 | |
Bram Moolenaar | 97202d9 | 2021-01-28 18:34:35 +0100 | [diff] [blame] | 212 | " Command to check for not running under ASAN |
| 213 | command CheckNotAsan call CheckNotAsan() |
| 214 | func CheckNotAsan() |
| 215 | if execute('version') =~# '-fsanitize=[a-z,]*\<address\>' |
| 216 | throw 'Skipped: does not work with ASAN' |
| 217 | endif |
| 218 | endfunc |
| 219 | |
Bram Moolenaar | f8c52e8 | 2021-03-17 12:27:23 +0100 | [diff] [blame] | 220 | " Command to check for satisfying any of the conditions. |
| 221 | " e.g. CheckAnyOf Feature:bsd Feature:sun Linux |
| 222 | command -nargs=+ CheckAnyOf call CheckAnyOf(<f-args>) |
| 223 | func 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, '; ') |
| 234 | endfunc |
| 235 | |
| 236 | " Command to check for satisfying all of the conditions. |
| 237 | " e.g. CheckAllOf Unix Gui Option:ballooneval |
| 238 | command -nargs=+ CheckAllOf call CheckAllOf(<f-args>) |
| 239 | func CheckAllOf(...) |
| 240 | for arg in a:000 |
| 241 | exe 'Check' .. substitute(arg, ':', ' ', '') |
| 242 | endfor |
| 243 | endfunc |
| 244 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 245 | " vim: shiftwidth=2 sts=2 expandtab |