diff options
author | James McCoy <jamessan@jamessan.com> | 2019-12-12 07:26:39 -0500 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2019-12-12 07:57:27 -0500 |
commit | 91b313a904c039a9b6a53a7afc9f66e67a1e12fc (patch) | |
tree | 8d889a35b0c52cea3f3a9c465d6c14f23d9e26b8 | |
parent | 39963c6a04afc417a821b2255a5caea4b7955d7d (diff) | |
download | rneovim-91b313a904c039a9b6a53a7afc9f66e67a1e12fc.tar.gz rneovim-91b313a904c039a9b6a53a7afc9f66e67a1e12fc.tar.bz2 rneovim-91b313a904c039a9b6a53a7afc9f66e67a1e12fc.zip |
Add negative test for type of job's env option
-rw-r--r-- | src/nvim/eval.c | 17 | ||||
-rw-r--r-- | test/functional/core/job_spec.lua | 12 |
2 files changed, 21 insertions, 8 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index e498253db1..c14b7f513d 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -12630,17 +12630,18 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv, FunPtr fptr) return; } } - dictitem_T *item; - item = tv_dict_find(job_opts, S_LEN("env")); - if (item) { - 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) { + dictitem_T *job_env = tv_dict_find(job_opts, S_LEN("env")); + if (job_env) { + if (job_env->di_tv.v_type != VAR_DICT) { EMSG2(_(e_invarg2), "env"); + shell_free_argv(argv); 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) { // + 1 for last null entry 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 - 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); assert(str); size_t len = STRLEN(var->di_key) + strlen(str) + strlen("=") + 1; diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index af2299945e..e5d4444b92 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -49,6 +49,18 @@ describe('jobs', function() ]]) 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() nvim('command', "let $VAR = 'abc'") nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") |