aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/system_spec.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2025-07-02 12:08:48 +0100
committerLewis Russell <me@lewisr.dev>2025-07-02 17:01:29 +0100
commit4eebc46930008d7cf47491121556ee201e1f4860 (patch)
tree03cf369b044a12b4ac0a87af9b2be12c7dc6232b /test/functional/lua/system_spec.lua
parente91224bfaa043bb85cdfa6394f417e400522ff53 (diff)
downloadrneovim-4eebc46930008d7cf47491121556ee201e1f4860.tar.gz
rneovim-4eebc46930008d7cf47491121556ee201e1f4860.tar.bz2
rneovim-4eebc46930008d7cf47491121556ee201e1f4860.zip
fix(vim.system): env=nil passes env=nil to uv.spawn
731e616a79 made it so passing `{env = nil, clear_env = true }` would pass `{env = {}}` to `vim.uv.spawn`. However this is not what `clear_env` is (arguably) supposed to do. If `env=nil` then that implies the uses wants `vim.uv.spawn()` to use the default environment. Adding `clear_env = true` simply prevents `NVIM` (the base environment) from being added. Fixes #34730
Diffstat (limited to 'test/functional/lua/system_spec.lua')
-rw-r--r--test/functional/lua/system_spec.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/functional/lua/system_spec.lua b/test/functional/lua/system_spec.lua
index 97972698a6..7016ffbc59 100644
--- a/test/functional/lua/system_spec.lua
+++ b/test/functional/lua/system_spec.lua
@@ -93,6 +93,27 @@ describe('vim.system', function()
)
end)
+ it('can set environment with clear_env = true and env = nil', function()
+ exec_lua(function()
+ vim.env.TEST = 'TESTVAL'
+ end)
+
+ -- Not passing env with clear_env should not clear the environment
+ eq(
+ 'TESTVAL',
+ system({ n.testprg('printenv-test'), 'TEST' }, { clear_env = true, text = true }).stdout
+ )
+
+ -- Passing env = {} with clear_env should clear the environment
+ eq(
+ '',
+ system(
+ { n.testprg('printenv-test'), 'TEST' },
+ { env = {}, clear_env = true, text = true }
+ ).stdout
+ )
+ end)
+
it('supports timeout', function()
eq({
code = 124,