Create tests for CtrlP

This commit is contained in:
ZyX 2015-01-06 00:02:03 +03:00
parent aa456e415b
commit d8307b03ae
4 changed files with 122 additions and 0 deletions

View File

@ -42,6 +42,15 @@ fi
archive="${PWD:-$(pwd)}/tests/bot-ci/deps/fish/fish.tar.gz"
sudo sh -c "cd /opt && tar xzf $archive"
mkdir tests/vim-plugins
for archive in "$ROOT"/tests/bot-ci/deps/vim-plugins/*.tar.gz ; do
(
cd tests/vim-plugins
tar -xzvf "$archive"
)
done
# Travis has too outdated fish. It cannot be used for tests.
# sudo apt-get install fish
true

View File

@ -0,0 +1,18 @@
# vim:fileencoding=utf-8:noet
import json
import vim
from powerline.lib.unicode import u
_powerline_old_render = powerline.render # NOQA
def _powerline_test_render_function(*args, **kwargs):
ret = _powerline_old_render(*args, **kwargs)
vim.eval('add(g:statusline_values, %s)' % json.dumps(u(ret)))
return ret
powerline.render = _powerline_test_render_function # NOQA

17
tests/test_ctrlp_plugin.vim Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/vim -S
set nocompatible
set columns=80
execute 'source' fnameescape(expand('<sfile>:p:h').'/vim_utils.vim')
call EnablePlugins('ctrlp')
call SourcePowerline()
let g:statusline_values = []
call PyFile('setup_statusline_catcher')
execute 'CtrlP'|call feedkeys("\<C-c>")
call RunPython('powerline.render = _powerline_old_render')
let g:expected_statusline = '%#Pl_231_16777215_236_3158064_NONE# mru  %#Pl_236_3158064_240_5789784_NONE# %#Pl_231_16777215_240_5789784_bold#  files    %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE# buf                                          prt  path '
if index(g:statusline_values, g:expected_statusline) == -1
call CheckStatuslineValue(g:statusline_values[-1], g:expected_statusline)
cquit
endif
call CheckMessages()
qall

78
tests/vim_utils.vim Normal file
View File

@ -0,0 +1,78 @@
let g:powerline_use_var_handler = 1
let g:root=expand('<sfile>:p:h:h')
let g:mf=g:root.'/message.fail'
command -nargs=1 LST :call writefile(<args>, g:mf) | cquit
command -nargs=1 ERR :LST [<args>]
command -nargs=1 EXC :ERR 'Unexpected exception', <q-args>, v:exception, v:throwpoint
function EnablePlugins(...)
let &runtimepath = join(map(copy(a:000), 'escape(g:root."/tests/vim-plugins/".v:val, "\\,")'), ',')
try
runtime! plugin/*.vim
silent doautocmd BufWinEnter
silent doautocmd BufEnter
silent doautocmd VimEnter
catch
EXC EnablePlugins
endtry
endfunction
function RecordStatusline()
let g:statusline = &l:statusline
if g:statusline[:1] is# '%!'
let g:statusline_value=eval(g:statusline[2:])
else
ERR 'Statusline does not start with %!', g:statusline
endif
return ''
endfunction
function SourcePowerline()
let g:powerline_config_paths = [g:root . '/powerline/config_files']
try
execute 'source' fnameescape(g:root . '/powerline/bindings/vim/plugin/powerline.vim')
catch
EXC SourcePowerline
endtry
endfunction
function NDiff(actual, expected)
return systemlist(shellescape(g:root.'/tests/bot-ci/scripts/ndiff-strings.py').' '.shellescape(a:actual).' '.shellescape(a:expected))
endfunction
function CheckStatuslineValue(actual, expected)
if a:actual isnot# a:expected
LST ['Expected different statusline value', a:actual, a:expected] + NDiff(a:actual, a:expected)
endif
endfunction
function CheckRecordedStatuslineValue(expected)
return CheckStatuslineValue(g:statusline_value, a:expected)
endfunction
function CheckMessages()
if !empty(g:powerline_log_messages)
LST ['Unexpected messages in log'] + g:powerline_log_messages
endif
redir => mes
messages
redir END
let mesl = split(mes, "\n")[1:]
if !empty(mesl)
LST ['Unexpected messages'] + split(mes, "\n", 1)
endif
endfunction
function RunPython(s)
if has('python')
execute 'python' a:s
else
execute 'python3' a:s
endif
endfunction
function PyFile(f)
if has('python')
execute 'pyfile' fnameescape(g:root.'/tests/'.a:f.'.py')
else
execute 'py3file' fnameescape(g:root.'/tests/'.a:f.'.py')
endif
endfunction
for s:c in ['noremap', 'noremap!']
execute s:c '<special><expr>' '<Plug>(PowerlineTestRecordStatusline)' 'RecordStatusline()'
endfor