neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

check.vim (7972B)


      1 source shared.vim
      2 source term_util.vim
      3 
      4 command -nargs=1 MissingFeature throw 'Skipped: ' .. <args> .. ' feature missing'
      5 
      6 " Command to check for the presence of a feature.
      7 command -nargs=1 CheckFeature call CheckFeature(<f-args>)
      8 func 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
     15 endfunc
     16 
     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 
     28 " Command to check for the presence of a working option.
     29 command -nargs=1 CheckOption call CheckOption(<f-args>)
     30 func CheckOption(name)
     31  if !exists('&' .. a:name)
     32    throw 'Checking for non-existent option ' .. a:name
     33  endif
     34  if !exists('+' .. a:name)
     35    throw 'Skipped: ' .. a:name .. ' option not supported'
     36  endif
     37 endfunc
     38 
     39 " Command to check for the presence of a function.
     40 command -nargs=1 CheckFunction call CheckFunction(<f-args>)
     41 func CheckFunction(name)
     42  if !exists('*' .. a:name)
     43    throw 'Skipped: ' .. a:name .. ' function missing'
     44  endif
     45 endfunc
     46 
     47 " Command to check for the presence of an Ex command
     48 command -nargs=1 CheckCommand call CheckCommand(<f-args>)
     49 func CheckCommand(name)
     50  if !exists(':' .. a:name)
     51    throw 'Skipped: ' .. a:name .. ' command not supported'
     52  endif
     53 endfunc
     54 
     55 " Command to check for the presence of a shell command
     56 command -nargs=1 CheckExecutable call CheckExecutable(<f-args>)
     57 func CheckExecutable(name)
     58  if !executable(a:name)
     59    throw 'Skipped: ' .. a:name .. ' program not executable'
     60  endif
     61 endfunc
     62 
     63 " Command to check for the presence of python.  Argument should have been
     64 " obtained with PythonProg()
     65 func CheckPython(name)
     66  if a:name == ''
     67    throw 'Skipped: python command not available'
     68  endif
     69 endfunc
     70 
     71 " Command to check for running on MS-Windows
     72 command CheckMSWindows call CheckMSWindows()
     73 func CheckMSWindows()
     74  if !has('win32')
     75    throw 'Skipped: only works on MS-Windows'
     76  endif
     77 endfunc
     78 
     79 " Command to check for NOT running on MS-Windows
     80 command CheckNotMSWindows call CheckNotMSWindows()
     81 func CheckNotMSWindows()
     82  if has('win32')
     83    throw 'Skipped: does not work on MS-Windows'
     84  endif
     85 endfunc
     86 
     87 " Command to check for running on Unix
     88 command CheckUnix call CheckUnix()
     89 func CheckUnix()
     90  if !has('unix')
     91    throw 'Skipped: only works on Unix'
     92  endif
     93 endfunc
     94 
     95 " Command to check for running on Linux
     96 command CheckLinux call CheckLinux()
     97 func CheckLinux()
     98  if !has('linux')
     99    throw 'Skipped: only works on Linux'
    100  endif
    101 endfunc
    102 
    103 " Command to check for not running on a BSD system.
    104 command CheckNotBSD call CheckNotBSD()
    105 func CheckNotBSD()
    106  if has('bsd')
    107    throw 'Skipped: does not work on BSD'
    108  endif
    109 endfunc
    110 
    111 " Command to check for not running on OpenBSD
    112 command CheckNotOpenBSD call CheckNotOpenBSD()
    113 func CheckNotOpenBSD()
    114  if has('bsd')
    115    let uname = trim(system('uname'))
    116    if uname == 'OpenBSD'
    117      throw 'Skipped: does not work on OpenBSD'
    118    endif
    119  endif
    120 endfunc
    121 
    122 " Command to check for not running on a MacOS
    123 command CheckNotMac call CheckNotMac()
    124 func CheckNotMac()
    125  if has('mac')
    126    throw 'Skipped: does not work on MacOS'
    127  endif
    128 endfunc
    129 
    130 " Command to check for not running on a MacOS M1 system.
    131 command CheckNotMacM1 call CheckNotMacM1()
    132 func CheckNotMacM1()
    133  if has('mac') && system('uname -a') =~ '\<arm64\>'
    134    throw 'Skipped: does not work on MacOS M1'
    135  endif
    136 endfunc
    137 
    138 func SetupWindowSizeToForVisualDumps()
    139  " The dumps used as reference in these tests were created with a terminal
    140  " width of 75 columns. The vim window that uses the remainder of the GUI
    141  " window width must be at least 3 columns. In theory this means we need the
    142  " GUI shell to provide 78+ columns. However the GTK3 resize logic is flaky,
    143  " sometimes resulting in X11 Configure events that are narrower than
    144  " expected by a number of pixels equal to 2 column widths. Therefore
    145  " setting 80 columns ensures that the GUI shell can still provide 78+
    146  " columns. This is very likely papering over a GTK3 resize bug but one that
    147  " has existed for a very long time. Establishing this workaround is meant to
    148  " get the GTK3 code working under CI so that we can focus on removing this
    149  " over the long term.
    150  if &columns != 80
    151    set columns=80
    152  endif
    153  " Without resetting lines, some GTK3 resize events can carry over between
    154  " tests, which invalidate assumptions in the scrollbar offset calculations.
    155  if &lines != 25
    156    set lines=25
    157  endif
    158 endfunc
    159 
    160 " Command to check that making screendumps is supported.
    161 " Caller must source screendump.vim
    162 command CheckScreendump call CheckScreendump()
    163 func CheckScreendump()
    164  let g:check_screendump_called = v:true
    165  if !CanRunVimInTerminal()
    166    throw 'Skipped: cannot make screendumps'
    167  endif
    168  if has('gui_running')
    169    call SetupWindowSizeToForVisualDumps()
    170  endif
    171 endfunc
    172 
    173 " Command to check that we can Run Vim in a terminal window
    174 command CheckRunVimInTerminal call CheckRunVimInTerminal()
    175 func CheckRunVimInTerminal()
    176  if !CanRunVimInTerminal()
    177    throw 'Skipped: cannot run Vim in a terminal window'
    178  endif
    179 endfunc
    180 
    181 " Command to check that we can run the GUI
    182 command CheckCanRunGui call CheckCanRunGui()
    183 func CheckCanRunGui()
    184  if !has('gui') || ($DISPLAY == "" && !has('gui_running'))
    185    throw 'Skipped: cannot start the GUI'
    186  endif
    187 endfunc
    188 
    189 " Command to Check for an environment variable
    190 command -nargs=1 CheckEnv call CheckEnv(<f-args>)
    191 func CheckEnv(name)
    192  if empty(eval('$' .. a:name))
    193    throw 'Skipped: Environment variable ' .. a:name .. ' is not set'
    194  endif
    195 endfunc
    196 
    197 " Command to check that we are using the GUI
    198 command CheckGui call CheckGui()
    199 func CheckGui()
    200  if !has('gui_running')
    201    throw 'Skipped: only works in the GUI'
    202  endif
    203 endfunc
    204 
    205 " Command to check that not currently using the GUI
    206 command CheckNotGui call CheckNotGui()
    207 func CheckNotGui()
    208  if has('gui_running')
    209    throw 'Skipped: only works in the terminal'
    210  endif
    211 endfunc
    212 
    213 " Command to check that test is not running as root
    214 command CheckNotRoot call CheckNotRoot()
    215 func CheckNotRoot()
    216  if IsRoot()
    217    throw 'Skipped: cannot run test as root'
    218  endif
    219 endfunc
    220 
    221 " Command to check that the current language is English
    222 command CheckEnglish call CheckEnglish()
    223 func CheckEnglish()
    224  if v:lang != "C" && v:lang !~ '^[Ee]n'
    225      throw 'Skipped: only works in English language environment'
    226  endif
    227 endfunc
    228 
    229 " Command to check for not running under ASAN
    230 command CheckNotAsan call CheckNotAsan()
    231 func CheckNotAsan()
    232  if execute('verbose version') =~# '-fsanitize=[a-z,]*\<address\>'
    233    throw 'Skipped: does not work with ASAN'
    234  endif
    235 endfunc
    236 
    237 " Command to check for not running under valgrind
    238 command CheckNotValgrind call CheckNotValgrind()
    239 func CheckNotValgrind()
    240  if RunningWithValgrind()
    241    throw 'Skipped: does not work well with valgrind'
    242  endif
    243 endfunc
    244 
    245 " Command to check for X11 based GUI
    246 command CheckX11BasedGui call CheckX11BasedGui()
    247 func CheckX11BasedGui()
    248  if !g:x11_based_gui
    249    throw 'Skipped: requires X11 based GUI'
    250  endif
    251 endfunc
    252 
    253 " Command to check for satisfying any of the conditions.
    254 " e.g. CheckAnyOf Feature:bsd Feature:sun Linux
    255 command -nargs=+ CheckAnyOf call CheckAnyOf(<f-args>)
    256 func CheckAnyOf(...)
    257  let excp = []
    258  for arg in a:000
    259    try
    260      exe 'Check' .. substitute(arg, ':', ' ', '')
    261      return
    262    catch /^Skipped:/
    263      let excp += [substitute(v:exception, '^Skipped:\s*', '', '')]
    264    endtry
    265  endfor
    266  throw 'Skipped: ' .. join(excp, '; ')
    267 endfunc
    268 
    269 " Command to check for satisfying all of the conditions.
    270 " e.g. CheckAllOf Unix Gui Option:ballooneval
    271 command -nargs=+ CheckAllOf call CheckAllOf(<f-args>)
    272 func CheckAllOf(...)
    273  for arg in a:000
    274    exe 'Check' .. substitute(arg, ':', ' ', '')
    275  endfor
    276 endfunc
    277 
    278 " vim: shiftwidth=2 sts=2 expandtab