aboutsummaryrefslogtreecommitdiff
path: root/test/testutil.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-09-02 19:14:09 +0200
committerJustin M. Keyes <justinkz@gmail.com>2024-09-02 20:19:50 +0200
commit137f98cf6428a55b1b7687c151d8481c1deb9347 (patch)
tree043b7c4cd4d1b0f89352d48b9f6c62ed08b91a9d /test/testutil.lua
parentef8067a19d981388a14407ea08245811cf5b3604 (diff)
downloadrneovim-137f98cf6428a55b1b7687c151d8481c1deb9347.tar.gz
rneovim-137f98cf6428a55b1b7687c151d8481c1deb9347.tar.bz2
rneovim-137f98cf6428a55b1b7687c151d8481c1deb9347.zip
test: tmpname() can skip file creation
Diffstat (limited to 'test/testutil.lua')
-rw-r--r--test/testutil.lua10
1 files changed, 7 insertions, 3 deletions
diff --git a/test/testutil.lua b/test/testutil.lua
index 439f13cf49..0118f6b9e9 100644
--- a/test/testutil.lua
+++ b/test/testutil.lua
@@ -402,14 +402,18 @@ end
local tmpname_id = 0
local tmpdir = tmpdir_get()
---- Creates a new temporary file for use by tests.
-function M.tmpname()
+--- Generates a unique file path for use by tests, and writes the file unless `create=false`.
+---
+---@param create? boolean (default true) Write the file.
+function M.tmpname(create)
if tmpdir_is_local(tmpdir) then
-- Cannot control os.tmpname() dir, so hack our own tmpname() impl.
tmpname_id = tmpname_id + 1
-- "…/Xtest_tmpdir/T42.7"
local fname = ('%s/%s.%d'):format(tmpdir, (_G._nvim_test_id or 'nvim-test'), tmpname_id)
- io.open(fname, 'w'):close()
+ if create ~= false then
+ io.open(fname, 'w'):close()
+ end
return fname
end