test: tmpname(create:boolean) #30242

Problem:
137f98cf64 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.
This commit is contained in:
Justin M. Keyes
2024-09-03 02:18:17 -07:00
committed by GitHub
parent ae9674704a
commit ea2d949351
5 changed files with 9 additions and 8 deletions

View File

@ -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