summaryrefslogtreecommitdiffstats
path: root/tests/test_vim
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/test_vim/pyfiles/setup_statusline_catcher.py18
-rwxr-xr-xtests/test_vim/test.sh60
-rwxr-xr-xtests/test_vim/tests/commandt_plugin.vim17
-rwxr-xr-xtests/test_vim/tests/empty_encoding.old.vim32
-rw-r--r--tests/test_vim/tests/foreign_stl_override.vim22
-rw-r--r--tests/test_vim/tests/invalid_unicode.vim19
-rwxr-xr-xtests/test_vim/tests/local_overrides.vim48
-rwxr-xr-xtests/test_vim/tests/nerdtree_plugin.vim11
-rwxr-xr-xtests/test_vim/tests/plugin_file.vim22
-rwxr-xr-xtests/test_vim/tests/tabline.vim56
-rw-r--r--tests/test_vim/vim_utils.vim88
11 files changed, 393 insertions, 0 deletions
diff --git a/tests/test_vim/pyfiles/setup_statusline_catcher.py b/tests/test_vim/pyfiles/setup_statusline_catcher.py
new file mode 100644
index 0000000..014a2e9
--- /dev/null
+++ b/tests/test_vim/pyfiles/setup_statusline_catcher.py
@@ -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
diff --git a/tests/test_vim/test.sh b/tests/test_vim/test.sh
new file mode 100755
index 0000000..ecd0285
--- /dev/null
+++ b/tests/test_vim/test.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+. tests/shlib/common.sh
+. tests/shlib/vterm.sh
+. tests/shlib/vim.sh
+
+enter_suite vim final
+
+vterm_setup vim
+
+# Define some overrides. These ones must be ignored and do not affect Vim
+# status/tab lines.
+export POWERLINE_CONFIG_OVERRIDES='common.default_top_theme=ascii'
+export POWERLINE_THEME_OVERRIDES='default.segments.left=[]'
+
+test_script() {
+ local vim="$1" ; shift
+ local script="$1" ; shift
+ local allow_failure_arg="$1" ; shift
+ echo "Running script $script with $vim"
+ if ! test -e "$vim" ; then
+ return 0
+ fi
+ if ! script="$script" "$vim" -u NONE -c 'source $script' \
+ || test -f message.fail
+ then
+ local test_name="${script##*/}"
+ fail $allow_failure_arg "${test_name%.vim}" \
+ F "Failed script $script run with $vim"
+ if test -e message.fail ; then
+ cat message.fail >&2
+ rm message.fail
+ fi
+ fi
+}
+
+TEST_SCRIPT_ROOT="$ROOT/tests/test_vim/tests"
+
+cd "$TEST_ROOT"
+
+for script in "$TEST_SCRIPT_ROOT"/*.vim ; do
+ if test "${script%.old.vim}" = "${script}" ; then
+ test_script "$NEW_VIM" "$script" ""
+ fi
+done
+
+if test "$PYTHON_VERSION_MAJOR.$PYTHON_VERSION_MINOR" = "2.7" ; then
+ ALLOW_FAILURE_ARG=--allow-failure
+else
+ ALLOW_FAILURE_ARG=
+fi
+
+if test -e "$OLD_VIM" ; then
+ for script in "$TEST_SCRIPT_ROOT"/*.old.vim ; do
+ test_script "$OLD_VIM" "$script" "$ALLOW_FAILURE_ARG"
+ done
+fi
+
+vterm_shutdown
+
+exit_suite
diff --git a/tests/test_vim/tests/commandt_plugin.vim b/tests/test_vim/tests/commandt_plugin.vim
new file mode 100755
index 0000000..9f944b9
--- /dev/null
+++ b/tests/test_vim/tests/commandt_plugin.vim
@@ -0,0 +1,17 @@
+#!/usr/bin/vim -S
+set nocompatible
+set columns=80
+execute 'source' fnameescape(expand('<sfile>:p:h:h').'/vim_utils.vim')
+call EnablePlugins('command-t')
+call SourcePowerline()
+let g:statusline_values = []
+call PyFile('setup_statusline_catcher')
+execute 'CommandTBuffer'|call feedkeys("\<C-c>")
+call RunPython('powerline.render = _powerline_old_render')
+let g:expected_statusline = '%#Pl_231_16777215_240_5789784_bold# Command-T %#Pl_231_16777215_240_5789784_NONE# %#Pl_231_16777215_240_5789784_bold#BufferFinder %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                                    '
+call CheckMessages()
+if index(g:statusline_values, g:expected_statusline) == -1
+ call CheckStatuslineValue(get(g:statusline_values, -1, ''), g:expected_statusline)
+ cquit
+endif
+qall
diff --git a/tests/test_vim/tests/empty_encoding.old.vim b/tests/test_vim/tests/empty_encoding.old.vim
new file mode 100755
index 0000000..124a10a
--- /dev/null
+++ b/tests/test_vim/tests/empty_encoding.old.vim
@@ -0,0 +1,32 @@
+#!/usr/bin/vim -S
+if has('multi_byte')
+ if empty(&encoding)
+ call writefile(['&encoding option value is empty, even though Vim has +multibyte'], 'message.fail')
+ cquit
+ endif
+ qall
+endif
+if !empty(&encoding)
+ call writefile(['&encoding option value is not empty, even though Vim does not have +multibyte'], 'message.fail')
+ cquit
+endif
+
+let g:powerline_config_paths = [expand('<sfile>:p:h:h:h:h') . '/powerline/config_files']
+
+try
+ source <sfile>:p:h:h:h:h/powerline/bindings/vim/plugin/powerline.vim
+catch
+ call writefile(['Unexpected exception:', v:exception], 'message.fail')
+ cquit
+endtry
+set ls=2
+redrawstatus!
+redir => g:messages
+ messages
+redir END
+let mess=split(g:messages, "\n")
+if len(mess)>1
+ call writefile(['Unexpected message(s):']+mess, 'message.fail')
+ cquit
+endif
+qall!
diff --git a/tests/test_vim/tests/foreign_stl_override.vim b/tests/test_vim/tests/foreign_stl_override.vim
new file mode 100644
index 0000000..2a5b8c0
--- /dev/null
+++ b/tests/test_vim/tests/foreign_stl_override.vim
@@ -0,0 +1,22 @@
+scriptencoding utf-8
+set encoding=utf-8
+let g:powerline_config_paths = [expand('<sfile>:p:h:h:h:h') . '/powerline/config_files']
+set laststatus=2
+redir => g:messages
+ try
+ source <sfile>:p:h:h:h:h/powerline/bindings/vim/plugin/powerline.vim
+ redrawstatus!
+ vsplit
+ redrawstatus!
+ setlocal statusline=«»
+ redrawstatus!
+ catch
+ call writefile(['Unexpected exception', v:exception], 'message.fail')
+ cquit
+ endtry
+redir END
+if g:messages =~# '\v\S'
+ call writefile(['Unexpected messages'] + split(g:messages, "\n", 1), 'message.fail')
+ cquit
+endif
+qall!
diff --git a/tests/test_vim/tests/invalid_unicode.vim b/tests/test_vim/tests/invalid_unicode.vim
new file mode 100644
index 0000000..ac91f3c
--- /dev/null
+++ b/tests/test_vim/tests/invalid_unicode.vim
@@ -0,0 +1,19 @@
+set encoding=utf-8
+let g:powerline_config_paths = [expand('<sfile>:p:h:h:h:h') . '/powerline/config_files']
+set laststatus=2
+set showtabline=2
+edit `="\xFF"`
+redir => g:messages
+ try
+ source <sfile>:p:h:h:h:h/powerline/bindings/vim/plugin/powerline.vim
+ redrawstatus!
+ catch
+ call writefile(['Unexpected exception', v:exception], 'message.fail')
+ cquit
+ endtry
+redir END
+if g:messages =~# '\v\S'
+ call writefile(['Unexpected messages'] + split(g:messages, "\n", 1), 'message.fail')
+ cquit
+endif
+qall!
diff --git a/tests/test_vim/tests/local_overrides.vim b/tests/test_vim/tests/local_overrides.vim
new file mode 100755
index 0000000..aba14e2
--- /dev/null
+++ b/tests/test_vim/tests/local_overrides.vim
@@ -0,0 +1,48 @@
+#!/usr/bin/vim -S
+set encoding=utf-8
+let g:powerline_config_paths = [expand('<sfile>:p:h:h:h:h') . '/powerline/config_files']
+let g:powerline_config_overrides = {'common': {'default_top_theme': 'ascii'}}
+let g:powerline_theme_overrides = {'default': {'segment_data': {'line_current_symbol': {'contents': 'LN '}, 'branch': {'before': 'B '}}}}
+
+redir => g:messages
+
+try
+ python import powerline.vim
+ let pycmd = 'python'
+catch
+ try
+ python3 import powerline.vim
+ let pycmd = 'python3'
+ catch
+ call writefile(['Unable to determine python version', v:exception], 'message.fail')
+ cquit
+ endtry
+endtry
+
+try
+ execute pycmd 'powerline.vim.setup()'
+catch
+ call writefile(['Failed to run setup function', v:exception], 'message.fail')
+ cquit
+endtry
+
+try
+ let &columns = 80
+ let result = eval(&statusline[2:])
+catch
+ call writefile(['Exception while evaluating &stl', v:exception], 'message.fail')
+ cquit
+endtry
+
+if result isnot# '%#Pl_22_24320_148_11523840_bold# NORMAL %#Pl_148_11523840_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE# %#Pl_247_10395294_236_3158064_NONE#unix%#Pl_240_5789784_236_3158064_NONE# %#Pl_247_10329757_240_5789784_NONE# 100%%%#Pl_252_13684944_240_5789784_NONE# %#Pl_235_2500134_252_13684944_NONE# LN %#Pl_235_2500134_252_13684944_bold# 1%#Pl_22_24576_252_13684944_NONE#:1 '
+ call writefile(['Unexpected result', result], 'message.fail')
+ cquit
+endif
+
+redir END
+if g:messages =~ '\S'
+ call writefile(['Non-empty messages:', g:messages], 'message.fail')
+ cquit
+endif
+
+qall!
diff --git a/tests/test_vim/tests/nerdtree_plugin.vim b/tests/test_vim/tests/nerdtree_plugin.vim
new file mode 100755
index 0000000..761cb5f
--- /dev/null
+++ b/tests/test_vim/tests/nerdtree_plugin.vim
@@ -0,0 +1,11 @@
+#!/usr/bin/vim -S
+set nocompatible
+set columns=80
+execute 'source' fnameescape(expand('<sfile>:p:h:h').'/vim_utils.vim')
+call EnablePlugins('nerdtree')
+call SourcePowerline()
+NERDTree /home
+redrawstatus
+call CheckCurrentStatusline('%#Pl_231_16777215_240_5789784_bold# /home %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                      ')
+call CheckMessages()
+qall
diff --git a/tests/test_vim/tests/plugin_file.vim b/tests/test_vim/tests/plugin_file.vim
new file mode 100755
index 0000000..1848933
--- /dev/null
+++ b/tests/test_vim/tests/plugin_file.vim
@@ -0,0 +1,22 @@
+#!/usr/bin/vim -S
+set encoding=utf-8
+let g:powerline_config_paths = [expand('<sfile>:p:h:h:h:h') . '/powerline/config_files']
+tabedit abc
+tabedit def
+try
+ source <sfile>:p:h:h:h:h/powerline/bindings/vim/plugin/powerline.vim
+catch
+ call writefile([v:exception], 'message.fail')
+ cquit
+endtry
+set ls=2
+redrawstatus!
+redir =>mes
+ messages
+redir END
+let mess=split(mes, "\n")
+if len(mess)>1
+ call writefile(mess, 'message.fail')
+ cquit
+endif
+qall!
diff --git a/tests/test_vim/tests/tabline.vim b/tests/test_vim/tests/tabline.vim
new file mode 100755
index 0000000..ff76dc0
--- /dev/null
+++ b/tests/test_vim/tests/tabline.vim
@@ -0,0 +1,56 @@
+#!/usr/bin/vim -S
+set encoding=utf-8
+let g:powerline_config_paths = [expand('<sfile>:p:h:h:h:h') . '/powerline/config_files']
+source <sfile>:p:h:h:h:h/powerline/bindings/vim/plugin/powerline.vim
+edit abc
+tabedit def
+tabedit ghi
+
+redir => g:messages
+
+try
+ let &columns = 80
+ let result = eval(&tabline[2:])
+catch
+ call writefile(['Exception while evaluating &tabline', v:exception], 'message.fail')
+ cquit
+endtry
+
+if result isnot# '%1T%#Pl_247_10395294_236_3158064_NONE# 1 ./abc %#Pl_244_8421504_236_3158064_NONE# %2T%#Pl_247_10395294_236_3158064_NONE#2 ./def %#Pl_236_3158064_240_5789784_NONE# %3T%#Pl_250_12369084_240_5789784_NONE#3 ./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %T%#Pl_231_16777215_236_3158064_NONE#                                         %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Tabs '
+ call writefile(['Unexpected tabline', result], 'message.fail')
+ cquit
+endif
+
+tabonly!
+
+try
+ let result = eval(&tabline[2:])
+catch
+ call writefile(['Exception while evaluating &tabline (2)', v:exception], 'message.fail')
+ cquit
+endtry
+
+if result isnot# '%T%#Pl_247_10395294_236_3158064_NONE# 1 ./abc %#Pl_244_8421504_236_3158064_NONE# %#Pl_247_10395294_236_3158064_NONE#2 ./def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#3 ./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                         %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Bufs '
+ call writefile(['Unexpected tabline (2)', result], 'message.fail')
+ cquit
+endif
+
+try
+ vsplit
+ let result = eval(&tabline[2:])
+catch
+ call writefile(['Exception while evaluating &tabline (3)', v:exception], 'message.fail')
+endtry
+
+if result isnot# '%T%#Pl_247_10395294_236_3158064_NONE# 1 ./abc %#Pl_244_8421504_236_3158064_NONE# %#Pl_247_10395294_236_3158064_NONE#2 ./def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#3 ./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                         %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Bufs '
+ call writefile(['Unexpected tabline (3)', result], 'message.fail')
+ cquit
+endif
+
+redir END
+if g:messages =~ '\S'
+ call writefile(['Non-empty messages:', g:messages], 'message.fail')
+ cquit
+endif
+
+qall!
diff --git a/tests/test_vim/vim_utils.vim b/tests/test_vim/vim_utils.vim
new file mode 100644
index 0000000..6219ec4
--- /dev/null
+++ b/tests/test_vim/vim_utils.vim
@@ -0,0 +1,88 @@
+let g:powerline_use_var_handler = 1
+
+let g:pyfiles_root=expand('<sfile>:p:h').'/pyfiles'
+let g:root=expand('<sfile>:p:h:h:h')
+let g:mf=fnamemodify('message.fail', ':p')
+
+command -nargs=1 LST :call writefile(<args>, g:mf, 'a') | 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 GetCurrentStatusline()
+ if &l:statusline[:1] isnot# '%!'
+ ERR 'Statusline does not start with %!', &l:statusline
+ endif
+ return eval(&l:statusline[2:])
+endfunction
+function CheckCurrentStatusline(expected)
+ return CheckStatuslineValue(GetCurrentStatusline(), 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:pyfiles_root.'/'.a:f.'.py')
+ else
+ execute 'py3file' fnameescape(g:pyfiles_root.'/'.a:f.'.py')
+ endif
+endfunction
+
+for s:c in ['noremap', 'noremap!']
+ execute s:c '<special><expr>' '<Plug>(PowerlineTestRecordStatusline)' 'RecordStatusline()'
+endfor