11local pathlib = require ("@std/path" )
22local process = require ("@std/process" )
33local test = require ("@std/test" )
4+ local system = require ("@std/system" )
45
56test .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,54 @@ 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 letter and construct root path
49+ local cwd = process .cwd ()
50+ local cwdPath = pathlib .parse (cwd )
51+ local driveLetter = cwdPath .driveLetter
52+ local rootPath = 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 = system .win32 and { "cd" } or { "pwd" }
81+ local opts = system .win32 and { cwd = tmpdirStr , shell = true } or { cwd = tmpdirStr }
82+
83+ local r = process .run (cmd , opts )
84+ assert .eq (r .exitcode , 0 )
85+ assert .eq (r .ok , true )
86+ assert .eq (r .stderr , "" )
87+ -- Normalize path separators and compare (remove trailing newline)
88+ local actualPath = string.gsub (r .stdout , "\r\n $" , "" )
89+ assert .eq (actualPath , tmpdirStr )
90+ end )
91+
4092 suite :case ("run_nonzero_exitcode" , function (assert )
4193 local r = process .run ({ "sh" , "-c" , "exit 41" })
4294 assert .tableeq (r , {
0 commit comments