aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-02-24 20:09:14 +0100
committerJustin M. Keyes <justinkz@gmail.com>2019-02-27 23:29:07 +0100
commit89515304e4eb81ff9eb65f3a582136fc658de139 (patch)
tree24b445c4aa5588772aa98f830f4646a738727810 /test
parent1d8e7683604828592bd41cdac5a351145cd93487 (diff)
downloadrneovim-89515304e4eb81ff9eb65f3a582136fc658de139.tar.gz
rneovim-89515304e4eb81ff9eb65f3a582136fc658de139.tar.bz2
rneovim-89515304e4eb81ff9eb65f3a582136fc658de139.zip
os/env: use libuv v1.12 getenv/setenv API
- Minimum required libuv is now v1.12 - Because `uv_os_getenv` requires allocating, we must manage a map (`envmap` in `env.c`) to maintain the old behavior of `os_getenv` . - free() map-items after removal. khash.h does not make copies of anything, so even its keys must be memory-managed by the caller. closes #8398 closes #9267
Diffstat (limited to 'test')
-rw-r--r--test/unit/helpers.lua12
-rw-r--r--test/unit/os/env_spec.lua79
2 files changed, 63 insertions, 28 deletions
diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua
index f8143a0125..beb25f25db 100644
--- a/test/unit/helpers.lua
+++ b/test/unit/helpers.lua
@@ -645,16 +645,16 @@ local function itp_child(wr, func)
s = s:sub(1, hook_msglen - 2)
sc.write(wr, '>' .. s .. (' '):rep(hook_msglen - 2 - #s) .. '\n')
end
- local err, emsg = pcall(init)
- if err then
+ local status, result = pcall(init)
+ if status then
collectgarbage('stop')
child_sethook(wr)
- err, emsg = pcall(func)
+ status, result = pcall(func)
debug.sethook()
end
- emsg = tostring(emsg)
sc.write(wr, trace_end_msg)
- if not err then
+ if not status then
+ local emsg = tostring(result)
if #emsg > 99999 then
emsg = emsg:sub(1, 99999)
end
@@ -668,7 +668,7 @@ local function itp_child(wr, func)
collectgarbage()
sc.write(wr, '$\n')
sc.close(wr)
- sc.exit(err and 0 or 1)
+ sc.exit(status and 0 or 1)
end
local function check_child_err(rd)
diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua
index c54d5a9b77..c543551607 100644
--- a/test/unit/os/env_spec.lua
+++ b/test/unit/os/env_spec.lua
@@ -8,17 +8,22 @@ local ffi = helpers.ffi
local cstr = helpers.cstr
local to_cstr = helpers.to_cstr
local NULL = helpers.NULL
+local OK = 0
require('lfs')
local cimp = cimport('./src/nvim/os/os.h')
describe('env.c', function()
+ local function os_env_exists(name)
+ return cimp.os_env_exists(to_cstr(name))
+ end
+
local function os_setenv(name, value, override)
return cimp.os_setenv(to_cstr(name), to_cstr(value), override)
end
- local function os_unsetenv(name, _, _)
+ local function os_unsetenv(name)
return cimp.os_unsetenv(to_cstr(name))
end
@@ -31,25 +36,44 @@ describe('env.c', function()
end
end
- describe('os_setenv', function()
- local OK = 0
+ itp('os_env_exists', function()
+ eq(false, os_env_exists(''))
+ eq(false, os_env_exists(' '))
+ eq(false, os_env_exists('\t'))
+ eq(false, os_env_exists('\n'))
+ eq(false, os_env_exists('AaあB <= very weird name...'))
- itp('sets an env variable and returns OK', function()
+ local varname = 'NVIM_UNIT_TEST_os_env_exists'
+ eq(false, os_env_exists(varname))
+ eq(OK, os_setenv(varname, 'foo bar baz ...', 1))
+ eq(true, os_env_exists(varname))
+ end)
+
+ describe('os_setenv', function()
+ itp('sets an env var and returns success', function()
local name = 'NVIM_UNIT_TEST_SETENV_1N'
local value = 'NVIM_UNIT_TEST_SETENV_1V'
eq(nil, os.getenv(name))
- eq(OK, (os_setenv(name, value, 1)))
+ eq(OK, os_setenv(name, value, 1))
eq(value, os.getenv(name))
+
+ -- Set empty, then set non-empty, then retrieve.
+ eq(OK, os_setenv(name, '', 1))
+ eq('', os.getenv(name))
+ eq(OK, os_setenv(name, 'non-empty', 1))
+ eq('non-empty', os.getenv(name))
end)
- itp("dosn't overwrite an env variable if overwrite is 0", function()
+ itp("`overwrite` behavior", function()
local name = 'NVIM_UNIT_TEST_SETENV_2N'
local value = 'NVIM_UNIT_TEST_SETENV_2V'
local value_updated = 'NVIM_UNIT_TEST_SETENV_2V_UPDATED'
- eq(OK, (os_setenv(name, value, 0)))
+ eq(OK, os_setenv(name, value, 0))
eq(value, os.getenv(name))
- eq(OK, (os_setenv(name, value_updated, 0)))
+ eq(OK, os_setenv(name, value_updated, 0))
eq(value, os.getenv(name))
+ eq(OK, os_setenv(name, value_updated, 1))
+ eq(value_updated, os.getenv(name))
end)
end)
@@ -93,31 +117,42 @@ describe('env.c', function()
end)
describe('os_getenv', function()
- itp('reads an env variable', function()
+ itp('reads an env var', function()
local name = 'NVIM_UNIT_TEST_GETENV_1N'
local value = 'NVIM_UNIT_TEST_GETENV_1V'
eq(NULL, os_getenv(name))
-- Use os_setenv because Lua dosen't have setenv.
os_setenv(name, value, 1)
eq(value, os_getenv(name))
+
+ -- Get a big value.
+ local bigval = ('x'):rep(256)
+ eq(OK, os_setenv(name, bigval, 1))
+ eq(bigval, os_getenv(name))
+
+ -- Set non-empty, then set empty.
+ eq(OK, os_setenv(name, 'non-empty', 1))
+ eq('non-empty', os_getenv(name))
+ eq(OK, os_setenv(name, '', 1))
+ eq(NULL, os_getenv(name))
end)
- itp('returns NULL if the env variable is not found', function()
- local name = 'NVIM_UNIT_TEST_GETENV_NOTFOUND'
- return eq(NULL, os_getenv(name))
+ itp('returns NULL if the env var is not found', function()
+ eq(NULL, os_getenv('NVIM_UNIT_TEST_GETENV_NOTFOUND'))
end)
end)
- describe('os_unsetenv', function()
- itp('unsets environment variable', function()
- local name = 'TEST_UNSETENV'
- local value = 'TESTVALUE'
- os_setenv(name, value, 1)
- os_unsetenv(name)
- neq(os_getenv(name), value)
- -- Depending on the platform the var might be unset or set as ''
- assert.True(os_getenv(name) == nil or os_getenv(name) == '')
- end)
+ itp('os_unsetenv', function()
+ local name = 'TEST_UNSETENV'
+ local value = 'TESTVALUE'
+ os_setenv(name, value, 1)
+ eq(OK, os_unsetenv(name))
+ neq(os_getenv(name), value)
+ -- Depending on the platform the var might be unset or set as ''
+ assert.True(os_getenv(name) == nil or os_getenv(name) == '')
+ if os_getenv(name) == nil then
+ eq(false, os_env_exists(name))
+ end
end)
describe('os_getenvname_at_index', function()