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/write_spec.lua | |
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/write_spec.lua')
-rw-r--r-- | test/functional/ex_cmds/write_spec.lua | 18 |
1 files changed, 8 insertions, 10 deletions
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) |