Skip to content

Commit fbc2c0a

Browse files
authored
Improve tempdir test to ensure filename generated on UNIX is valid
1 parent cb32020 commit fbc2c0a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

test/file.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,20 +520,21 @@ end
520520
@test my_tempdir[end] != '\\'
521521

522522
var = Sys.iswindows() ? "TMP" : "TMPDIR"
523-
PATH_PREFIX = Sys.iswindows() ? "C:\\" : "/tmp/"
523+
PATH_PREFIX = Sys.iswindows() ? "C:\\" : "/tmp/" * "x"^255 # we want a long path on UNIX so that we test buffer resizing in `tempdir`
524524
# Warning: On Windows uv_os_tmpdir internally calls GetTempPathW. The max string length for
525525
# GetTempPathW is 261 (including the implied trailing backslash), not the typical length 259.
526-
# We thus use 260 (with implied trailing slash backlash this then gives 261 chars) and
527-
# subtract 9 to account for i = 0:9.
528-
MAX_PATH = (Sys.iswindows() ? 260-9 : 1024) - length(PATH_PREFIX)
526+
# We thus use 260 (with implied trailing slash backlash this then gives 261 chars)
527+
# NOTE: not the actual max path on UNIX, but true in the Windows case for this function.
528+
# NOTE: we subtract 9 to account for i = 0:9.
529+
MAX_PATH = (Sys.iswindows() ? 260 - length(PATH_PREFIX) : 255) - 9
529530
for i = 0:8
530-
local tmp = PATH_PREFIX * "x"^MAX_PATH * "123456789"[1:i]
531+
local tmp = joinpath(PATH_PREFIX, "x"^MAX_PATH * "123456789"[1:i])
531532
@test withenv(var => tmp) do
532533
tempdir()
533534
end == (tmp)
534535
end
535536
for i = 9
536-
local tmp = PATH_PREFIX * "x"^MAX_PATH * "123456789"[1:i]
537+
local tmp = joinpath(PATH_PREFIX, "x"^MAX_PATH * "123456789"[1:i])
537538
if Sys.iswindows()
538539
# libuv bug
539540
@test_broken withenv(var => tmp) do

0 commit comments

Comments
 (0)