From ea2d9493514a82bb5077e73957a22648cb5d7d14 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 3 Sep 2024 02:18:17 -0700 Subject: test: tmpname(create:boolean) #30242 Problem: 137f98cf6428 added the `create` parameter to `tmpname()` but didn't fully implement it. Solution: - Update impl for the `os.tmpname()` codepath. - Inspect all usages of `tmpname()`, update various tests. --- test/testutil.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'test/testutil.lua') diff --git a/test/testutil.lua b/test/testutil.lua index 0118f6b9e9..01eaf25406 100644 --- a/test/testutil.lua +++ b/test/testutil.lua @@ -402,7 +402,8 @@ end local tmpname_id = 0 local tmpdir = tmpdir_get() ---- Generates a unique file path for use by tests, and writes the file unless `create=false`. +--- Generates a unique filepath for use by tests, in a test-specific "…/Xtest_tmpdir/T42.7" +--- directory (which is cleaned up by the test runner), and writes the file unless `create=false`. --- ---@param create? boolean (default true) Write the file. function M.tmpname(create) @@ -418,6 +419,10 @@ function M.tmpname(create) end local fname = os.tmpname() + if create == false then + os.remove(fname) + end + if M.is_os('win') and fname:sub(1, 2) == '\\s' then -- In Windows tmpname() returns a filename starting with -- special sequence \s, prepend $TEMP path -- cgit