mirror of
https://github.com/neovim/neovim.git
synced 2025-10-09 19:36:40 +00:00
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
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user