summaryrefslogtreecommitdiffstatshomepage
path: root/test/functional/vimscript
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2026-04-18 11:15:01 -0400
committerGitHub <noreply@github.com>2026-04-18 11:15:01 -0400
commita306cd70283f61d20b6fddcbe752c307571b5ade (patch)
tree03d9b898be8d5fba70ada1065f257b113faf591b /test/functional/vimscript
parent48d11681c2c108e34be088cf2f6ce6cc753fa57f (diff)
parent6701b4533144a9f94ab0b4ae3c24f90b29e6b5f8 (diff)
Merge #39176 from justinmk/luavimfn
Diffstat (limited to 'test/functional/vimscript')
-rw-r--r--test/functional/vimscript/environ_spec.lua32
1 files changed, 26 insertions, 6 deletions
diff --git a/test/functional/vimscript/environ_spec.lua b/test/functional/vimscript/environ_spec.lua
index abb093a6c8..9046d2d696 100644
--- a/test/functional/vimscript/environ_spec.lua
+++ b/test/functional/vimscript/environ_spec.lua
@@ -11,17 +11,37 @@ local command = n.command
local eval = n.eval
local setenv = n.fn.setenv
-describe('environment variables', function()
- it('environ() handles empty env variable', function()
+describe('vim.fn.environ()', function()
+ it('exists() handles empty env variable', function()
+ clear({ env = { EMPTY_VAR = '' } })
+ eq(1, exists('$EMPTY_VAR'))
+ eq(0, exists('$DOES_NOT_EXIST'))
+ end)
+
+ it('handles empty env variable', function()
clear({ env = { EMPTY_VAR = '' } })
eq('', environ()['EMPTY_VAR'])
+ -- vim.env returns nil if the value is empty string. 🤷
+ eq(vim.NIL, n.exec_lua('return vim.env.EMPTY_VAR'))
eq(nil, environ()['DOES_NOT_EXIST'])
+ eq(vim.NIL, n.exec_lua('return vim.env.DOES_NOT_EXIST'))
end)
- it('exists() handles empty env variable', function()
- clear({ env = { EMPTY_VAR = '' } })
- eq(1, exists('$EMPTY_VAR'))
- eq(0, exists('$DOES_NOT_EXIST'))
+ it('results match getenv()', function()
+ clear()
+ eq(
+ true,
+ n.exec_lua([[
+ local env = vim.fn.environ()
+ assert(vim.tbl_count(env) > 10, 'environ() should have some env vars!')
+ for k, v in pairs(env) do
+ if v ~= '' and vim.fn.getenv(k) ~= v then
+ error(('environ()[%q] = %q, but vim.fn.getenv(%q) = %q'):format(k, v, k, vim.fn.getenv(k)))
+ end
+ end
+ return true
+ ]])
+ )
end)
end)