Add negative test for type of job's env option

This commit is contained in:
James McCoy 2019-12-12 07:26:39 -05:00
parent 39963c6a04
commit 91b313a904
No known key found for this signature in database
GPG Key ID: DFE691AE331BA3DB
2 changed files with 21 additions and 8 deletions

View File

@ -12630,17 +12630,18 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
return; return;
} }
} }
dictitem_T *item; dictitem_T *job_env = tv_dict_find(job_opts, S_LEN("env"));
item = tv_dict_find(job_opts, S_LEN("env")); if (job_env) {
if (item) { if (job_env->di_tv.v_type != VAR_DICT) {
size_t custom_env_size = (size_t)tv_dict_len(item->di_tv.vval.v_dict);
size_t i = 0;
size_t env_size = 0;
if (item->di_tv.v_type != VAR_DICT) {
EMSG2(_(e_invarg2), "env"); EMSG2(_(e_invarg2), "env");
shell_free_argv(argv);
return; return;
} }
size_t custom_env_size = (size_t)tv_dict_len(job_env->di_tv.vval.v_dict);
size_t i = 0;
size_t env_size = 0;
if (clear_env) { if (clear_env) {
// + 1 for last null entry // + 1 for last null entry
env = xmalloc((custom_env_size + 1) * sizeof(*env)); env = xmalloc((custom_env_size + 1) * sizeof(*env));
@ -12655,7 +12656,7 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
} }
assert(env); // env must be allocated at this point assert(env); // env must be allocated at this point
TV_DICT_ITER(item->di_tv.vval.v_dict, var, { TV_DICT_ITER(job_env->di_tv.vval.v_dict, var, {
const char *str = tv_get_string(&var->di_tv); const char *str = tv_get_string(&var->di_tv);
assert(str); assert(str);
size_t len = STRLEN(var->di_key) + strlen(str) + strlen("=") + 1; size_t len = STRLEN(var->di_key) + strlen(str) + strlen("=") + 1;

View File

@ -49,6 +49,18 @@ describe('jobs', function()
]]) ]])
end) end)
it('must specify env option as a dict', function()
command("let g:job_opts.env = v:true")
local _, err = pcall(function()
if iswin() then
nvim('command', "let j = jobstart('set', g:job_opts)")
else
nvim('command', "let j = jobstart('env', g:job_opts)")
end
end)
ok(string.find(err, "E475: Invalid argument: env") ~= nil)
end)
it('append environment #env', function() it('append environment #env', function()
nvim('command', "let $VAR = 'abc'") nvim('command', "let $VAR = 'abc'")
nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}")