2016-06-19 21:39:46 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2016-05-02 21:35:04 -07:00
|
|
|
local eq = helpers.eq
|
|
|
|
local eval = helpers.eval
|
|
|
|
local clear = helpers.clear
|
|
|
|
local source = helpers.source
|
|
|
|
local redir_exec = helpers.redir_exec
|
|
|
|
local exc_exec = helpers.exc_exec
|
|
|
|
local funcs = helpers.funcs
|
|
|
|
local Screen = require('test.functional.ui.screen')
|
2017-01-08 21:13:51 -07:00
|
|
|
local command = helpers.command
|
2017-01-18 13:13:59 -07:00
|
|
|
local feed = helpers.feed
|
2017-05-10 06:04:49 -07:00
|
|
|
local iswin = helpers.iswin
|
2016-05-02 21:35:04 -07:00
|
|
|
|
2016-07-31 10:23:29 -07:00
|
|
|
describe('execute()', function()
|
2016-05-02 21:35:04 -07:00
|
|
|
before_each(clear)
|
|
|
|
|
2016-09-29 17:33:50 -07:00
|
|
|
it('captures the same result as :redir', function()
|
2016-07-31 10:23:29 -07:00
|
|
|
eq(redir_exec('messages'), funcs.execute('messages'))
|
2016-05-02 21:35:04 -07:00
|
|
|
end)
|
|
|
|
|
2016-09-29 17:33:50 -07:00
|
|
|
it('captures the concatenated outputs of a List of commands', function()
|
2016-07-31 10:23:29 -07:00
|
|
|
eq("foobar", funcs.execute({'echon "foo"', 'echon "bar"'}))
|
|
|
|
eq("\nfoo\nbar", funcs.execute({'echo "foo"', 'echo "bar"'}))
|
2016-05-02 21:35:04 -07:00
|
|
|
end)
|
|
|
|
|
2017-01-30 19:40:02 -07:00
|
|
|
it('supports nested execute("execute(...)")', function()
|
|
|
|
eq('42', funcs.execute([[echon execute("echon execute('echon 42')")]]))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('supports nested :redir to a variable', function()
|
2016-05-02 21:35:04 -07:00
|
|
|
source([[
|
|
|
|
function! g:Foo()
|
|
|
|
let a = ''
|
|
|
|
redir => a
|
|
|
|
silent echon "foo"
|
|
|
|
redir END
|
|
|
|
return a
|
|
|
|
endfunction
|
|
|
|
function! g:Bar()
|
|
|
|
let a = ''
|
|
|
|
redir => a
|
2017-01-30 19:40:02 -07:00
|
|
|
silent echon "bar1"
|
2016-05-02 21:35:04 -07:00
|
|
|
call g:Foo()
|
2017-01-30 19:40:02 -07:00
|
|
|
silent echon "bar2"
|
2016-05-02 21:35:04 -07:00
|
|
|
redir END
|
2017-01-30 19:40:02 -07:00
|
|
|
silent echon "bar3"
|
2016-05-02 21:35:04 -07:00
|
|
|
return a
|
|
|
|
endfunction
|
|
|
|
]])
|
2017-01-30 19:40:02 -07:00
|
|
|
eq('top1bar1foobar2bar3', funcs.execute('echon "top1"|call g:Bar()'))
|
|
|
|
end)
|
2016-05-02 21:35:04 -07:00
|
|
|
|
2017-01-30 19:40:02 -07:00
|
|
|
it('supports nested :redir to a register', function()
|
|
|
|
source([[
|
|
|
|
let @a = ''
|
|
|
|
function! g:Foo()
|
|
|
|
redir @a>>
|
|
|
|
silent echon "foo"
|
|
|
|
redir END
|
|
|
|
return @a
|
|
|
|
endfunction
|
|
|
|
function! g:Bar()
|
|
|
|
redir @a>>
|
|
|
|
silent echon "bar1"
|
|
|
|
call g:Foo()
|
|
|
|
silent echon "bar2"
|
|
|
|
redir END
|
|
|
|
silent echon "bar3"
|
|
|
|
return @a
|
|
|
|
endfunction
|
|
|
|
]])
|
|
|
|
eq('top1bar1foobar2bar3', funcs.execute('echon "top1"|call g:Bar()'))
|
|
|
|
-- :redir itself doesn't nest, so the redirection ends in g:Foo
|
|
|
|
eq('bar1foo', eval('@a'))
|
2016-05-02 21:35:04 -07:00
|
|
|
end)
|
|
|
|
|
2016-09-29 17:33:50 -07:00
|
|
|
it('captures a transformed string', function()
|
2016-07-31 10:23:29 -07:00
|
|
|
eq('^A', funcs.execute('echon "\\<C-a>"'))
|
2016-05-02 21:35:04 -07:00
|
|
|
end)
|
|
|
|
|
2016-09-29 17:33:50 -07:00
|
|
|
it('returns empty string if the argument list is empty', function()
|
2016-07-31 10:23:29 -07:00
|
|
|
eq('', funcs.execute({}))
|
|
|
|
eq(0, exc_exec('let g:ret = execute(v:_null_list)'))
|
2016-05-02 21:35:04 -07:00
|
|
|
eq('', eval('g:ret'))
|
|
|
|
end)
|
|
|
|
|
2016-09-29 17:33:50 -07:00
|
|
|
it('captures errors', function()
|
2016-05-02 21:35:04 -07:00
|
|
|
local ret
|
2016-07-31 10:23:29 -07:00
|
|
|
ret = exc_exec('call execute(0.0)')
|
2016-05-02 21:35:04 -07:00
|
|
|
eq('Vim(call):E806: using Float as a String', ret)
|
2016-07-31 10:23:29 -07:00
|
|
|
ret = exc_exec('call execute(v:_null_dict)')
|
2016-05-02 21:35:04 -07:00
|
|
|
eq('Vim(call):E731: using Dictionary as a String', ret)
|
2016-07-31 10:23:29 -07:00
|
|
|
ret = exc_exec('call execute(function("tr"))')
|
2016-05-02 21:35:04 -07:00
|
|
|
eq('Vim(call):E729: using Funcref as a String', ret)
|
2016-07-31 10:23:29 -07:00
|
|
|
ret = exc_exec('call execute(["echo 42", 0.0, "echo 44"])')
|
2017-01-08 21:13:51 -07:00
|
|
|
eq('Vim:E806: using Float as a String', ret)
|
2016-07-31 10:23:29 -07:00
|
|
|
ret = exc_exec('call execute(["echo 42", v:_null_dict, "echo 44"])')
|
2017-01-08 21:13:51 -07:00
|
|
|
eq('Vim:E731: using Dictionary as a String', ret)
|
2016-07-31 10:23:29 -07:00
|
|
|
ret = exc_exec('call execute(["echo 42", function("tr"), "echo 44"])')
|
2017-01-08 21:13:51 -07:00
|
|
|
eq('Vim:E729: using Funcref as a String', ret)
|
2016-05-02 21:35:04 -07:00
|
|
|
end)
|
|
|
|
|
2017-01-18 13:13:59 -07:00
|
|
|
it('captures output with highlights', function()
|
|
|
|
eq('\nErrorMsg xxx ctermfg=15 ctermbg=1 guifg=White guibg=Red',
|
|
|
|
eval('execute("hi ErrorMsg")'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('does not corrupt the command display #5422', function()
|
2018-03-31 02:12:27 -07:00
|
|
|
local screen = Screen.new(70, 7)
|
2017-01-18 13:13:59 -07:00
|
|
|
screen:attach()
|
|
|
|
feed(':echo execute("hi ErrorMsg")<CR>')
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
|
|
|
|
|
{1:~ }|
|
|
|
|
{1:~ }|
|
|
|
|
{2: }|
|
2018-12-11 19:29:10 -07:00
|
|
|
|
|
2017-01-18 13:13:59 -07:00
|
|
|
ErrorMsg xxx ctermfg=15 ctermbg=1 guifg=White guibg=Red |
|
2018-03-31 02:12:27 -07:00
|
|
|
{3:Press ENTER or type command to continue}^ |
|
|
|
|
]], {
|
|
|
|
[1] = {bold = true, foreground = Screen.colors.Blue1},
|
|
|
|
[2] = {bold = true, reverse = true},
|
|
|
|
[3] = {bold = true, foreground = Screen.colors.SeaGreen4},
|
|
|
|
})
|
2017-01-18 13:13:59 -07:00
|
|
|
feed('<CR>')
|
|
|
|
end)
|
|
|
|
|
2018-12-06 07:27:25 -07:00
|
|
|
it('places cursor correctly #6035', function()
|
2018-12-08 02:14:43 -07:00
|
|
|
local screen = Screen.new(40, 6)
|
2018-12-06 07:27:25 -07:00
|
|
|
screen:attach()
|
|
|
|
source([=[
|
2018-12-08 02:14:43 -07:00
|
|
|
" test 1: non-silenced output goes as usual
|
|
|
|
function! Test1()
|
|
|
|
echo 1234
|
|
|
|
let x = execute('echon "abcdef"', '')
|
|
|
|
echon 'ABCD'
|
2018-12-06 07:27:25 -07:00
|
|
|
endfunction
|
|
|
|
|
2018-12-08 02:14:43 -07:00
|
|
|
" test 2: silenced output does not affect ui
|
|
|
|
function! Test2()
|
|
|
|
echo 1234
|
|
|
|
let x = execute('echon "abcdef"', 'silent')
|
|
|
|
echon 'ABCD'
|
2018-12-06 07:27:25 -07:00
|
|
|
endfunction
|
|
|
|
|
2018-12-08 02:14:43 -07:00
|
|
|
" test 3: silenced! error does not affect ui
|
|
|
|
function! Test3()
|
|
|
|
echo 1234
|
|
|
|
let x = execute('echoerr "abcdef"', 'silent!')
|
|
|
|
echon 'ABCD'
|
2018-12-06 07:27:25 -07:00
|
|
|
endfunction
|
|
|
|
|
2018-12-08 02:14:43 -07:00
|
|
|
" test 4: silenced echoerr goes as usual
|
|
|
|
" bug here
|
|
|
|
function! Test4()
|
|
|
|
echo 1234
|
|
|
|
let x = execute('echoerr "abcdef"', 'silent')
|
|
|
|
echon 'ABCD'
|
2018-12-06 07:27:25 -07:00
|
|
|
endfunction
|
|
|
|
|
2018-12-08 02:14:43 -07:00
|
|
|
" test 5: silenced! echoerr does not affect ui
|
|
|
|
function! Test5()
|
|
|
|
echo 1234
|
|
|
|
let x = execute('echoerr "abcdef"', 'silent!')
|
|
|
|
echon 'ABCD'
|
2018-12-06 07:27:25 -07:00
|
|
|
endfunction
|
|
|
|
|
2018-12-08 02:14:43 -07:00
|
|
|
" test 6: silenced error goes as usual
|
|
|
|
function! Test6()
|
|
|
|
echo 1234
|
|
|
|
let x = execute('echo undefined', 'silent')
|
|
|
|
echon 'ABCD'
|
2018-12-06 07:27:25 -07:00
|
|
|
endfunction
|
|
|
|
|
2018-12-08 02:14:43 -07:00
|
|
|
" test 7: existing error does not mess the result
|
|
|
|
function! Test7()
|
|
|
|
" display from Test6() is still visible
|
|
|
|
" why does the "abcdef" goes into a newline
|
|
|
|
let x = execute('echon "abcdef"', '')
|
|
|
|
echon 'ABCD'
|
2018-12-06 07:27:25 -07:00
|
|
|
endfunction
|
|
|
|
]=])
|
|
|
|
|
2018-12-08 02:14:43 -07:00
|
|
|
feed([[:call Test1()<cr>]])
|
2018-12-06 07:27:25 -07:00
|
|
|
screen:expect([[
|
2018-12-08 02:14:43 -07:00
|
|
|
^ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
2018-12-11 19:29:10 -07:00
|
|
|
ABCD |
|
2018-12-06 07:27:25 -07:00
|
|
|
]])
|
|
|
|
|
2018-12-08 02:14:43 -07:00
|
|
|
feed([[:call Test2()<cr>]])
|
2018-12-06 07:27:25 -07:00
|
|
|
screen:expect([[
|
2018-12-08 02:14:43 -07:00
|
|
|
^ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
1234ABCD |
|
2018-12-06 07:27:25 -07:00
|
|
|
]])
|
|
|
|
|
2018-12-08 02:14:43 -07:00
|
|
|
feed([[:call Test3()<cr>]])
|
2018-12-06 07:27:25 -07:00
|
|
|
screen:expect([[
|
2018-12-08 02:14:43 -07:00
|
|
|
^ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
1234ABCD |
|
2018-12-06 07:27:25 -07:00
|
|
|
]])
|
|
|
|
|
2018-12-08 02:14:43 -07:00
|
|
|
feed([[:call Test4()<cr>]])
|
|
|
|
-- unexpected: need to fix
|
|
|
|
-- echoerr does not set did_emsg
|
|
|
|
-- "ef" was overwritten since msg_col was recovered wrongly
|
2018-12-06 07:27:25 -07:00
|
|
|
screen:expect([[
|
2018-12-08 02:14:43 -07:00
|
|
|
1234 |
|
|
|
|
Error detected while processing function|
|
|
|
|
Test4: |
|
|
|
|
line 2: |
|
|
|
|
abcdABCD |
|
2018-12-06 07:27:25 -07:00
|
|
|
Press ENTER or type command to continue^ |
|
|
|
|
]])
|
|
|
|
|
2018-12-08 02:14:43 -07:00
|
|
|
feed([[<cr>]]) -- to clear screen
|
|
|
|
feed([[:call Test5()<cr>]])
|
2018-12-06 07:27:25 -07:00
|
|
|
screen:expect([[
|
2018-12-08 02:14:43 -07:00
|
|
|
^ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
1234ABCD |
|
2018-12-06 07:27:25 -07:00
|
|
|
]])
|
|
|
|
|
2018-12-08 02:14:43 -07:00
|
|
|
feed([[:call Test6()<cr>]])
|
2018-12-06 07:27:25 -07:00
|
|
|
screen:expect([[
|
2018-12-11 19:29:10 -07:00
|
|
|
|
|
2018-12-06 07:27:25 -07:00
|
|
|
Error detected while processing function|
|
2018-12-08 02:14:43 -07:00
|
|
|
Test6: |
|
2018-12-06 07:27:25 -07:00
|
|
|
line 2: |
|
2018-12-11 19:29:10 -07:00
|
|
|
E121ABCD |
|
2018-12-06 07:27:25 -07:00
|
|
|
Press ENTER or type command to continue^ |
|
|
|
|
]])
|
|
|
|
|
2018-12-08 02:14:43 -07:00
|
|
|
feed([[:call Test7()<cr>]])
|
2018-12-06 07:27:25 -07:00
|
|
|
screen:expect([[
|
|
|
|
Error detected while processing function|
|
2018-12-08 02:14:43 -07:00
|
|
|
Test6: |
|
2018-12-06 07:27:25 -07:00
|
|
|
line 2: |
|
2018-12-11 19:29:10 -07:00
|
|
|
E121ABCD |
|
|
|
|
ABCD |
|
2018-12-06 07:27:25 -07:00
|
|
|
Press ENTER or type command to continue^ |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2018-01-21 11:58:19 -07:00
|
|
|
-- This deviates from vim behavior, but is consistent
|
|
|
|
-- with how nvim currently displays the output.
|
2018-12-06 07:27:25 -07:00
|
|
|
it('captures shell-command output', function()
|
2017-05-10 06:04:49 -07:00
|
|
|
local win_lf = iswin() and '\13' or ''
|
2018-01-21 11:58:19 -07:00
|
|
|
eq('\n:!echo foo\r\n\nfoo'..win_lf..'\n', funcs.execute('!echo foo'))
|
2016-09-29 17:33:50 -07:00
|
|
|
end)
|
|
|
|
|
2017-01-08 21:13:51 -07:00
|
|
|
describe('{silent} argument', function()
|
|
|
|
it('captures & displays output for ""', function()
|
|
|
|
local screen = Screen.new(40, 5)
|
|
|
|
screen:attach()
|
|
|
|
command('let g:mes = execute("echon 42", "")')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
42 |
|
|
|
|
]])
|
|
|
|
eq('42', eval('g:mes'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('captures but does not display output for "silent"', function()
|
|
|
|
local screen = Screen.new(40, 5)
|
|
|
|
screen:attach()
|
|
|
|
command('let g:mes = execute("echon 42")')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
eq('42', eval('g:mes'))
|
|
|
|
|
|
|
|
command('let g:mes = execute("echon 13", "silent")')
|
2017-06-26 05:49:15 -07:00
|
|
|
screen:expect{grid=[[
|
2017-01-08 21:13:51 -07:00
|
|
|
^ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
|
|
2017-06-26 05:49:15 -07:00
|
|
|
]], unchanged=true}
|
2017-01-08 21:13:51 -07:00
|
|
|
eq('13', eval('g:mes'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('suppresses errors for "silent!"', function()
|
|
|
|
eq(0, exc_exec('let g:mes = execute(0.0, "silent!")'))
|
|
|
|
eq('', eval('g:mes'))
|
|
|
|
|
|
|
|
eq(0, exc_exec('let g:mes = execute("echon add(1, 1)", "silent!")'))
|
|
|
|
eq('1', eval('g:mes'))
|
|
|
|
|
|
|
|
eq(0, exc_exec('let g:mes = execute(["echon 42", "echon add(1, 1)"], "silent!")'))
|
|
|
|
eq('421', eval('g:mes'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('propagates errors for "" and "silent"', function()
|
|
|
|
local ret
|
|
|
|
ret = exc_exec('call execute(0.0, "")')
|
|
|
|
eq('Vim(call):E806: using Float as a String', ret)
|
|
|
|
|
|
|
|
ret = exc_exec('call execute(v:_null_dict, "silent")')
|
|
|
|
eq('Vim(call):E731: using Dictionary as a String', ret)
|
|
|
|
|
|
|
|
ret = exc_exec('call execute("echo add(1, 1)", "")')
|
|
|
|
eq('Vim(echo):E714: List required', ret)
|
|
|
|
|
|
|
|
ret = exc_exec('call execute(["echon 42", "echo add(1, 1)"], "")')
|
|
|
|
eq('Vim(echo):E714: List required', ret)
|
|
|
|
|
|
|
|
ret = exc_exec('call execute("echo add(1, 1)", "silent")')
|
|
|
|
eq('Vim(echo):E714: List required', ret)
|
|
|
|
|
|
|
|
ret = exc_exec('call execute(["echon 42", "echo add(1, 1)"], "silent")')
|
|
|
|
eq('Vim(echo):E714: List required', ret)
|
|
|
|
end)
|
2016-05-02 21:35:04 -07:00
|
|
|
end)
|
|
|
|
end)
|