From b0030995b0c60c0fb88d01d71cdd2d5773c8f321 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Thu, 22 Aug 2024 17:48:58 -0300 Subject: Teal: convert luarocks.test.command --- src/luarocks/test/command.lua | 52 ---------------------------------------- src/luarocks/test/command.tl | 55 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 52 deletions(-) delete mode 100644 src/luarocks/test/command.lua create mode 100644 src/luarocks/test/command.tl (limited to 'src') diff --git a/src/luarocks/test/command.lua b/src/luarocks/test/command.lua deleted file mode 100644 index bed6744e..00000000 --- a/src/luarocks/test/command.lua +++ /dev/null @@ -1,52 +0,0 @@ - -local command = {} - -local fs = require("luarocks.fs") -local cfg = require("luarocks.core.cfg") - -local unpack = table.unpack or unpack - -function command.detect_type() - if fs.exists("test.lua") then - return true - end - return false -end - -function command.run_tests(test, args) - if not test then - test = { - script = "test.lua" - } - end - - if not test.script and not test.command then - test.script = "test.lua" - end - - local ok - - if test.script then - if type(test.script) ~= "string" then - return nil, "Malformed rockspec: 'script' expects a string" - end - if not fs.exists(test.script) then - return nil, "Test script " .. test.script .. " does not exist" - end - local lua = fs.Q(cfg.variables["LUA"]) -- get lua interpreter configured - ok = fs.execute(lua, test.script, unpack(args)) - elseif test.command then - if type(test.command) ~= "string" then - return nil, "Malformed rockspec: 'command' expects a string" - end - ok = fs.execute(test.command, unpack(args)) - end - - if ok then - return true - else - return nil, "tests failed with non-zero exit code" - end -end - -return command diff --git a/src/luarocks/test/command.tl b/src/luarocks/test/command.tl new file mode 100644 index 00000000..217a34fc --- /dev/null +++ b/src/luarocks/test/command.tl @@ -0,0 +1,55 @@ + +local record command +end + +local fs = require("luarocks.fs") +local cfg = require("luarocks.core.cfg") + +local type Test = require("luarocks.core.types.rockspec").Test + +function command.detect_type(): boolean + if fs.exists("test.lua") then + return true + end + return false +end + +function command.run_tests(test: Test, args: {string}): boolean, string + if not test then + test = { + script = "test.lua" + } + end + + if not test.script and not test.command then + test.script = "test.lua" + end + + local ok: boolean + + if test.script then + local test_script = test.script + if not test_script is string then + return nil, "Malformed rockspec: 'script' expects a string" + end + if not fs.exists(test.script) then + return nil, "Test script " .. test.script .. " does not exist" + end + local lua = fs.Q(cfg.variables["LUA"]) -- get lua interpreter configured + ok = fs.execute(lua, test.script, table.unpack(args)) + elseif test.command then + local test_command = test.command + if not test_command is string then + return nil, "Malformed rockspec: 'command' expects a string" + end + ok = fs.execute(test.command, table.unpack(args)) + end + + if ok then + return true + else + return nil, "tests failed with non-zero exit code" + end +end + +return command -- cgit v1.2.3-55-g6feb