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 | |
| 17 | " Command to check for the presence of a working option. |
| 18 | command -nargs=1 CheckOption call CheckOption(<f-args>) |
| 19 | func CheckOption(name) |
Bram Moolenaar | c5a8fdc | 2020-03-22 20:13:39 +0100 | [diff] [blame] | 20 | if !exists('&' .. a:name) |
| 21 | throw 'Checking for non-existent option ' .. a:name |
| 22 | endif |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 23 | if !exists('+' .. a:name) |
| 24 | throw 'Skipped: ' .. a:name .. ' option not supported' |
| 25 | endif |
| 26 | endfunc |
| 27 | |
Bram Moolenaar | 15c4760 | 2020-03-26 22:16:48 +0100 | [diff] [blame] | 28 | " Command to check for the presence of a built-in function. |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 29 | command -nargs=1 CheckFunction call CheckFunction(<f-args>) |
| 30 | func CheckFunction(name) |
Bram Moolenaar | 15c4760 | 2020-03-26 22:16:48 +0100 | [diff] [blame] | 31 | if !exists('?' .. a:name) |
| 32 | throw 'Checking for non-existent function ' .. 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 .. ' function missing' |
| 36 | endif |
| 37 | endfunc |
Bram Moolenaar | 4641a12 | 2019-07-29 22:10:23 +0200 | [diff] [blame] | 38 | |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 39 | " Command to check for the presence of an Ex command |
| 40 | command -nargs=1 CheckCommand call CheckCommand(<f-args>) |
| 41 | func CheckCommand(name) |
| 42 | if !exists(':' .. a:name) |
| 43 | throw 'Skipped: ' .. a:name .. ' command not supported' |
| 44 | endif |
| 45 | endfunc |
| 46 | |
| 47 | " Command to check for the presence of a shell command |
| 48 | command -nargs=1 CheckExecutable call CheckExecutable(<f-args>) |
| 49 | func CheckExecutable(name) |
| 50 | if !executable(a:name) |
| 51 | throw 'Skipped: ' .. a:name .. ' program not executable' |
| 52 | endif |
| 53 | endfunc |
| 54 | |
Bram Moolenaar | 4641a12 | 2019-07-29 22:10:23 +0200 | [diff] [blame] | 55 | " Command to check for running on MS-Windows |
| 56 | command CheckMSWindows call CheckMSWindows() |
| 57 | func CheckMSWindows() |
| 58 | if !has('win32') |
| 59 | throw 'Skipped: only works on MS-Windows' |
| 60 | endif |
| 61 | endfunc |
| 62 | |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 63 | " Command to check for NOT running on MS-Windows |
| 64 | command CheckNotMSWindows call CheckNotMSWindows() |
| 65 | func CheckNotMSWindows() |
| 66 | if has('win32') |
| 67 | throw 'Skipped: does not work on MS-Windows' |
| 68 | endif |
| 69 | endfunc |
| 70 | |
Bram Moolenaar | 4641a12 | 2019-07-29 22:10:23 +0200 | [diff] [blame] | 71 | " Command to check for running on Unix |
| 72 | command CheckUnix call CheckUnix() |
| 73 | func CheckUnix() |
| 74 | if !has('unix') |
| 75 | throw 'Skipped: only works on Unix' |
| 76 | endif |
| 77 | endfunc |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 78 | |
Bram Moolenaar | 9134f1e | 2019-11-29 20:26:13 +0100 | [diff] [blame] | 79 | " Command to check for not running on a BSD system. |
| 80 | " TODO: using this checks should not be needed |
| 81 | command CheckNotBSD call CheckNotBSD() |
| 82 | func CheckNotBSD() |
| 83 | if has('bsd') |
| 84 | throw 'Skipped: does not work on BSD' |
| 85 | endif |
| 86 | endfunc |
| 87 | |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 88 | " Command to check that making screendumps is supported. |
| 89 | " Caller must source screendump.vim |
| 90 | command CheckScreendump call CheckScreendump() |
| 91 | func CheckScreendump() |
| 92 | if !CanRunVimInTerminal() |
| 93 | throw 'Skipped: cannot make screendumps' |
| 94 | endif |
| 95 | endfunc |
| 96 | |
| 97 | " Command to check that we can Run Vim in a terminal window |
| 98 | command CheckRunVimInTerminal call CheckRunVimInTerminal() |
| 99 | func CheckRunVimInTerminal() |
| 100 | if !CanRunVimInTerminal() |
| 101 | throw 'Skipped: cannot run Vim in a terminal window' |
| 102 | endif |
| 103 | endfunc |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 104 | |
| 105 | " Command to check that we can run the GUI |
| 106 | command CheckCanRunGui call CheckCanRunGui() |
| 107 | func CheckCanRunGui() |
| 108 | if !has('gui') || ($DISPLAY == "" && !has('gui_running')) |
Bram Moolenaar | 2514315 | 2019-08-09 14:13:57 +0200 | [diff] [blame] | 109 | throw 'Skipped: cannot start the GUI' |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 110 | endif |
| 111 | endfunc |
| 112 | |
| 113 | " Command to check that we are using the GUI |
| 114 | command CheckGui call CheckGui() |
| 115 | func CheckGui() |
| 116 | if !has('gui_running') |
| 117 | throw 'Skipped: only works in the GUI' |
| 118 | endif |
| 119 | endfunc |
| 120 | |
| 121 | " Command to check that not currently using the GUI |
| 122 | command CheckNotGui call CheckNotGui() |
| 123 | func CheckNotGui() |
| 124 | if has('gui_running') |
| 125 | throw 'Skipped: only works in the terminal' |
| 126 | endif |
| 127 | endfunc |
Bram Moolenaar | 07282f0 | 2019-10-10 16:46:17 +0200 | [diff] [blame] | 128 | |
| 129 | " Command to check that test is not running as root |
| 130 | command CheckNotRoot call CheckNotRoot() |
| 131 | func CheckNotRoot() |
| 132 | if IsRoot() |
| 133 | throw 'Skipped: cannot run test as root' |
| 134 | endif |
| 135 | endfunc |