From 3c0e2702792334fc40d5ebc6b6295a9337ab4cc0 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Tue, 24 Jan 2023 12:52:41 -0500 Subject: [PATCH] Share more code in task lib test files --- src/tests/task/defer.luau | 14 +------------- src/tests/task/delay.luau | 14 +------------- src/tests/task/fcheck.luau | 13 +++++++++++++ src/tests/task/spawn.luau | 14 +------------- 4 files changed, 16 insertions(+), 39 deletions(-) create mode 100644 src/tests/task/fcheck.luau diff --git a/src/tests/task/defer.luau b/src/tests/task/defer.luau index 83fcda4..df95338 100644 --- a/src/tests/task/defer.luau +++ b/src/tests/task/defer.luau @@ -41,19 +41,7 @@ assert(flag3 == 3, "Defer should run after spawned threads") -- Varargs should get passed correctly -local function fcheck(index: number, type: string, value: any) - if typeof(value) ~= type then - console.error( - string.format( - "Expected argument #%d to be of type %s, got %s", - index, - type, - console.format(value) - ) - ) - process.exit(1) - end -end +local fcheck = require("./fcheck") local function f(...: any) fcheck(1, "string", select(1, ...)) diff --git a/src/tests/task/delay.luau b/src/tests/task/delay.luau index abedffe..7d00546 100644 --- a/src/tests/task/delay.luau +++ b/src/tests/task/delay.luau @@ -28,19 +28,7 @@ assert(not flag2, "Delay should work with yielding (2)") -- Varargs should get passed correctly -local function fcheck(index: number, type: string, value: any) - if typeof(value) ~= type then - console.error( - string.format( - "Expected argument #%d to be of type %s, got %s", - index, - type, - console.format(value) - ) - ) - process.exit(1) - end -end +local fcheck = require("./fcheck") local function f(...: any) fcheck(1, "string", select(1, ...)) diff --git a/src/tests/task/fcheck.luau b/src/tests/task/fcheck.luau new file mode 100644 index 0000000..04e0081 --- /dev/null +++ b/src/tests/task/fcheck.luau @@ -0,0 +1,13 @@ +return function(index: number, type: string, value: any) + if typeof(value) ~= type then + console.error( + string.format( + "Expected argument #%d to be of type %s, got %s", + index, + type, + console.format(value) + ) + ) + process.exit(1) + end +end diff --git a/src/tests/task/spawn.luau b/src/tests/task/spawn.luau index 08f1ae8..7080d05 100644 --- a/src/tests/task/spawn.luau +++ b/src/tests/task/spawn.luau @@ -33,19 +33,7 @@ assert(flag3, "Spawn should run threads made from coroutine.create") -- Varargs should get passed correctly -local function fcheck(index: number, type: string, value: any) - if typeof(value) ~= type then - console.error( - string.format( - "Expected argument #%d to be of type %s, got %s", - index, - type, - console.format(value) - ) - ) - process.exit(1) - end -end +local fcheck = require("./fcheck") local function f(...: any) fcheck(1, "string", select(1, ...))