aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/vim_spec.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-01-05 11:17:21 +0100
committerJustin M. Keyes <justinkz@gmail.com>2018-01-10 23:45:44 +0100
commitc095f83116eb8ef87983ca5fea61053755fbc4e5 (patch)
tree82be0f4aa1a50be3703a91236d1913462fd6a28a /test/functional/api/vim_spec.lua
parentf0845197d868735dc97aac72738b69c639c634b3 (diff)
downloadrneovim-c095f83116eb8ef87983ca5fea61053755fbc4e5.tar.gz
rneovim-c095f83116eb8ef87983ca5fea61053755fbc4e5.tar.bz2
rneovim-c095f83116eb8ef87983ca5fea61053755fbc4e5.zip
api: change nvim_command_output behavior
Implement nvim_command_output with `execute({cmd},"silent")`. Behavior changes: - does not provoke any hit-enter prompt - no longer prepends a newline char - does not capture some noise (like the "[New File]" message, see the change to tabnewentered_spec.lua) Technically ("bug-for-bug") this a breaking change. But the previous behavior of nvim_command_output meant that it probably wasn't used for anything outside of tests. Also remove the undocumented `v:command_output` variable which was a hack introduced only for the purposes of nvim_command_output. closes #7726
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r--test/functional/api/vim_spec.lua53
1 files changed, 52 insertions, 1 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index ff28e3d133..d213c3c34e 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -37,7 +37,7 @@ describe('api', function()
os.remove(fname)
end)
- it("VimL error: fails (VimL error), does NOT update v:errmsg", function()
+ it("parse error: fails (specific error), does NOT update v:errmsg", function()
-- Most API methods return generic errors (or no error) if a VimL
-- expression fails; nvim_command returns the VimL error details.
local status, rv = pcall(nvim, "command", "bogus_command")
@@ -45,6 +45,57 @@ describe('api', function()
eq("E492:", string.match(rv, "E%d*:")) -- VimL error was returned.
eq("", nvim("eval", "v:errmsg")) -- v:errmsg was not updated.
end)
+
+ it("runtime error: fails (specific error)", function()
+ local status, rv = pcall(nvim, "command_output", "buffer 23487")
+ eq(false, status) -- nvim_command() failed.
+ eq("E86: Buffer 23487 does not exist", string.match(rv, "E%d*:.*"))
+ eq("", nvim("eval", "v:errmsg")) -- v:errmsg was not updated.
+ end)
+ end)
+
+ describe('nvim_command_output', function()
+ it('does not induce hit-enter prompt', function()
+ -- Induce a hit-enter prompt use nvim_input (non-blocking).
+ nvim('command', 'set cmdheight=1')
+ nvim('input', [[:echo "hi\nhi2"<CR>]])
+
+ -- Verify hit-enter prompt.
+ eq({mode='r', blocking=true}, nvim("get_mode"))
+ nvim('input', [[<C-c>]])
+
+ -- Verify NO hit-enter prompt.
+ nvim('command_output', [[echo "hi\nhi2"]])
+ eq({mode='n', blocking=false}, nvim("get_mode"))
+ end)
+
+ it('returns command output', function()
+ eq('this is\nspinal tap',
+ nvim('command_output', [[echo "this is\nspinal tap"]]))
+ end)
+
+ it('does not return shell |:!| output', function()
+ eq(':!echo "foo"\r\n', nvim('command_output', [[!echo "foo"]]))
+ end)
+
+ it("parse error: fails (specific error), does NOT update v:errmsg", function()
+ local status, rv = pcall(nvim, "command_output", "bogus commannnd")
+ eq(false, status) -- nvim_command_output() failed.
+ eq("E492: Not an editor command: bogus commannnd",
+ string.match(rv, "E%d*:.*"))
+ eq("", nvim("eval", "v:errmsg")) -- v:errmsg was not updated.
+ -- Verify NO hit-enter prompt.
+ eq({mode='n', blocking=false}, nvim("get_mode"))
+ end)
+
+ it("runtime error: fails (specific error)", function()
+ local status, rv = pcall(nvim, "command_output", "buffer 42")
+ eq(false, status) -- nvim_command_output() failed.
+ eq("E86: Buffer 42 does not exist", string.match(rv, "E%d*:.*"))
+ eq("", nvim("eval", "v:errmsg")) -- v:errmsg was not updated.
+ -- Verify NO hit-enter prompt.
+ eq({mode='n', blocking=false}, nvim("get_mode"))
+ end)
end)
describe('nvim_eval', function()