aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-22 17:48:56 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-10-21 13:30:51 -0300
commit08351f44d22f07f0eaf87fcc5732a32e7e5282df (patch)
tree68f45a6681e9d34999ab7bb69b05aa68e54911cc /src
parentfdc7493906e7eab77a7d74ffde52a38e0055393e (diff)
downloadluarocks-08351f44d22f07f0eaf87fcc5732a32e7e5282df.tar.gz
luarocks-08351f44d22f07f0eaf87fcc5732a32e7e5282df.tar.bz2
luarocks-08351f44d22f07f0eaf87fcc5732a32e7e5282df.zip
Teal: convert luarocks.test
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/test.tl55
1 files changed, 32 insertions, 23 deletions
diff --git a/src/luarocks/test.tl b/src/luarocks/test.tl
index d074b950..d076d264 100644
--- a/src/luarocks/test.tl
+++ b/src/luarocks/test.tl
@@ -1,32 +1,44 @@
1 1local record test
2local test = {} 2end
3 3
4local fetch = require("luarocks.fetch") 4local fetch = require("luarocks.fetch")
5local deps = require("luarocks.deps") 5local deps = require("luarocks.deps")
6local util = require("luarocks.util") 6local util = require("luarocks.util")
7 7
8local type Rockspec = require("luarocks.core.types.rockspec").Rockspec
9local type Dependencies = require("luarocks.core.types.rockspec").Dependencies
10
11local type TestRunner = require("luarocks.core.types.testrunner").TestRunner
12
8local test_types = { 13local test_types = {
9 "busted", 14 "busted",
10 "command", 15 "command",
11} 16}
12 17
13local test_modules = {} 18local test_modules: {TestRunner} = {}
19local typetomod: {string: TestRunner} = {}
20local modtotype: {TestRunner: string} = {}
14 21
15for _, test_type in ipairs(test_types) do 22for _, test_type in ipairs(test_types) do
16 local mod = require("luarocks.test." .. test_type) 23 local mod: TestRunner
24 if test_type == "command" then
25 mod = require("luarocks.test.command")
26 elseif test_type == "busted" then
27 mod = require("luarocks.test.busted")
28 end
17 table.insert(test_modules, mod) 29 table.insert(test_modules, mod)
18 test_modules[test_type] = mod 30 typetomod[test_type] = mod
19 test_modules[mod] = test_type 31 modtotype[mod] = test_type
20end 32end
21 33
22local function get_test_type(rockspec) 34local function get_test_type(rockspec: Rockspec): string, string
23 if rockspec.test and rockspec.test.type then 35 if rockspec.test and rockspec.test.type then
24 return rockspec.test.type 36 return rockspec.test.type
25 end 37 end
26 38
27 for _, test_module in ipairs(test_modules) do 39 for _, test_module in ipairs(test_modules) do
28 if test_module.detect_type() then 40 if test_module.detect_type() then
29 return test_modules[test_module] 41 return modtotype[test_module]
30 end 42 end
31 end 43 end
32 44
@@ -34,27 +46,25 @@ local function get_test_type(rockspec)
34end 46end
35 47
36-- Run test suite as configured in rockspec in the current directory. 48-- Run test suite as configured in rockspec in the current directory.
37function test.run_test_suite(rockspec_arg, test_type, args, prepare) 49function test.run_test_suite(rockspec_arg: string | Rockspec, test_type: string, args: {string}, prepare: boolean): boolean, string, string
38 local rockspec 50 local rockspec: Rockspec
39 if type(rockspec_arg) == "string" then 51 if rockspec_arg is string then
40 local err, errcode 52 local err, errcode: string, string
41 rockspec, err, errcode = fetch.load_rockspec(rockspec_arg) 53 rockspec, err, errcode = fetch.load_rockspec(rockspec_arg)
42 if err then 54 if err then
43 return nil, err, errcode 55 return nil, err, errcode
44 end 56 end
45 else 57 else
46 assert(type(rockspec_arg) == "table")
47 rockspec = rockspec_arg 58 rockspec = rockspec_arg
48 end 59 end
49 60
50 if not test_type then 61 if not test_type then
51 local err 62 local err: string
52 test_type, err = get_test_type(rockspec, test_type) 63 test_type, err = get_test_type(rockspec)
53 if not test_type then 64 if not test_type then
54 return nil, err 65 return nil, err
55 end 66 end
56 end 67 end
57 assert(test_type)
58 68
59 local all_deps = { 69 local all_deps = {
60 "dependencies", 70 "dependencies",
@@ -62,29 +72,28 @@ function test.run_test_suite(rockspec_arg, test_type, args, prepare)
62 "test_dependencies", 72 "test_dependencies",
63 } 73 }
64 for _, dep_kind in ipairs(all_deps) do 74 for _, dep_kind in ipairs(all_deps) do
65 if rockspec[dep_kind] and next(rockspec[dep_kind]) then 75 if (rockspec as {string: Dependencies})[dep_kind] and next((rockspec as {string: Dependencies})[dep_kind]) ~= nil then
66 local ok, err, errcode = deps.fulfill_dependencies(rockspec, dep_kind, "all") 76 local _, err, errcode = deps.fulfill_dependencies(rockspec, dep_kind, "all")
67 if err then 77 if err then
68 return nil, err, errcode 78 return nil, err, errcode
69 end 79 end
70 end 80 end
71 end 81 end
72 82
73 local mod_name = "luarocks.test." .. test_type 83 local pok, test_mod = pcall(require, "luarocks.test."..test_type) as (boolean, TestRunner)
74 local pok, test_mod = pcall(require, mod_name)
75 if not pok then 84 if not pok then
76 return nil, "failed loading test execution module " .. mod_name 85 return nil, "failed loading test execution module luarocks.test."..test_type
77 end 86 end
78 87
79 if prepare then 88 if prepare then
80 if test_type == "busted" then 89 if test_type == "busted" then
81 return test_mod.run_tests(rockspec_arg, {"--version"}) 90 return test_mod.run_tests(rockspec.test, {"--version"})
82 else 91 else
83 return true 92 return true
84 end 93 end
85 else 94 else
86 local flags = rockspec.test and rockspec.test.flags 95 local flags = rockspec.test and rockspec.test.flags
87 if type(flags) == "table" then 96 if flags is {string} then
88 util.variable_substitutions(flags, rockspec.variables) 97 util.variable_substitutions(flags, rockspec.variables)
89 98
90 -- insert any flags given in test.flags at the front of args 99 -- insert any flags given in test.flags at the front of args