diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-08-22 17:48:58 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
| commit | b0030995b0c60c0fb88d01d71cdd2d5773c8f321 (patch) | |
| tree | 8781a9da9672ee25a10dbc0d0281e269018631be /src | |
| parent | a9c43e2efbfe05f5a71b68235d7115bbb06f407a (diff) | |
| download | luarocks-b0030995b0c60c0fb88d01d71cdd2d5773c8f321.tar.gz luarocks-b0030995b0c60c0fb88d01d71cdd2d5773c8f321.tar.bz2 luarocks-b0030995b0c60c0fb88d01d71cdd2d5773c8f321.zip | |
Teal: convert luarocks.test.command
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/test/command.tl (renamed from src/luarocks/test/command.lua) | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/luarocks/test/command.lua b/src/luarocks/test/command.tl index bed6744e..217a34fc 100644 --- a/src/luarocks/test/command.lua +++ b/src/luarocks/test/command.tl | |||
| @@ -1,19 +1,20 @@ | |||
| 1 | 1 | ||
| 2 | local command = {} | 2 | local record command |
| 3 | end | ||
| 3 | 4 | ||
| 4 | local fs = require("luarocks.fs") | 5 | local fs = require("luarocks.fs") |
| 5 | local cfg = require("luarocks.core.cfg") | 6 | local cfg = require("luarocks.core.cfg") |
| 6 | 7 | ||
| 7 | local unpack = table.unpack or unpack | 8 | local type Test = require("luarocks.core.types.rockspec").Test |
| 8 | 9 | ||
| 9 | function command.detect_type() | 10 | function command.detect_type(): boolean |
| 10 | if fs.exists("test.lua") then | 11 | if fs.exists("test.lua") then |
| 11 | return true | 12 | return true |
| 12 | end | 13 | end |
| 13 | return false | 14 | return false |
| 14 | end | 15 | end |
| 15 | 16 | ||
| 16 | function command.run_tests(test, args) | 17 | function command.run_tests(test: Test, args: {string}): boolean, string |
| 17 | if not test then | 18 | if not test then |
| 18 | test = { | 19 | test = { |
| 19 | script = "test.lua" | 20 | script = "test.lua" |
| @@ -24,22 +25,24 @@ function command.run_tests(test, args) | |||
| 24 | test.script = "test.lua" | 25 | test.script = "test.lua" |
| 25 | end | 26 | end |
| 26 | 27 | ||
| 27 | local ok | 28 | local ok: boolean |
| 28 | 29 | ||
| 29 | if test.script then | 30 | if test.script then |
| 30 | if type(test.script) ~= "string" then | 31 | local test_script = test.script |
| 32 | if not test_script is string then | ||
| 31 | return nil, "Malformed rockspec: 'script' expects a string" | 33 | return nil, "Malformed rockspec: 'script' expects a string" |
| 32 | end | 34 | end |
| 33 | if not fs.exists(test.script) then | 35 | if not fs.exists(test.script) then |
| 34 | return nil, "Test script " .. test.script .. " does not exist" | 36 | return nil, "Test script " .. test.script .. " does not exist" |
| 35 | end | 37 | end |
| 36 | local lua = fs.Q(cfg.variables["LUA"]) -- get lua interpreter configured | 38 | local lua = fs.Q(cfg.variables["LUA"]) -- get lua interpreter configured |
| 37 | ok = fs.execute(lua, test.script, unpack(args)) | 39 | ok = fs.execute(lua, test.script, table.unpack(args)) |
| 38 | elseif test.command then | 40 | elseif test.command then |
| 39 | if type(test.command) ~= "string" then | 41 | local test_command = test.command |
| 42 | if not test_command is string then | ||
| 40 | return nil, "Malformed rockspec: 'command' expects a string" | 43 | return nil, "Malformed rockspec: 'command' expects a string" |
| 41 | end | 44 | end |
| 42 | ok = fs.execute(test.command, unpack(args)) | 45 | ok = fs.execute(test.command, table.unpack(args)) |
| 43 | end | 46 | end |
| 44 | 47 | ||
| 45 | if ok then | 48 | if ok then |
