diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2022-06-30 13:16:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-30 04:16:46 -0700 |
commit | f50135a32e11c535e1dc3a8e9460c5b4e640ee86 (patch) | |
tree | 4531a75f5f099877cb8d672743abf03004171f4f /test/functional | |
parent | 514e76e4b2903530922529c60bfbf32cadd257a3 (diff) | |
download | rneovim-f50135a32e11c535e1dc3a8e9460c5b4e640ee86.tar.gz rneovim-f50135a32e11c535e1dc3a8e9460c5b4e640ee86.tar.bz2 rneovim-f50135a32e11c535e1dc3a8e9460c5b4e640ee86.zip |
feat: stdpath('run'), /tmp/nvim.user/ #18993
Problem:
- Since c57f6b28d71d #8519, sockets are created in ~/.local/… but XDG
spec says: "XDG_RUNTIME_DIR: Must be on the local filesystem", which
implies that XDG_STATE_DIR is potentially non-local.
- Not easy to inspect Nvim-created temp files (for debugging etc).
Solution:
- Store sockets in stdpath('run') ($XDG_RUNTIME_DIR).
- Establish "/tmp/nvim.user/" as the tempdir root shared by all Nvims.
- Make ok() actually useful.
- Introduce assert_nolog().
closes #3517
closes #17093
Diffstat (limited to 'test/functional')
-rw-r--r-- | test/functional/api/server_requests_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/core/fileio_spec.lua | 72 | ||||
-rw-r--r-- | test/functional/core/startup_spec.lua | 3 | ||||
-rw-r--r-- | test/functional/options/defaults_spec.lua | 8 | ||||
-rw-r--r-- | test/functional/terminal/api_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/vimscript/server_spec.lua | 17 | ||||
-rw-r--r-- | test/functional/vimscript/timer_spec.lua | 2 |
7 files changed, 101 insertions, 7 deletions
diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index cdcf08c348..00a4dd041d 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -170,7 +170,7 @@ describe('server -> client', function() if method == "notification" then eq('done!', eval('rpcrequest('..cid..', "nested")')) elseif method == "nested_done" then - ok(false, 'this should never have been sent') + ok(false, 'never sent', 'sent') end end diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index bc025771d1..a4d22685e8 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -1,22 +1,28 @@ local helpers = require('test.functional.helpers')(after_each) +local assert_log = helpers.assert_log +local assert_nolog = helpers.assert_nolog local clear = helpers.clear local command = helpers.command local eq = helpers.eq +local ok = helpers.ok local feed = helpers.feed local funcs = helpers.funcs local nvim_prog = helpers.nvim_prog local request = helpers.request local retry = helpers.retry local rmdir = helpers.rmdir +local matches = helpers.matches local mkdir = helpers.mkdir local sleep = helpers.sleep local read_file = helpers.read_file +local tmpname = helpers.tmpname local trim = helpers.trim local currentdir = helpers.funcs.getcwd local iswin = helpers.iswin local assert_alive = helpers.assert_alive local expect_exit = helpers.expect_exit +local write_file = helpers.write_file describe('fileio', function() before_each(function() @@ -140,3 +146,69 @@ describe('fileio', function() end) end) +describe('tmpdir', function() + local tmproot_pat = [=[.*[/\\]nvim%.[^/\\]+]=] + local testlog = 'Xtest_tmpdir_log' + local faketmp + + before_each(function() + -- Fake /tmp dir so that we can mess it up. + faketmp = tmpname() + os.remove(faketmp) + mkdir(faketmp) + end) + + after_each(function() + expect_exit(command, ':qall!') + os.remove(testlog) + end) + + it('failure modes', function() + clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=faketmp, } }) + assert_nolog('tempdir is not a directory', testlog) + assert_nolog('tempdir has invalid permissions', testlog) + + -- Tempfiles typically look like: "…/nvim.<user>/xxx/0". + -- - "…/nvim.<user>/xxx/" is the per-process tmpdir, not shared with other Nvims. + -- - "…/nvim.<user>/" is the tmpdir root, shared by all Nvims (normally). + local tmproot = (funcs.tempname()):match(tmproot_pat) + ok(tmproot:len() > 4, 'tmproot like "nvim.foo"', tmproot) + + -- Test how Nvim handles invalid tmpdir root (by hostile users or accidents). + -- + -- "…/nvim.<user>/" is not a directory: + expect_exit(command, ':qall!') + rmdir(tmproot) + write_file(tmproot, '') -- Not a directory, vim_mktempdir() should skip it. + clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=faketmp, } }) + matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). + -- Assert that broken tmpdir root was handled. + retry(nil, 1000, function() + assert_log('tempdir root not a directory', testlog, 100) + end) + + -- "…/nvim.<user>/" has wrong permissions: + if iswin() then + return -- TODO(justinmk): need setfperm/getfperm on Windows. #8244 + end + os.remove(testlog) + os.remove(tmproot) + mkdir(tmproot) + funcs.setfperm(tmproot, 'rwxr--r--') -- Invalid permissions, vim_mktempdir() should skip it. + clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=faketmp, } }) + matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). + -- Assert that broken tmpdir root was handled. + retry(nil, 1000, function() + assert_log('tempdir root has invalid permissions', testlog, 100) + end) + end) + + it('too long', function() + local bigname = ('%s/%s'):format(faketmp, ('x'):rep(666)) + mkdir(bigname) + clear({ env={ NVIM_LOG_FILE=testlog, TMPDIR=bigname, } }) + matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). + local len = (funcs.tempname()):len() + ok(len > 4 and len < 256, '4 < len < 256', tostring(len)) + end) +end) diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 5ba80a3646..fc9ea72ff2 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -399,7 +399,8 @@ describe('startup', function() eq({'ordinary', 'FANCY', 'mittel', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]]) local rtp = meths.get_option'rtp' - ok(startswith(rtp, 'test/functional/fixtures/nvim,test/functional/fixtures/pack/*/start/*,test/functional/fixtures/start/*,test/functional/fixtures,test/functional/fixtures/middle,'), 'rtp='..rtp) + ok(startswith(rtp, 'test/functional/fixtures/nvim,test/functional/fixtures/pack/*/start/*,test/functional/fixtures/start/*,test/functional/fixtures,test/functional/fixtures/middle,'), + 'startswith(…)', 'rtp='..rtp) end) it("handles the correct order with opt packages and after/", function() diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index 92873e9937..9244ca0974 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -9,6 +9,7 @@ local clear = helpers.clear local exc_exec = helpers.exc_exec local eval = helpers.eval local eq = helpers.eq +local ok = helpers.ok local funcs = helpers.funcs local insert = helpers.insert local iswin = helpers.iswin @@ -238,7 +239,7 @@ describe('startup defaults', function() end) end) -describe('XDG-based defaults', function() +describe('XDG defaults', function() -- Need separate describe() blocks to not run clear() twice. -- Do not put before_each() here for the same reasons. @@ -282,6 +283,7 @@ describe('XDG-based defaults', function() eq('.', meths.get_option('viewdir')) eq('.', meths.get_option('directory')) eq('.', meths.get_option('undodir')) + ok((funcs.tempname()):len() > 4) end) end) @@ -306,6 +308,7 @@ describe('XDG-based defaults', function() .. env_sep.. root_path .. ('/b'):rep(2048) .. (env_sep .. root_path .. '/c'):rep(512)), XDG_DATA_HOME=(root_path .. ('/X'):rep(4096)), + XDG_RUNTIME_DIR=(root_path .. ('/X'):rep(4096)), XDG_STATE_HOME=(root_path .. ('/X'):rep(4096)), XDG_DATA_DIRS=(root_path .. ('/A'):rep(2048) .. env_sep .. root_path .. ('/B'):rep(2048) @@ -376,6 +379,7 @@ describe('XDG-based defaults', function() XDG_CONFIG_HOME='$XDG_DATA_HOME', XDG_CONFIG_DIRS='$XDG_DATA_DIRS', XDG_DATA_HOME='$XDG_CONFIG_HOME', + XDG_RUNTIME_DIR='$XDG_RUNTIME_DIR', XDG_STATE_HOME='$XDG_CONFIG_HOME', XDG_DATA_DIRS='$XDG_CONFIG_DIRS', }}) @@ -438,6 +442,7 @@ describe('XDG-based defaults', function() meths.get_option('undodir'):gsub('\\', '/')) eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'), meths.get_option('viewdir'):gsub('\\', '/')) + eq(nil, (funcs.tempname()):match('XDG_RUNTIME_DIR')) end) end) @@ -519,6 +524,7 @@ describe('stdpath()', function() eq(statedir, funcs.fnamemodify(funcs.stdpath('state'), ':t')) eq('table', type(funcs.stdpath('config_dirs'))) eq('table', type(funcs.stdpath('data_dirs'))) + eq('string', type(funcs.stdpath('run'))) assert_alive() -- Check for crash. #8393 end) diff --git a/test/functional/terminal/api_spec.lua b/test/functional/terminal/api_spec.lua index b3a0b8a2c8..5305b8af9c 100644 --- a/test/functional/terminal/api_spec.lua +++ b/test/functional/terminal/api_spec.lua @@ -48,8 +48,8 @@ describe('api', function() {3:-- TERMINAL --} | ]]) - ok(socket_session1:request("nvim_ui_attach", 42, 6, {rgb=true})) - ok(socket_session2:request("nvim_ui_attach", 25, 30, {rgb=true})) + ok((socket_session1:request("nvim_ui_attach", 42, 6, {rgb=true}))) + ok((socket_session2:request("nvim_ui_attach", 25, 30, {rgb=true}))) socket_session1:notify("nvim_input", "\n[socket 1] this is more than 25 columns") socket_session2:notify("nvim_input", "\n[socket 2] input") diff --git a/test/functional/vimscript/server_spec.lua b/test/functional/vimscript/server_spec.lua index ea07be231d..6e95459630 100644 --- a/test/functional/vimscript/server_spec.lua +++ b/test/functional/vimscript/server_spec.lua @@ -5,6 +5,7 @@ local iswin = helpers.iswin local ok = helpers.ok local matches = helpers.matches local pcall_err = helpers.pcall_err +local mkdir = helpers.mkdir local function clear_serverlist() for _, server in pairs(funcs.serverlist()) do @@ -13,9 +14,19 @@ local function clear_serverlist() end describe('server', function() - before_each(clear) + it('serverstart() stores sockets in $XDG_RUNTIME_DIR', function() + local dir = 'Xtest_xdg_run' + mkdir(dir) + clear({ env={ XDG_RUNTIME_DIR=dir } }) + matches(dir, funcs.stdpath('run')) + if not iswin() then + matches(dir, funcs.serverstart()) + end + end) + it('serverstart(), serverstop() does not set $NVIM', function() + clear() local s = eval('serverstart()') assert(s ~= nil and s:len() > 0, "serverstart() returned empty") eq('', eval('$NVIM')) @@ -34,6 +45,7 @@ describe('server', function() end) it('sets v:servername at startup or if all servers were stopped', function() + clear() local initial_server = meths.get_vvar('servername') assert(initial_server ~= nil and initial_server:len() > 0, 'v:servername was not initialized') @@ -62,11 +74,13 @@ describe('server', function() end) it('serverstop() returns false for invalid input', function() + clear() eq(0, eval("serverstop('')")) eq(0, eval("serverstop('bogus-socket-name')")) end) it('parses endpoints', function() + clear() clear_serverlist() eq({}, funcs.serverlist()) @@ -111,6 +125,7 @@ describe('server', function() end) it('serverlist() returns the list of servers', function() + clear() -- There should already be at least one server. local n = eval('len(serverlist())') diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index 20f2afb20f..5463cfb234 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -96,7 +96,7 @@ describe('timers', function() nvim_async("command", "let g:val = 0 | let g:c = getchar()") retry(nil, nil, function() local val = eval("g:val") - ok(val >= 2, "expected >= 2, got: "..tostring(val)) + ok(val >= 2, '>= 2', tostring(val)) eq(0, eval("getchar(1)")) end) feed("c") |