diff options
Diffstat (limited to 'test/functional/core/job_spec.lua')
-rw-r--r-- | test/functional/core/job_spec.lua | 58 |
1 files changed, 53 insertions, 5 deletions
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 9c37e55f42..e5d4444b92 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -26,6 +26,7 @@ describe('jobs', function() before_each(function() clear() + channel = nvim('get_api_info')[1] nvim('set_var', 'channel', channel) source([[ @@ -48,6 +49,57 @@ 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'}") + if iswin() then + nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) + else + nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) + end + + expect_msg_seq({ + {'notification', 'stdout', {0, {'hello world abc', ''}}}, + }) + end) + + it('replace environment #env', function() + nvim('command', "let $VAR = 'abc'") + nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") + nvim('command', "let g:job_opts.clear_env = 1") + + -- libuv ensures that certain "required" environment variables are + -- preserved if the user doesn't provide them in a custom environment + -- https://github.com/libuv/libuv/blob/635e0ce6073c5fbc96040e336b364c061441b54b/src/win/process.c#L672 + -- https://github.com/libuv/libuv/blob/635e0ce6073c5fbc96040e336b364c061441b54b/src/win/process.c#L48-L60 + -- + -- Rather than expecting a completely empty environment, ensure that $VAR + -- is *not* in the environment but $TOTO is. + if iswin() then + nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) + expect_msg_seq({ + {'notification', 'stdout', {0, {'hello world %VAR%', ''}}} + }) + else + nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) + expect_msg_seq({ + {'notification', 'stdout', {0, {'hello world', ''}}} + }) + end + end) + it('uses &shell and &shellcmdflag if passed a string', function() nvim('command', "let $VAR = 'abc'") if iswin() then @@ -202,8 +254,7 @@ describe('jobs', function() if helpers.isCI('travis') and os.getenv('CC') == 'gcc-4.9' and helpers.is_os('mac') then -- XXX: Hangs Travis macOS since e9061117a5b8f195c3f26a5cb94e18ddd7752d86. - pending("[Hangs on Travis macOS. #5002]", function() end) - return + pending("[Hangs on Travis macOS. #5002]") end nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") @@ -963,9 +1014,6 @@ describe("pty process teardown", function() | ]]) end) - after_each(function() - screen:detach() - end) it("does not prevent/delay exit. #4798 #4900", function() if helpers.pending_win32(pending) then return end |