" Functions shared by several tests." Get the name of the Python executable." Also keeps it in s:python.func PythonProg()" This test requires the Python command to run the test server." This most likely only works on Unix and Windows.if has('unix')" We also need the job feature or the pkill command to make sure the server" can be stopped.if !(executable('python') && (has('job') || executable('pkill')))return ''endiflet s:python = 'python'elseif has('win32')" Use Python Launcher for Windows (py.exe) if available.if executable('py.exe')let s:python = 'py.exe'elseif executable('python.exe')let s:python = 'python.exe'elsereturn ''endifelsereturn ''endifreturn s:pythonendfunc" Run "cmd". Returns the job if using a job.func RunCommand(cmd)let job = 0if has('job')let job = job_start(a:cmd, {"stoponexit": "hup"})call job_setoptions(job, {"stoponexit": "kill"})elseif has('win32')exe 'silent !start cmd /c start "test_channel" ' . a:cmdelseexe 'silent !' . a:cmd . '&'endifreturn jobendfunc" Read the port number from the Xportnr file.func GetPort()let l = []for i in range(200)trylet l = readfile("Xportnr")catchendtryif len(l) >= 1breakendifsleep 10mendforcall delete("Xportnr")if len(l) == 0" Can't make the connection, give up.return 0endifreturn l[0]endfunc" Run a Python server for "cmd" and call "testfunc"." Always kills the server before returning.func RunServer(cmd, testfunc, args)" The Python program writes the port number in Xportnr.call delete("Xportnr")if len(a:args) == 1let arg = ' ' . a:args[0]elselet arg = ''endiflet pycmd = s:python . " " . a:cmd . argtrylet g:currentJob = RunCommand(pycmd)" Wait for up to 2 seconds for the port number to be there.let port = GetPort()if port == 0call assert_false(1, "Can't start " . a:cmd)returnendifcall call(function(a:testfunc), [port])catchcall assert_false(1, 'Caught exception: "' . v:exception . '" in ' . v:throwpoint)finallycall s:kill_server(a:cmd)endtryendfuncfunc s:kill_server(cmd)if has('job')if exists('g:currentJob')call job_stop(g:currentJob)unlet g:currentJobendifelseif has('win32')let cmd = substitute(a:cmd, ".py", '', '')call system('taskkill /IM ' . s:python . ' /T /F /FI "WINDOWTITLE eq ' . cmd . '"')elsecall system("pkill -f " . a:cmd)endifendfunc" Wait for up to a second for "expr" to become true." Return time slept in milliseconds. With the +reltime feature this can be" more than the actual waiting time. Without +reltime it can also be less.func WaitFor(expr)" using reltime() is more accurate, but not always availableif has('reltime')let start = reltime()elselet slept = 0endiffor i in range(100)tryif eval(a:expr)if has('reltime')return float2nr(reltimefloat(reltime(start)) * 1000)endifreturn sleptendifcatchendtryif !has('reltime')let slept += 10endifsleep 10mendforreturn 1000endfunc" Wait for up to a given milliseconds." With the +timers feature this waits for key-input by getchar(), Resume()" feeds key-input and resumes process. Return time waited in milliseconds." Without +timers it uses simply :sleep.func Standby(msec)if has('timers')let start = reltime()let g:_standby_timer = timer_start(a:msec, function('s:feedkeys'))call getchar()return float2nr(reltimefloat(reltime(start)) * 1000)elseexecute 'sleep ' a:msec . 'm'return a:msecendifendfuncfunc Resume()if exists('g:_standby_timer')call timer_stop(g:_standby_timer)call s:feedkeys(0)unlet g:_standby_timerendifendfuncfunc s:feedkeys(timer)call feedkeys('x', 'nt')endfunc" Run Vim, using the "vimcmd" file and "-u NORC"." "before" is a list of Vim commands to be executed before loading plugins." "after" is a list of Vim commands to be executed after loading plugins." Plugins are not loaded, unless 'loadplugins' is set in "before"." Return 1 if Vim could be executed.func RunVim(before, after, arguments)return RunVimPiped(a:before, a:after, a:arguments, '')endfuncfunc RunVimPiped(before, after, arguments, pipecmd)if !filereadable('vimcmd')return 0endiflet args = ''if len(a:before) > 0call writefile(a:before, 'Xbefore.vim')let args .= ' --cmd "so Xbefore.vim"'endifif len(a:after) > 0call writefile(a:after, 'Xafter.vim')let args .= ' -S Xafter.vim'endiflet cmd = readfile('vimcmd')[0]let cmd = substitute(cmd, '-u \f\+', '-u NONE', '')if cmd !~ '-u NONE'let cmd = cmd . ' -u NONE'endif" With pipecmd we can't set VIMRUNTIME.if a:pipecmd != ''let cmd = substitute(cmd, 'VIMRUNTIME=.*VIMRUNTIME;', '', '')endifexe "silent !" . a:pipecmd . cmd . args . ' ' . a:argumentsif len(a:before) > 0call delete('Xbefore.vim')endifif len(a:after) > 0call delete('Xafter.vim')endifreturn 1endfunc
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。