xref: /vim-8.2.3635/src/testdir/check.vim (revision d0bce504)
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 presence of a working option.
18command -nargs=1 CheckOption call CheckOption(<f-args>)
19func CheckOption(name)
20  if !exists('&' .. a:name)
21    throw 'Checking for non-existent option ' .. a:name
22  endif
23  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 built-in function.
29command -nargs=1 CheckFunction call CheckFunction(<f-args>)
30func CheckFunction(name)
31  if !exists('?' .. a:name)
32    throw 'Checking for non-existent function ' .. a:name
33  endif
34  if !exists('*' .. a:name)
35    throw 'Skipped: ' .. a:name .. ' function missing'
36  endif
37endfunc
38
39" Command to check for the presence of an Ex command
40command -nargs=1 CheckCommand call CheckCommand(<f-args>)
41func CheckCommand(name)
42  if !exists(':' .. a:name)
43    throw 'Skipped: ' .. a:name .. ' command not supported'
44  endif
45endfunc
46
47" Command to check for the presence of a shell command
48command -nargs=1 CheckExecutable call CheckExecutable(<f-args>)
49func CheckExecutable(name)
50  if !executable(a:name)
51    throw 'Skipped: ' .. a:name .. ' program not executable'
52  endif
53endfunc
54
55" Command to check for the presence of python.  Argument should have been
56" obtained with PythonProg()
57func CheckPython(name)
58  if a:name == ''
59    throw 'Skipped: python command not available'
60  endif
61endfunc
62
63" Command to check for running on MS-Windows
64command CheckMSWindows call CheckMSWindows()
65func CheckMSWindows()
66  if !has('win32')
67    throw 'Skipped: only works on MS-Windows'
68  endif
69endfunc
70
71" Command to check for NOT running on MS-Windows
72command CheckNotMSWindows call CheckNotMSWindows()
73func CheckNotMSWindows()
74  if has('win32')
75    throw 'Skipped: does not work on MS-Windows'
76  endif
77endfunc
78
79" Command to check for running on Unix
80command CheckUnix call CheckUnix()
81func CheckUnix()
82  if !has('unix')
83    throw 'Skipped: only works on Unix'
84  endif
85endfunc
86
87" Command to check for not running on a BSD system.
88" TODO: using this checks should not be needed
89command CheckNotBSD call CheckNotBSD()
90func CheckNotBSD()
91  if has('bsd')
92    throw 'Skipped: does not work on BSD'
93  endif
94endfunc
95
96" Command to check that making screendumps is supported.
97" Caller must source screendump.vim
98command CheckScreendump call CheckScreendump()
99func CheckScreendump()
100  if !CanRunVimInTerminal()
101    throw 'Skipped: cannot make screendumps'
102  endif
103endfunc
104
105" Command to check that we can Run Vim in a terminal window
106command CheckRunVimInTerminal call CheckRunVimInTerminal()
107func CheckRunVimInTerminal()
108  if !CanRunVimInTerminal()
109    throw 'Skipped: cannot run Vim in a terminal window'
110  endif
111endfunc
112
113" Command to check that we can run the GUI
114command CheckCanRunGui call CheckCanRunGui()
115func CheckCanRunGui()
116  if !has('gui') || ($DISPLAY == "" && !has('gui_running'))
117    throw 'Skipped: cannot start the GUI'
118  endif
119endfunc
120
121" Command to check that we are using the GUI
122command CheckGui call CheckGui()
123func CheckGui()
124  if !has('gui_running')
125    throw 'Skipped: only works in the GUI'
126  endif
127endfunc
128
129" Command to check that not currently using the GUI
130command CheckNotGui call CheckNotGui()
131func CheckNotGui()
132  if has('gui_running')
133    throw 'Skipped: only works in the terminal'
134  endif
135endfunc
136
137" Command to check that test is not running as root
138command CheckNotRoot call CheckNotRoot()
139func CheckNotRoot()
140  if IsRoot()
141    throw 'Skipped: cannot run test as root'
142  endif
143endfunc
144
145" Command to check that the current language is English
146command CheckEnglish call CheckEnglish()
147func CheckEnglish()
148  if v:lang != "C" && v:lang !~ '^[Ee]n'
149      throw 'Skipped: only works in English language environment'
150  endif
151endfunc
152
153" Command to check that loopback device has IPv6 address
154command CheckIPv6 call CheckIPv6()
155func CheckIPv6()
156  if !has('ipv6')
157    throw 'Skipped: cannot use IPv6 networking'
158  endif
159  if !exists('s:ipv6_loopback')
160    let s:ipv6_loopback = s:CheckIPv6Loopback()
161  endif
162  if !s:ipv6_loopback
163    throw 'Skipped: no IPv6 address for loopback device'
164  endif
165endfunc
166
167func s:CheckIPv6Loopback()
168  if has('win32')
169    return system('netsh interface ipv6 show interface') =~? '\<Loopback\>'
170  elseif filereadable('/proc/net/if_inet6')
171    return (match(readfile('/proc/net/if_inet6'), '\slo$') >= 0)
172  elseif executable('ifconfig')
173    for dev in ['lo0', 'lo', 'loop']
174      " NOTE: On SunOS, need specify address family 'inet6' to get IPv6 info.
175      if system('ifconfig ' .. dev .. ' inet6 2>/dev/null') =~? '\<inet6\>'
176            \ || system('ifconfig ' .. dev .. ' 2>/dev/null') =~? '\<inet6\>'
177        return v:true
178      endif
179    endfor
180  else
181    " TODO: How to check it in other platforms?
182  endif
183  return v:false
184endfunc
185
186" Command to check for not running under ASAN
187command CheckNotAsan call CheckNotAsan()
188func CheckNotAsan()
189  if execute('version') =~# '-fsanitize=[a-z,]*\<address\>'
190    throw 'Skipped: does not work with ASAN'
191  endif
192endfunc
193
194" vim: shiftwidth=2 sts=2 expandtab
195