From 2e9ff358cc5d93d50f672f6a6db3f65887e4821c Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sat, 16 Sep 2023 15:03:01 -0500 Subject: [PATCH] Fix cwd and wait tests on windows --- tests/process/cwd.luau | 6 +++++- tests/task/wait.luau | 22 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/process/cwd.luau b/tests/process/cwd.luau index 02bba4c..4094523 100644 --- a/tests/process/cwd.luau +++ b/tests/process/cwd.luau @@ -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 diff --git a/tests/task/wait.luau b/tests/task/wait.luau index bc72fe4..adc1622 100644 --- a/tests/task/wait.luau +++ b/tests/task/wait.luau @@ -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() @@ -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(