From 2afbce7651f79b0626ebeae3688274ce18ac2920 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 19 Sep 2021 02:29:37 -0700 Subject: 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`. --- test/functional/vimscript/ctx_functions_spec.lua | 38 +++++++++++------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'test/functional/vimscript/ctx_functions_spec.lua') 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() -- cgit