test(fs): get tmpdir robustly #23021

Problem:
helpers.tmpname() may create a local file, depending on circumstances.

Solution:
Only use helpers.tmpname() for its parent directory (the "temp root").
Use fs_mkdtemp() to actually get a unique name.
This commit is contained in:
kylo252
2023-07-16 14:50:10 +02:00
committed by GitHub
parent c3de6524a5
commit f660b79480
2 changed files with 3 additions and 11 deletions

View File

@@ -19,7 +19,6 @@ local meths = helpers.meths
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 assert_alive = helpers.assert_alive
@@ -266,9 +265,7 @@ describe('tmpdir', function()
before_each(function()
-- Fake /tmp dir so that we can mess it up.
os_tmpdir = tmpname()
os.remove(os_tmpdir)
mkdir(os_tmpdir)
os_tmpdir = vim.loop.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX')
end)
after_each(function()