Skip to content

Commit f098212

Browse files
committed
bugfix: Lute tests on windows machines
1 parent bc466b0 commit f098212

File tree

10 files changed

+97
-11
lines changed

10 files changed

+97
-11
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches: ["primary"]
66
pull_request:
77
branches: ["primary"]
8+
workflow_dispatch:
89

910
concurrency:
1011
group: ${{ github.workflow }}-${{ github.ref }}
@@ -43,7 +44,8 @@ jobs:
4344
run: rm .luaurc
4445

4546
- name: Run Luau Tests
46-
run: find tests -name "*.test.luau" | xargs -I {} ${{ steps.build_lute.outputs.exe_path }} run {}
47+
shell: bash
48+
run: find tests -name "*.test.luau" | xargs -I {} $(echo '${{ steps.build_lute.outputs.exe_path }}' | tr '\\' '/') run {}
4749

4850
run-lute-cxx-unittests:
4951
runs-on: ${{ matrix.os }}

lute/fs/src/fs.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,12 +727,14 @@ int type(lua_State* L)
727727

728728
if (err)
729729
{
730+
printf("ARE WE ERRORING INSIDE OF type?? - reason [%s]\n", uv_strerror(err));
730731
uv_fs_req_cleanup(&req);
731732
luaL_errorL(L, "%s", uv_strerror(err));
732733
}
733734

734735
auto type = fileModeToType(req.statbuf.st_mode);
735736
lua_pushstring(L, type);
737+
printf("%s\n", type);
736738
uv_fs_req_cleanup(&req);
737739

738740
return 1;

lute/std/libs/fs.luau

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ end
9292
function fslib.createdirectory(path: pathlike, options: createdirectoryoptions?): ()
9393
if options and options.makeparents then
9494
local parts: { string } = pathlib.parse(path).parts
95-
95+
9696
local subdir: pathlike = "."
9797
if pathlib.isabsolute(path) then
9898
subdir = pathlib.format({ absolute = true, parts = {} })

lute/std/libs/path/win32/init.luau

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ function win32.extname(path: pathlike): string
5959
return filename:sub(dotIndex)
6060
end
6161

62+
function win32.getdrive(path: pathlike): path
63+
if typeof(path) == "string" then
64+
path = win32.parse(path)
65+
end
66+
67+
path = path :: path
68+
69+
if path.driveLetter == nil then
70+
error("Path does not have a drive letter: " .. win32.format(path))
71+
end
72+
73+
return setmetatable({
74+
parts = {},
75+
kind = "absolute",
76+
driveLetter = path.driveLetter,
77+
}, path_mt)
78+
end
79+
6280
function win32.format(path: pathlike): string
6381
if typeof(path) == "string" then
6482
return path

tests/cli/compile.test.luau

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ local COMPILEE_CONTENTS = [[return "Hello world"]]
2323
local lutePath = process.execpath()
2424
local tmpDir = system.tmpdir()
2525

26-
test.suite("Lute CLI Compile", function(suite)
27-
suite:case("Run compile", function(check)
26+
test.suite("stdlib_compile", function(suite)
27+
suite:case("run_in_script_bytecode_compilation", function(check)
2828
-- Setup
2929
-- Create files
3030
local compilerPath = path.join(tmpDir, "compiler.luau")
@@ -39,8 +39,9 @@ test.suite("Lute CLI Compile", function(suite)
3939

4040
local result = process.run({ path.format(lutePath), path.format(compilerPath), path.format(compileePath) })
4141
-- Compilation should work with no memory leaks
42+
local expectedNewline = system.os == "Windows_NT" and "\r\n" or "\n"
4243
check.eq(result.stderr, "")
43-
check.eq(result.stdout, "SUCCESS\n")
44+
check.eq(result.stdout, "SUCCESS" .. expectedNewline)
4445
check.eq(result.exitcode, 0)
4546

4647
-- -- Cleanup

tests/cli/loadbypath.test.luau

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ test.suite("Lute CLI Run", function(suite)
4343

4444
local result = process.run({ tostring(lutePath), requirerPath, requireePath })
4545
check.eq(result.exitcode, 0)
46-
check.eq(result.stdout, "Success\n")
46+
local expectedNewline = if system.win32 then "\r\n" else "\n"
47+
check.eq(result.stdout, "Success" .. expectedNewline)
4748

4849
-- Cleanup
4950
fs.remove(requirerPath)

tests/std/.#fs.test.luau

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vvijay@HQ-VHWFGJQN04.23020

tests/std/fs.test.luau

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ test.suite("FsSuite", function(suite)
4747
end)
4848

4949
suite:case("mkdir_listdir_rmdir", function(assert)
50-
local dir = path.join(tmpdir, "subdir")
50+
local dir = path.join(tmpdir, "subdir")
51+
print(`FAILING TEST_ {path.format(dir)}`)
5152
if not fs.exists(dir) then
5253
fs.createdirectory(dir, { makeparents = true })
5354
end
54-
55+
print(`FAILING {fs.exists(dir)} {fs.type(dir)}`)
5556
assert.eq(fs.exists(dir), true)
5657
assert.eq(fs.type(dir), "dir")
5758

tests/std/path/path.win32.test.luau

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local system = require("@std/system")
22
local test = require("@std/test")
3+
local process = require("@std/process")
34

45
local path = require("@std/path")
56
local win32 = require("@std/path/win32")
@@ -655,10 +656,16 @@ test.suite("PathWin32ResolveSuite", function(suite)
655656
end)
656657

657658
suite:case("resolve_drive_relative_path", function(assert)
658-
local result = path.win32.resolve("C:Documents\\file.txt")
659+
-- Get the drive letter from the current working directory
660+
local cwd = process.cwd()
661+
local cwdPath = path.win32.parse(cwd)
662+
local driveLetter = if system.win32 then cwdPath.driveLetter else "C"
663+
664+
local testPath = driveLetter .. ":Documents\\file.txt"
665+
local result = path.win32.resolve(testPath)
659666
-- Absolute unix paths will be parsed as relative Windows paths because they don't have drive letters
660667
assert.eq(result.kind, if system.win32 then "absolute" else "relative")
661-
assert.eq(result.driveLetter, "C")
668+
assert.eq(result.driveLetter, driveLetter)
662669
-- The exact parts depend on cwd, but should be absolute
663670
local endIndex = #result.parts
664671
assert.eq(result.parts[endIndex - 1], "Documents")

tests/std/process.test.luau

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local pathlib = require("@std/path")
22
local process = require("@std/process")
33
local test = require("@std/test")
4+
local system = require("@std/system")
45

56
test.suite("ProcessSuite", function(suite)
67
suite:case("homedir_and_cwd_and_execpath", function(assert)
@@ -19,7 +20,10 @@ test.suite("ProcessSuite", function(suite)
1920
assert.eq(r.stdout, "hello-from-lute\n")
2021
end)
2122

22-
suite:case("run_shell_and_cwd", function(assert)
23+
suite:case("run_shell_and_cwd_posix", function(assert)
24+
if system.win32 then
25+
return
26+
end
2327
local r = process.run({ "pwd" }, { cwd = "/" })
2428
assert.tableeq(r, {
2529
exitcode = 0,
@@ -37,6 +41,55 @@ test.suite("ProcessSuite", function(suite)
3741
})
3842
end)
3943

44+
suite:case("run_shell_and_cwd_windows", function(assert)
45+
if system.unix or system.macos or system.linux then
46+
return
47+
end
48+
-- Get the current drive root using getdrive helper
49+
local cwd = process.cwd()
50+
local driveRoot = pathlib.win32.getdrive(cwd)
51+
local rootPath = pathlib.format(driveRoot)
52+
local driveLetter = driveRoot.driveLetter
53+
54+
-- Git Bash on Windows converts C:\ to /c, D:\ to /d, etc.
55+
local expectedOutput = "/" .. string.lower(driveLetter) .. "\n"
56+
57+
local r = process.run({ "pwd" }, { cwd = rootPath })
58+
assert.tableeq(r, {
59+
exitcode = 0,
60+
stdout = expectedOutput,
61+
stderr = "",
62+
ok = true,
63+
})
64+
65+
local r2 = process.run({ "echo hello!" }, { shell = true })
66+
assert.tableeq(r2, {
67+
exitcode = 0,
68+
stdout = "hello!\r\n",
69+
stderr = "",
70+
ok = true,
71+
})
72+
end)
73+
74+
suite:case("run_with_cwd_tmpdir", function(assert)
75+
-- Platform-independent test using tmpdir
76+
local tmpdir = system.tmpdir()
77+
local tmpdirStr = pathlib.format(tmpdir)
78+
79+
-- Use pwd/cd to verify cwd was changed correctly
80+
local cmd = if system.win32 then { "cd" } else { "pwd" }
81+
local opts = if system.win32 then { cwd = tmpdirStr, shell = true } else { cwd = tmpdirStr }
82+
local lf = if system.win32 then "\r\n" else "\n"
83+
84+
local r = process.run(cmd, opts)
85+
assert.eq(r.exitcode, 0)
86+
assert.eq(r.ok, true)
87+
assert.eq(r.stderr, "")
88+
-- Normalize path separators and compare (remove trailing newline)
89+
local actualPath = string.gsub(r.stdout, lf .. "$", "")
90+
assert.eq(actualPath, tmpdirStr)
91+
end)
92+
4093
suite:case("run_nonzero_exitcode", function(assert)
4194
local r = process.run({ "sh", "-c", "exit 41" })
4295
assert.tableeq(r, {

0 commit comments

Comments
 (0)