blob: d01dd81dd56282c6445b7a0727fb516f04d0a587 [file] [log] [blame]
Bram Moolenaar07282f02019-10-10 16:46:17 +02001source shared.vim
Bram Moolenaar3180fe62020-02-02 13:47:06 +01002source term_util.vim
Bram Moolenaar07282f02019-10-10 16:46:17 +02003
Bram Moolenaar7f829ca2020-01-31 22:12:41 +01004command -nargs=1 MissingFeature throw 'Skipped: ' .. <args> .. ' feature missing'
5
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02006" Command to check for the presence of a feature.
7command -nargs=1 CheckFeature call CheckFeature(<f-args>)
8func CheckFeature(name)
Bram Moolenaar79296512020-03-22 16:17:14 +01009 if !has(a:name, 1)
10 throw 'Checking for non-existent feature ' .. a:name
11 endif
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020012 if !has(a:name)
Bram Moolenaar7f829ca2020-01-31 22:12:41 +010013 MissingFeature a:name
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020014 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)
Bram Moolenaarc5a8fdc2020-03-22 20:13:39 +010020 if !exists('&' .. a:name)
21 throw 'Checking for non-existent option ' .. a:name
22 endif
Bram Moolenaarb46fecd2019-06-15 17:58:09 +020023 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 function.
29command -nargs=1 CheckFunction call CheckFunction(<f-args>)
30func CheckFunction(name)
31 if !exists('*' .. a:name)
32 throw 'Skipped: ' .. a:name .. ' function missing'
33 endif
34endfunc
Bram Moolenaar4641a122019-07-29 22:10:23 +020035
Bram Moolenaar8c5a2782019-08-07 23:07:07 +020036" Command to check for the presence of an Ex command
37command -nargs=1 CheckCommand call CheckCommand(<f-args>)
38func CheckCommand(name)
39 if !exists(':' .. a:name)
40 throw 'Skipped: ' .. a:name .. ' command not supported'
41 endif
42endfunc
43
44" Command to check for the presence of a shell command
45command -nargs=1 CheckExecutable call CheckExecutable(<f-args>)
46func CheckExecutable(name)
47 if !executable(a:name)
48 throw 'Skipped: ' .. a:name .. ' program not executable'
49 endif
50endfunc
51
Bram Moolenaar4641a122019-07-29 22:10:23 +020052" Command to check for running on MS-Windows
53command CheckMSWindows call CheckMSWindows()
54func CheckMSWindows()
55 if !has('win32')
56 throw 'Skipped: only works on MS-Windows'
57 endif
58endfunc
59
Bram Moolenaar8c5a2782019-08-07 23:07:07 +020060" Command to check for NOT running on MS-Windows
61command CheckNotMSWindows call CheckNotMSWindows()
62func CheckNotMSWindows()
63 if has('win32')
64 throw 'Skipped: does not work on MS-Windows'
65 endif
66endfunc
67
Bram Moolenaar4641a122019-07-29 22:10:23 +020068" Command to check for running on Unix
69command CheckUnix call CheckUnix()
70func CheckUnix()
71 if !has('unix')
72 throw 'Skipped: only works on Unix'
73 endif
74endfunc
Bram Moolenaar3c8ee622019-08-03 22:55:50 +020075
Bram Moolenaar9134f1e2019-11-29 20:26:13 +010076" Command to check for not running on a BSD system.
77" TODO: using this checks should not be needed
78command CheckNotBSD call CheckNotBSD()
79func CheckNotBSD()
80 if has('bsd')
81 throw 'Skipped: does not work on BSD'
82 endif
83endfunc
84
Bram Moolenaar3c8ee622019-08-03 22:55:50 +020085" Command to check that making screendumps is supported.
86" Caller must source screendump.vim
87command CheckScreendump call CheckScreendump()
88func CheckScreendump()
89 if !CanRunVimInTerminal()
90 throw 'Skipped: cannot make screendumps'
91 endif
92endfunc
93
94" Command to check that we can Run Vim in a terminal window
95command CheckRunVimInTerminal call CheckRunVimInTerminal()
96func CheckRunVimInTerminal()
97 if !CanRunVimInTerminal()
98 throw 'Skipped: cannot run Vim in a terminal window'
99 endif
100endfunc
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200101
102" Command to check that we can run the GUI
103command CheckCanRunGui call CheckCanRunGui()
104func CheckCanRunGui()
105 if !has('gui') || ($DISPLAY == "" && !has('gui_running'))
Bram Moolenaar25143152019-08-09 14:13:57 +0200106 throw 'Skipped: cannot start the GUI'
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200107 endif
108endfunc
109
110" Command to check that we are using the GUI
111command CheckGui call CheckGui()
112func CheckGui()
113 if !has('gui_running')
114 throw 'Skipped: only works in the GUI'
115 endif
116endfunc
117
118" Command to check that not currently using the GUI
119command CheckNotGui call CheckNotGui()
120func CheckNotGui()
121 if has('gui_running')
122 throw 'Skipped: only works in the terminal'
123 endif
124endfunc
Bram Moolenaar07282f02019-10-10 16:46:17 +0200125
126" Command to check that test is not running as root
127command CheckNotRoot call CheckNotRoot()
128func CheckNotRoot()
129 if IsRoot()
130 throw 'Skipped: cannot run test as root'
131 endif
132endfunc