test: system(): Avoid indeterminism.

This commit is contained in:
Justin M. Keyes 2016-10-22 20:40:06 +02:00
parent 8b8db9e158
commit 459a6ff058
3 changed files with 29 additions and 20 deletions

View File

@ -34,7 +34,7 @@
#endif #endif
/// Executes an ex-command. /// Executes an ex-command.
/// VimL error will be returned and v:errmsg updated. /// On VimL error: Returns the VimL error and updates v:errmsg.
/// ///
/// @param command Ex-command string /// @param command Ex-command string
/// @param[out] err Error details (including actual VimL error), if any /// @param[out] err Error details (including actual VimL error), if any
@ -48,7 +48,7 @@ void nvim_command(String command, Error *err)
} }
/// Passes input keys to Nvim. /// Passes input keys to Nvim.
/// Does not fail on VimL error, but v:errmsg will be updated. /// On VimL error: Does not fail, but updates v:errmsg.
/// ///
/// @param keys to be typed /// @param keys to be typed
/// @param mode mapping options /// @param mode mapping options
@ -105,7 +105,7 @@ void nvim_feedkeys(String keys, String mode, Boolean escape_csi)
} }
/// Passes keys to Nvim as raw user-input. /// Passes keys to Nvim as raw user-input.
/// Does not fail on VimL error, but v:errmsg will be updated. /// On VimL error: Does not fail, but updates v:errmsg.
/// ///
/// Unlike `nvim_feedkeys`, this uses a lower-level input buffer and the call /// Unlike `nvim_feedkeys`, this uses a lower-level input buffer and the call
/// is not deferred. This is the most reliable way to emulate real user input. /// is not deferred. This is the most reliable way to emulate real user input.
@ -158,7 +158,7 @@ String nvim_command_output(String str, Error *err)
/// Evaluates a VimL expression (:help expression). /// Evaluates a VimL expression (:help expression).
/// Dictionaries and Lists are recursively expanded. /// Dictionaries and Lists are recursively expanded.
/// VimL error returns a generic error. v:errmsg is not updated. /// On VimL error: Returns a generic error; v:errmsg is not updated.
/// ///
/// @param expr VimL expression string /// @param expr VimL expression string
/// @param[out] err Error details, if any /// @param[out] err Error details, if any
@ -185,7 +185,7 @@ Object nvim_eval(String expr, Error *err)
} }
/// Calls a VimL function with the given arguments. /// Calls a VimL function with the given arguments.
/// VimL error returns a generic error. v:errmsg is not updated. /// On VimL error: Returns a generic error; v:errmsg is not updated.
/// ///
/// @param fname Function to call /// @param fname Function to call
/// @param args Function arguments packed in an Array /// @param args Function arguments packed in an Array
@ -235,7 +235,7 @@ free_vim_args:
} }
/// Calculates the number of display cells occupied by `text`. /// Calculates the number of display cells occupied by `text`.
/// Tab is counted as one cell. /// <Tab> counts as one cell.
/// ///
/// @param text Some text /// @param text Some text
/// @param[out] err Error details, if any /// @param[out] err Error details, if any
@ -344,7 +344,7 @@ void nvim_del_current_line(Error *err)
buffer_del_line(curbuf->handle, curwin->w_cursor.lnum - 1, err); buffer_del_line(curbuf->handle, curwin->w_cursor.lnum - 1, err);
} }
/// Gets a global variable /// Gets a global (g:) variable
/// ///
/// @param name Variable name /// @param name Variable name
/// @param[out] err Error details, if any /// @param[out] err Error details, if any
@ -354,7 +354,7 @@ Object nvim_get_var(String name, Error *err)
return dict_get_value(&globvardict, name, err); return dict_get_value(&globvardict, name, err);
} }
/// Sets a global variable /// Sets a global (g:) variable
/// ///
/// @param name Variable name /// @param name Variable name
/// @param value Variable value /// @param value Variable value
@ -364,7 +364,7 @@ void nvim_set_var(String name, Object value, Error *err)
dict_set_value(&globvardict, name, value, false, false, err); dict_set_value(&globvardict, name, value, false, false, err);
} }
/// Removes a global variable /// Removes a global (g:) variable
/// ///
/// @param name Variable name /// @param name Variable name
/// @param[out] err Error details, if any /// @param[out] err Error details, if any
@ -447,8 +447,8 @@ void nvim_err_write(String str)
write_msg(str, true); write_msg(str, true);
} }
/// Writes a message to vim error buffer. To ensure all contents are written, /// Writes a message to vim error buffer. Appends a linefeed to ensure all
/// a trailing linefeed is appended. /// contents are written.
/// ///
/// @param str Message /// @param str Message
/// @see nvim_err_write() /// @see nvim_err_write()

View File

@ -1,6 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local eq, clear, eval, feed, nvim = local eq, clear, eval, execute, feed, nvim =
helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.nvim helpers.eq, helpers.clear, helpers.eval, helpers.execute, helpers.feed,
helpers.nvim
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
@ -117,8 +118,12 @@ describe('system()', function()
eq("echoed", eval('system("echo -n echoed")')) eq("echoed", eval('system("echo -n echoed")'))
end) end)
it('to backgrounded command does not crash', function() it('to backgrounded command does not crash', function()
-- This is indeterminate, just exercise the codepath. -- This is indeterminate, just exercise the codepath. May get E5677.
eval('system("echo -n echoed &")') execute('call system("echo -n echoed &")')
local v_errnum = string.match(eval("v:errmsg"), "^E%d*:")
if v_errnum then
eq("E5677:", v_errnum)
end
eq(2, eval("1+1")) -- Still alive? eq(2, eval("1+1")) -- Still alive?
end) end)
end) end)
@ -128,8 +133,12 @@ describe('system()', function()
eq("input", eval('system("cat -", "input")')) eq("input", eval('system("cat -", "input")'))
end) end)
it('to backgrounded command does not crash', function() it('to backgrounded command does not crash', function()
-- This is indeterminate, just exercise the codepath. -- This is indeterminate, just exercise the codepath. May get E5677.
eval('system("cat - &", "input")') execute('call system("cat - &")')
local v_errnum = string.match(eval("v:errmsg"), "^E%d*:")
if v_errnum then
eq("E5677:", v_errnum)
end
eq(2, eval("1+1")) -- Still alive? eq(2, eval("1+1")) -- Still alive?
end) end)
end) end)