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