test: new test for setting environment

This commit is contained in:
Matthieu Coudron 2018-11-09 23:55:47 +09:00 committed by James McCoy
parent 4598e489c7
commit f3fcaedfad
No known key found for this signature in database
GPG Key ID: DFE691AE331BA3DB

View File

@ -26,6 +26,7 @@ describe('jobs', function()
before_each(function() before_each(function()
clear() clear()
channel = nvim('get_api_info')[1] channel = nvim('get_api_info')[1]
nvim('set_var', 'channel', channel) nvim('set_var', 'channel', channel)
source([[ source([[
@ -48,6 +49,45 @@ describe('jobs', function()
]]) ]])
end) 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() it('uses &shell and &shellcmdflag if passed a string', function()
nvim('command', "let $VAR = 'abc'") nvim('command', "let $VAR = 'abc'")
if iswin() then if iswin() then