diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2021-09-19 02:29:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-19 02:29:37 -0700 |
commit | 2afbce7651f79b0626ebeae3688274ce18ac2920 (patch) | |
tree | cb1e074962bdfc8ed00bf68775fc1fa0dbca6214 /test/functional/ex_cmds | |
parent | 924e8e4f2d88ee5c45e521e9f758b7c9f247a011 (diff) | |
download | rneovim-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/ex_cmds')
-rw-r--r-- | test/functional/ex_cmds/echo_spec.lua | 30 | ||||
-rw-r--r-- | test/functional/ex_cmds/write_spec.lua | 18 |
2 files changed, 19 insertions, 29 deletions
diff --git a/test/functional/ex_cmds/echo_spec.lua b/test/functional/ex_cmds/echo_spec.lua index 404dc39ad2..d320425de1 100644 --- a/test/functional/ex_cmds/echo_spec.lua +++ b/test/functional/ex_cmds/echo_spec.lua @@ -10,7 +10,7 @@ local source = helpers.source local dedent = helpers.dedent local command = helpers.command local exc_exec = helpers.exc_exec -local redir_exec = helpers.redir_exec +local exec_capture = helpers.exec_capture local matches = helpers.matches describe(':echo :echon :echomsg :echoerr', function() @@ -199,10 +199,8 @@ describe(':echo :echon :echomsg :echoerr', function() let d.tdr = TestDictRef ]]) eq(dedent([[ - - function('TestDict', {'tdr': function('TestDict', {...@1})}) function('TestDict', {'tdr': function('TestDict', {...@1})})]]), - redir_exec('echo String(d.tdr)')) + exec_capture('echo String(d.tdr)')) end) it('dumps automatically created partials', function() @@ -229,10 +227,8 @@ describe(':echo :echon :echomsg :echoerr', function() function() meths.set_var('d', {v=true}) eq(dedent([[ - - {'p': function('<SNR>2_Test2', {...@0}), 'f': function('<SNR>2_Test2'), 'v': v:true} {'p': function('<SNR>2_Test2', {...@0}), 'f': function('<SNR>2_Test2'), 'v': v:true}]]), - redir_exec('echo String(extend(extend(g:d, {"f": g:Test2_f}), {"p": g:d.f}))')) + exec_capture('echo String(extend(extend(g:d, {"f": g:Test2_f}), {"p": g:d.f}))')) end) it('does not show errors when dumping partials referencing the same dictionary', @@ -256,10 +252,8 @@ describe(':echo :echon :echomsg :echoerr', function() -- test/unit/api/private_helpers_spec.lua. eval('add(l, function("Test1", l))') eq(dedent([=[ - - function('Test1', [[[...@2], function('Test1', [[...@2]])], function('Test1', [[[...@4], function('Test1', [[...@4]])]])]) function('Test1', [[[...@2], function('Test1', [[...@2]])], function('Test1', [[[...@4], function('Test1', [[...@4]])]])])]=]), - redir_exec('echo String(function("Test1", l))')) + exec_capture('echo String(function("Test1", l))')) end) it('does not crash or halt when dumping partials with reference cycles in self and arguments', @@ -270,10 +264,8 @@ describe(':echo :echon :echomsg :echoerr', function() eval('add(l, function("Test1", l))') eval('add(l, function("Test1", d))') eq(dedent([=[ - - {'p': function('<SNR>2_Test2', [[[...@3], function('Test1', [[...@3]]), function('Test1', {...@0})], function('Test1', [[[...@5], function('Test1', [[...@5]]), function('Test1', {...@0})]]), function('Test1', {...@0})], {...@0}), 'f': function('<SNR>2_Test2'), 'v': v:true} {'p': function('<SNR>2_Test2', [[[...@3], function('Test1', [[...@3]]), function('Test1', {...@0})], function('Test1', [[[...@5], function('Test1', [[...@5]]), function('Test1', {...@0})]]), function('Test1', {...@0})], {...@0}), 'f': function('<SNR>2_Test2'), 'v': v:true}]=]), - redir_exec('echo String(extend(extend(g:d, {"f": g:Test2_f}), {"p": function(g:d.f, l)}))')) + exec_capture('echo String(extend(extend(g:d, {"f": g:Test2_f}), {"p": function(g:d.f, l)}))')) end) end) @@ -303,8 +295,8 @@ describe(':echo :echon :echomsg :echoerr', function() it('dumps recursive lists without error', function() meths.set_var('l', {}) eval('add(l, l)') - eq('\n[[...@0]]\n[[...@0]]', redir_exec('echo String(l)')) - eq('\n[[[...@1]]]\n[[[...@1]]]', redir_exec('echo String([l])')) + eq('[[...@0]]', exec_capture('echo String(l)')) + eq('[[[...@1]]]', exec_capture('echo String([l])')) end) end) @@ -333,10 +325,10 @@ describe(':echo :echon :echomsg :echoerr', function() it('dumps recursive dictionaries without the error', function() meths.set_var('d', {d=1}) eval('extend(d, {"d": d})') - eq('\n{\'d\': {...@0}}\n{\'d\': {...@0}}', - redir_exec('echo String(d)')) - eq('\n{\'out\': {\'d\': {...@1}}}\n{\'out\': {\'d\': {...@1}}}', - redir_exec('echo String({"out": d})')) + eq('{\'d\': {...@0}}', + exec_capture('echo String(d)')) + eq('{\'out\': {\'d\': {...@1}}}', + exec_capture('echo String({"out": d})')) end) end) diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index 4f526ddfca..32fe397c03 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -3,8 +3,7 @@ local lfs = require('lfs') local eq, eval, clear, write_file, source, insert = helpers.eq, helpers.eval, helpers.clear, helpers.write_file, helpers.source, helpers.insert -local redir_exec = helpers.redir_exec -local exc_exec = helpers.exc_exec +local pcall_err = helpers.pcall_err local command = helpers.command local feed_command = helpers.feed_command local funcs = helpers.funcs @@ -96,25 +95,24 @@ describe(':write', function() eq(funcs.fnamemodify('.', ':p:h'), funcs.fnamemodify('.', ':p:h:~')) -- Message from check_overwrite if not iswin() then - eq(('\nE17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'), - redir_exec('write .')) + eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'), + pcall_err(command, 'write .')) end meths.set_option('writeany', true) -- Message from buf_write - eq(('\nE502: "." is a directory'), - redir_exec('write .')) + eq(('Vim(write):E502: "." is a directory'), pcall_err(command, 'write .')) funcs.mkdir(fname_bak) meths.set_option('backupdir', '.') meths.set_option('backup', true) write_file(fname, 'content0') - eq(0, exc_exec('edit ' .. fname)) + command('edit ' .. fname) funcs.setline(1, 'TTY') eq('Vim(write):E510: Can\'t make backup file (add ! to override)', - exc_exec('write')) + pcall_err(command, 'write')) meths.set_option('backup', false) funcs.setfperm(fname, 'r--------') eq('Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)', - exc_exec('write')) + pcall_err(command, 'write')) if iswin() then eq(0, os.execute('del /q/f ' .. fname)) eq(0, os.execute('rd /q/s ' .. fname_bak)) @@ -127,6 +125,6 @@ describe(':write', function() if iswin() then return end lfs.link(fname_bak .. ('/xxxxx'):rep(20), fname, true) eq('Vim(write):E166: Can\'t open linked file for writing', - exc_exec('write!')) + pcall_err(command, 'write!')) end) end) |