mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 09:12:07 +00:00
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:
@@ -19,7 +19,6 @@ local meths = helpers.meths
|
|||||||
local mkdir = helpers.mkdir
|
local mkdir = helpers.mkdir
|
||||||
local sleep = helpers.sleep
|
local sleep = helpers.sleep
|
||||||
local read_file = helpers.read_file
|
local read_file = helpers.read_file
|
||||||
local tmpname = helpers.tmpname
|
|
||||||
local trim = helpers.trim
|
local trim = helpers.trim
|
||||||
local currentdir = helpers.funcs.getcwd
|
local currentdir = helpers.funcs.getcwd
|
||||||
local assert_alive = helpers.assert_alive
|
local assert_alive = helpers.assert_alive
|
||||||
@@ -266,9 +265,7 @@ describe('tmpdir', function()
|
|||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
-- Fake /tmp dir so that we can mess it up.
|
-- Fake /tmp dir so that we can mess it up.
|
||||||
os_tmpdir = tmpname()
|
os_tmpdir = vim.loop.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX')
|
||||||
os.remove(os_tmpdir)
|
|
||||||
mkdir(os_tmpdir)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
after_each(function()
|
after_each(function()
|
||||||
|
@@ -3,7 +3,6 @@ local eq = helpers.eq
|
|||||||
local exec_lua = helpers.exec_lua
|
local exec_lua = helpers.exec_lua
|
||||||
local clear = helpers.clear
|
local clear = helpers.clear
|
||||||
local is_os = helpers.is_os
|
local is_os = helpers.is_os
|
||||||
local mkdir = helpers.mkdir
|
|
||||||
|
|
||||||
describe('vim._watch', function()
|
describe('vim._watch', function()
|
||||||
before_each(function()
|
before_each(function()
|
||||||
@@ -12,9 +11,7 @@ describe('vim._watch', function()
|
|||||||
|
|
||||||
describe('watch', function()
|
describe('watch', function()
|
||||||
it('detects file changes', function()
|
it('detects file changes', function()
|
||||||
local root_dir = helpers.tmpname()
|
local root_dir = vim.loop.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX')
|
||||||
os.remove(root_dir)
|
|
||||||
mkdir(root_dir)
|
|
||||||
|
|
||||||
local result = exec_lua(
|
local result = exec_lua(
|
||||||
[[
|
[[
|
||||||
@@ -100,9 +97,7 @@ describe('vim._watch', function()
|
|||||||
|
|
||||||
describe('poll', function()
|
describe('poll', function()
|
||||||
it('detects file changes', function()
|
it('detects file changes', function()
|
||||||
local root_dir = helpers.tmpname()
|
local root_dir = vim.loop.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX')
|
||||||
os.remove(root_dir)
|
|
||||||
mkdir(root_dir)
|
|
||||||
|
|
||||||
local result = exec_lua(
|
local result = exec_lua(
|
||||||
[[
|
[[
|
||||||
|
Reference in New Issue
Block a user