Skip to content

Commit f6395ec

Browse files
committed
test(glob): fix Windows wildcard and case assertions
1 parent 1c2adcd commit f6395ec

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

tests/glob.test.lua

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ local args_repr = mods.utils.args_repr
1010
local spairs = mods.tbl.spairs
1111
local make_tmp_dir = helpers.make_tmp_dir
1212
local join = mods.path.join
13-
1413
local fmt = string.format
1514

1615
describe("mods.glob", function()
17-
local set_windows_semantics = glob._set_windows_semantics --[[@as fun()]]
18-
local set_posix_semantics = glob._set_posix_semantics --[[@as fun()]]
19-
local restore_semantics = mods.runtime.is_windows and set_windows_semantics or set_posix_semantics
16+
local is_windows = mods.runtime.is_windows
2017
local cwd = fs.cwd() --[[@as string]]
2118
local modes = Set({ "common", "posix", "windows" })
2219

20+
local set_windows_semantics = glob._set_windows_semantics --[[@as fun()]]
21+
local set_posix_semantics = glob._set_posix_semantics --[[@as fun()]]
22+
local restore_semantics = is_windows and set_windows_semantics or set_posix_semantics
23+
2324
local function make_recursive_txt_fixture()
2425
local root = make_tmp_dir()
2526
local subdir = join(root, "sub")
@@ -329,7 +330,7 @@ describe("mods.glob", function()
329330
local matches = glob.glob("*.txt")
330331
assert.is_true(fs.cd(cwd))
331332
assert.is_true(fs.rm(root, true))
332-
assert.same({ "./data.txt" }, matches)
333+
assert.same({ join(".", "data.txt") }, matches)
333334
end)
334335

335336
it("supports hidden", function()
@@ -357,7 +358,7 @@ describe("mods.glob", function()
357358

358359
assert.is_true(fs.touch(mixed))
359360

360-
assert.same({}, glob.glob(root, "*.txt"))
361+
assert.same({}, glob.glob(root, "*.txt", { ignorecase = false }))
361362
assert.same({ mixed }, glob.glob(root, "*.txt", { ignorecase = true }))
362363

363364
assert.is_true(fs.rm(root, true))
@@ -380,17 +381,20 @@ describe("mods.glob", function()
380381
local file1 = join(root, "file1.txt")
381382
local file2 = join(root, "file2.txt")
382383
local note = join(root, "file1.md")
383-
local literal = join(root, "a*b.txt")
384384

385385
assert.is_true(fs.touch(file1))
386386
assert.is_true(fs.touch(file2))
387387
assert.is_true(fs.touch(note))
388-
assert.is_true(fs.touch(literal))
389388

390389
assert.same({ file1, file2 }, glob.glob(root, "file?.txt"):sort())
391390
assert.same({ file1, file2 }, glob.glob(root, "file[1-2].txt"):sort())
392391
assert.same({ note, file1 }, glob.glob(root, "file1.{txt,md}"):sort())
393-
assert.same({ literal }, glob.glob(root, glob.escape("a*b.txt")))
392+
393+
if not is_windows then
394+
local literal = join(root, "a*b.txt")
395+
assert.is_true(fs.touch(literal))
396+
assert.same({ literal }, glob.glob(root, glob.escape("a*b.txt")))
397+
end
394398

395399
assert.is_true(fs.rm(root, true))
396400
end)
@@ -503,7 +507,7 @@ describe("mods.glob", function()
503507

504508
assert.is_true(fs.cd(cwd))
505509
assert.is_true(fs.rm(root, true))
506-
assert.same({ "./data.txt" }, ls)
510+
assert.same({ join(".", "data.txt") }, ls)
507511
end)
508512

509513
it("supports ignorecase and directory-only patterns", function()

0 commit comments

Comments
 (0)