mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Fix cwd and wait tests on windows
This commit is contained in:
parent
fad48b9603
commit
2e9ff358cc
2 changed files with 23 additions and 5 deletions
|
@ -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(#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
|
||||||
|
|
|
@ -2,10 +2,12 @@ local process = require("@lune/process")
|
||||||
local stdio = require("@lune/stdio")
|
local stdio = require("@lune/stdio")
|
||||||
local task = require("@lune/task")
|
local task = require("@lune/task")
|
||||||
|
|
||||||
-- Wait should be accurate down to at least 10ms
|
-- NOTE: For now we don't test accuracy of waiting, the only thing
|
||||||
-- on Windows, and 6ms on Linux and / or macOS
|
-- 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 function test(expected: number)
|
||||||
local start = os.clock()
|
local start = os.clock()
|
||||||
|
@ -20,7 +22,19 @@ local function test(expected: number)
|
||||||
2
|
2
|
||||||
)
|
)
|
||||||
end
|
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)
|
local difference = math.abs(elapsed - expected)
|
||||||
if difference > EPSILON then
|
if difference > EPSILON then
|
||||||
error(
|
error(
|
||||||
|
|
Loading…
Reference in a new issue