Skip to content

Commit

Permalink
Fix cwd and wait tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Sep 17, 2023
1 parent fad48b9 commit 2e9ff35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 5 additions & 1 deletion tests/process/cwd.luau
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ assert(type(process.cwd) == "string", "Process cwd is not a string")

assert(#process.cwd > 0, "Process cwd is an empty string")

assert(string.sub(process.cwd, -1) == "/", "Process cwd does not end with '/'")
if process.os == "windows" then
assert(string.sub(process.cwd, -1) == "\\", "Process cwd does not end with '\\'")
else
assert(string.sub(process.cwd, -1) == "/", "Process cwd does not end with '/'")
end
22 changes: 18 additions & 4 deletions tests/task/wait.luau
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ local process = require("@lune/process")
local stdio = require("@lune/stdio")
local task = require("@lune/task")

-- Wait should be accurate down to at least 10ms
-- on Windows, and 6ms on Linux and / or macOS
-- NOTE: For now we don't test accuracy of waiting, the only thing
-- we guarantee is that task.wait waits for _at least_ the amount
-- of time given. Windows sleep is extremely inaccurate.
local TEST_ACCURACY = false

local EPSILON = if process.os == "windows" then 10 / 1_000 else 6 / 1_000
local EPSILON = if process.os == "windows" then 12 / 1_000 else 8 / 1_000

local function test(expected: number)
local start = os.clock()
Expand All @@ -20,7 +22,19 @@ local function test(expected: number)
2
)
end
local elapsed = (os.clock() - start)
local elapsed = os.clock() - start
if elapsed < expected then
error(
string.format(
"Expected task.wait to yield for at least %.3f seconds, yielded for %.3f seconds",
expected,
elapsed
)
)
end
if not TEST_ACCURACY then
return
end
local difference = math.abs(elapsed - expected)
if difference > EPSILON then
error(
Expand Down

0 comments on commit 2e9ff35

Please sign in to comment.