check.vim 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. source shared.vim
  2. source term_util.vim
  3. command -nargs=1 MissingFeature throw 'Skipped: ' .. <args> .. ' feature missing'
  4. " Command to check for the presence of a feature.
  5. command -nargs=1 CheckFeature call CheckFeature(<f-args>)
  6. func CheckFeature(name)
  7. " if !has(a:name, 1)
  8. " throw 'Checking for non-existent feature ' .. a:name
  9. " endif
  10. if !has(a:name)
  11. MissingFeature a:name
  12. endif
  13. endfunc
  14. " Command to check for the absence of a feature.
  15. command -nargs=1 CheckNotFeature call CheckNotFeature(<f-args>)
  16. func CheckNotFeature(name)
  17. " if !has(a:name, 1)
  18. " throw 'Checking for non-existent feature ' .. a:name
  19. " endif
  20. if has(a:name)
  21. throw 'Skipped: ' .. a:name .. ' feature present'
  22. endif
  23. endfunc
  24. " Command to check for the presence of a working option.
  25. command -nargs=1 CheckOption call CheckOption(<f-args>)
  26. func CheckOption(name)
  27. if !exists('&' .. a:name)
  28. throw 'Checking for non-existent option ' .. a:name
  29. endif
  30. if !exists('+' .. a:name)
  31. throw 'Skipped: ' .. a:name .. ' option not supported'
  32. endif
  33. endfunc
  34. " Command to check for the presence of a function.
  35. command -nargs=1 CheckFunction call CheckFunction(<f-args>)
  36. func CheckFunction(name)
  37. if !exists('*' .. a:name)
  38. throw 'Skipped: ' .. a:name .. ' function missing'
  39. endif
  40. endfunc
  41. " Command to check for the presence of an Ex command
  42. command -nargs=1 CheckCommand call CheckCommand(<f-args>)
  43. func CheckCommand(name)
  44. if !exists(':' .. a:name)
  45. throw 'Skipped: ' .. a:name .. ' command not supported'
  46. endif
  47. endfunc
  48. " Command to check for the presence of a shell command
  49. command -nargs=1 CheckExecutable call CheckExecutable(<f-args>)
  50. func CheckExecutable(name)
  51. if !executable(a:name)
  52. throw 'Skipped: ' .. a:name .. ' program not executable'
  53. endif
  54. endfunc
  55. " Command to check for the presence of python. Argument should have been
  56. " obtained with PythonProg()
  57. func CheckPython(name)
  58. if a:name == ''
  59. throw 'Skipped: python command not available'
  60. endif
  61. endfunc
  62. " Command to check for running on MS-Windows
  63. command CheckMSWindows call CheckMSWindows()
  64. func CheckMSWindows()
  65. if !has('win32')
  66. throw 'Skipped: only works on MS-Windows'
  67. endif
  68. endfunc
  69. " Command to check for NOT running on MS-Windows
  70. command CheckNotMSWindows call CheckNotMSWindows()
  71. func CheckNotMSWindows()
  72. if has('win32')
  73. throw 'Skipped: does not work on MS-Windows'
  74. endif
  75. endfunc
  76. " Command to check for running on Unix
  77. command CheckUnix call CheckUnix()
  78. func CheckUnix()
  79. if !has('unix')
  80. throw 'Skipped: only works on Unix'
  81. endif
  82. endfunc
  83. " Command to check for running on Linux
  84. command CheckLinux call CheckLinux()
  85. func CheckLinux()
  86. if !has('linux')
  87. throw 'Skipped: only works on Linux'
  88. endif
  89. endfunc
  90. " Command to check for not running on a BSD system.
  91. command CheckNotBSD call CheckNotBSD()
  92. func CheckNotBSD()
  93. if has('bsd')
  94. throw 'Skipped: does not work on BSD'
  95. endif
  96. endfunc
  97. " Command to check for not running on a MacOS
  98. command CheckNotMac call CheckNotMac()
  99. func CheckNotMac()
  100. if has('mac')
  101. throw 'Skipped: does not work on MacOS'
  102. endif
  103. endfunc
  104. " Command to check for not running on a MacOS M1 system.
  105. command CheckNotMacM1 call CheckNotMacM1()
  106. func CheckNotMacM1()
  107. if has('mac') && system('uname -a') =~ '\<arm64\>'
  108. throw 'Skipped: does not work on MacOS M1'
  109. endif
  110. endfunc
  111. " Command to check that making screendumps is supported.
  112. " Caller must source screendump.vim
  113. command CheckScreendump call CheckScreendump()
  114. func CheckScreendump()
  115. if !CanRunVimInTerminal()
  116. throw 'Skipped: cannot make screendumps'
  117. endif
  118. endfunc
  119. " Command to check that we can Run Vim in a terminal window
  120. command CheckRunVimInTerminal call CheckRunVimInTerminal()
  121. func CheckRunVimInTerminal()
  122. if !CanRunVimInTerminal()
  123. throw 'Skipped: cannot run Vim in a terminal window'
  124. endif
  125. endfunc
  126. " Command to check that we can run the GUI
  127. command CheckCanRunGui call CheckCanRunGui()
  128. func CheckCanRunGui()
  129. if !has('gui') || ($DISPLAY == "" && !has('gui_running'))
  130. throw 'Skipped: cannot start the GUI'
  131. endif
  132. endfunc
  133. " Command to Check for an environment variable
  134. command -nargs=1 CheckEnv call CheckEnv(<f-args>)
  135. func CheckEnv(name)
  136. if empty(eval('$' .. a:name))
  137. throw 'Skipped: Environment variable ' .. a:name .. ' is not set'
  138. endif
  139. endfunc
  140. " Command to check that we are using the GUI
  141. command CheckGui call CheckGui()
  142. func CheckGui()
  143. if !has('gui_running')
  144. throw 'Skipped: only works in the GUI'
  145. endif
  146. endfunc
  147. " Command to check that not currently using the GUI
  148. command CheckNotGui call CheckNotGui()
  149. func CheckNotGui()
  150. if has('gui_running')
  151. throw 'Skipped: only works in the terminal'
  152. endif
  153. endfunc
  154. " Command to check that test is not running as root
  155. command CheckNotRoot call CheckNotRoot()
  156. func CheckNotRoot()
  157. if IsRoot()
  158. throw 'Skipped: cannot run test as root'
  159. endif
  160. endfunc
  161. " Command to check that the current language is English
  162. command CheckEnglish call CheckEnglish()
  163. func CheckEnglish()
  164. if v:lang != "C" && v:lang !~ '^[Ee]n'
  165. throw 'Skipped: only works in English language environment'
  166. endif
  167. endfunc
  168. " Command to check for not running under ASAN
  169. command CheckNotAsan call CheckNotAsan()
  170. func CheckNotAsan()
  171. if execute('verbose version') =~# '-fsanitize=[a-z,]*\<address\>'
  172. throw 'Skipped: does not work with ASAN'
  173. endif
  174. endfunc
  175. " Command to check for not running under valgrind
  176. command CheckNotValgrind call CheckNotValgrind()
  177. func CheckNotValgrind()
  178. if RunningWithValgrind()
  179. throw 'Skipped: does not work well with valgrind'
  180. endif
  181. endfunc
  182. " Command to check for X11 based GUI
  183. command CheckX11BasedGui call CheckX11BasedGui()
  184. func CheckX11BasedGui()
  185. if !g:x11_based_gui
  186. throw 'Skipped: requires X11 based GUI'
  187. endif
  188. endfunc
  189. " Command to check for satisfying any of the conditions.
  190. " e.g. CheckAnyOf Feature:bsd Feature:sun Linux
  191. command -nargs=+ CheckAnyOf call CheckAnyOf(<f-args>)
  192. func CheckAnyOf(...)
  193. let excp = []
  194. for arg in a:000
  195. try
  196. exe 'Check' .. substitute(arg, ':', ' ', '')
  197. return
  198. catch /^Skipped:/
  199. let excp += [substitute(v:exception, '^Skipped:\s*', '', '')]
  200. endtry
  201. endfor
  202. throw 'Skipped: ' .. join(excp, '; ')
  203. endfunc
  204. " Command to check for satisfying all of the conditions.
  205. " e.g. CheckAllOf Unix Gui Option:ballooneval
  206. command -nargs=+ CheckAllOf call CheckAllOf(<f-args>)
  207. func CheckAllOf(...)
  208. for arg in a:000
  209. exe 'Check' .. substitute(arg, ':', ' ', '')
  210. endfor
  211. endfunc
  212. " vim: shiftwidth=2 sts=2 expandtab