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