aboutsummaryrefslogtreecommitdiff
path: root/test/functional/vimscript/ctx_functions_spec.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2021-09-19 02:29:37 -0700
committerGitHub <noreply@github.com>2021-09-19 02:29:37 -0700
commit2afbce7651f79b0626ebeae3688274ce18ac2920 (patch)
treecb1e074962bdfc8ed00bf68775fc1fa0dbca6214 /test/functional/vimscript/ctx_functions_spec.lua
parent924e8e4f2d88ee5c45e521e9f758b7c9f247a011 (diff)
downloadrneovim-2afbce7651f79b0626ebeae3688274ce18ac2920.tar.gz
rneovim-2afbce7651f79b0626ebeae3688274ce18ac2920.tar.bz2
rneovim-2afbce7651f79b0626ebeae3688274ce18ac2920.zip
refactor(tests): remove redir_exec #15718
Problem - `redir_exec` is obsolete, but it keeps getting used in new tests because people copy existing tests. - Disadvantages of `redir_exec`: - Captures extra junk before the actual error/message that we _want_ to test. - Does not fail on error, unlike e.g. `command()`. Solution - Use new functions like `nvim_exec` and `pcall_err`.
Diffstat (limited to 'test/functional/vimscript/ctx_functions_spec.lua')
-rw-r--r--test/functional/vimscript/ctx_functions_spec.lua38
1 files changed, 17 insertions, 21 deletions
diff --git a/test/functional/vimscript/ctx_functions_spec.lua b/test/functional/vimscript/ctx_functions_spec.lua
index f23adbc556..d92a81c55b 100644
--- a/test/functional/vimscript/ctx_functions_spec.lua
+++ b/test/functional/vimscript/ctx_functions_spec.lua
@@ -9,7 +9,7 @@ local feed = helpers.feed
local map = helpers.tbl_map
local nvim = helpers.nvim
local parse_context = helpers.parse_context
-local redir_exec = helpers.redir_exec
+local exec_capture = helpers.exec_capture
local source = helpers.source
local trim = helpers.trim
local write_file = helpers.write_file
@@ -163,33 +163,29 @@ describe('context functions', function()
endfunction
]])
- eq('\nHello, World!', redir_exec([[call Greet('World')]]))
- eq('\nHello, World!'..
+ eq('Hello, World!', exec_capture([[call Greet('World')]]))
+ eq('Hello, World!'..
'\nHello, One!'..
'\nHello, Two!'..
'\nHello, Three!',
- redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]]))
+ exec_capture([[call GreetAll('World', 'One', 'Two', 'Three')]]))
call('SaveSFuncs')
call('DeleteSFuncs')
- eq('\nError detected while processing function Greet:'..
- '\nline 1:'..
- '\nE117: Unknown function: s:greet',
- redir_exec([[call Greet('World')]]))
- eq('\nError detected while processing function GreetAll:'..
- '\nline 1:'..
- '\nE117: Unknown function: s:greet_all',
- redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]]))
+ eq('Vim(call):E117: Unknown function: s:greet',
+ pcall_err(command, [[call Greet('World')]]))
+ eq('Vim(call):E117: Unknown function: s:greet_all',
+ pcall_err(command, [[call GreetAll('World', 'One', 'Two', 'Three')]]))
call('RestoreFuncs')
- eq('\nHello, World!', redir_exec([[call Greet('World')]]))
- eq('\nHello, World!'..
+ eq('Hello, World!', exec_capture([[call Greet('World')]]))
+ eq('Hello, World!'..
'\nHello, One!'..
'\nHello, Two!'..
'\nHello, Three!',
- redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]]))
+ exec_capture([[call GreetAll('World', 'One', 'Two', 'Three')]]))
end)
it('saves and restores functions properly', function()
@@ -206,12 +202,12 @@ describe('context functions', function()
endfunction
]])
- eq('\nHello, World!', redir_exec([[call Greet('World')]]))
- eq('\nHello, World!'..
+ eq('Hello, World!', exec_capture([[call Greet('World')]]))
+ eq('Hello, World!'..
'\nHello, One!'..
'\nHello, Two!'..
'\nHello, Three!',
- redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]]))
+ exec_capture([[call GreetAll('World', 'One', 'Two', 'Three')]]))
call('ctxpush', {'funcs'})
command('delfunction Greet')
@@ -223,12 +219,12 @@ describe('context functions', function()
call('ctxpop')
- eq('\nHello, World!', redir_exec([[call Greet('World')]]))
- eq('\nHello, World!'..
+ eq('Hello, World!', exec_capture([[call Greet('World')]]))
+ eq('Hello, World!'..
'\nHello, One!'..
'\nHello, Two!'..
'\nHello, Three!',
- redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]]))
+ exec_capture([[call GreetAll('World', 'One', 'Two', 'Three')]]))
end)
it('errors out when context stack is empty', function()