aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-13 19:53:11 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-13 19:53:11 +0300
commit9d4bebd145cbdf3185ed68ba1eb4140303eb093f (patch)
tree400a2298ccd99cd30e6afaaf342c123d50a7849f
parent6bafc07e7f6e93ef9d1bcaa73d8f16d17b114e1b (diff)
downloadluarocks-9d4bebd145cbdf3185ed68ba1eb4140303eb093f.tar.gz
luarocks-9d4bebd145cbdf3185ed68ba1eb4140303eb093f.tar.bz2
luarocks-9d4bebd145cbdf3185ed68ba1eb4140303eb093f.zip
test
-rw-r--r--spec/quick/install.q4
-rw-r--r--src/luarocks/test-original.lua (renamed from src/luarocks/test-incomplete.lua)57
-rw-r--r--src/luarocks/test.lua52
-rw-r--r--src/luarocks/test.tl17
4 files changed, 60 insertions, 70 deletions
diff --git a/spec/quick/install.q b/spec/quick/install.q
index 18f80eee..e2df4283 100644
--- a/spec/quick/install.q
+++ b/spec/quick/install.q
@@ -536,7 +536,7 @@ return "hasdep"
536RUN: luarocks build myrock-2.0-1.rockspec 536RUN: luarocks build myrock-2.0-1.rockspec
537RUN: luarocks build hasdep-1.0-1.rockspec 537RUN: luarocks build hasdep-1.0-1.rockspec
538RUN: luarocks build myrock-1.0-1.rockspec 538RUN: luarocks build myrock-1.0-1.rockspec
539VERBOSE: true 539
540STDERR: 540STDERR:
541-------------------------------------------------------------------------------- 541--------------------------------------------------------------------------------
542Will not remove myrock 2.0 542Will not remove myrock 2.0
@@ -607,7 +607,7 @@ return "hasdep"
607RUN: luarocks build myrock-2.0-1.rockspec 607RUN: luarocks build myrock-2.0-1.rockspec
608RUN: luarocks build hasdep-1.0-1.rockspec 608RUN: luarocks build hasdep-1.0-1.rockspec
609RUN: luarocks build myrock-1.0-1.rockspec --force 609RUN: luarocks build myrock-1.0-1.rockspec --force
610VERBOSE: true 610
611STDERR: 611STDERR:
612-------------------------------------------------------------------------------- 612--------------------------------------------------------------------------------
613The following packages may be broken by this forced removal 613The following packages may be broken by this forced removal
diff --git a/src/luarocks/test-incomplete.lua b/src/luarocks/test-original.lua
index 762b98b5..d074b950 100644
--- a/src/luarocks/test-incomplete.lua
+++ b/src/luarocks/test-original.lua
@@ -1,24 +1,10 @@
1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local pcall = _tl_compat and _tl_compat.pcall or pcall; local table = _tl_compat and _tl_compat.table or table; local test = {TestModules = {}, }
2
3
4
5
6
7 1
2local test = {}
8 3
9local fetch = require("luarocks.fetch") 4local fetch = require("luarocks.fetch")
10local deps = require("luarocks.deps") 5local deps = require("luarocks.deps")
11local util = require("luarocks.util") 6local util = require("luarocks.util")
12 7
13
14
15
16
17
18
19
20
21
22local test_types = { 8local test_types = {
23 "busted", 9 "busted",
24 "command", 10 "command",
@@ -27,15 +13,10 @@ local test_types = {
27local test_modules = {} 13local test_modules = {}
28 14
29for _, test_type in ipairs(test_types) do 15for _, test_type in ipairs(test_types) do
30 local mod 16 local mod = require("luarocks.test." .. test_type)
31 if test_type == "command" then
32 mod = require("luarocks.test.command")
33 elseif test_type == "busted" then
34 mod = require("luarocks.test.busted")
35 end
36 table.insert(test_modules, mod) 17 table.insert(test_modules, mod)
37 test_modules.typetomod[test_type] = mod 18 test_modules[test_type] = mod
38 test_modules.modtotype[mod] = test_type 19 test_modules[mod] = test_type
39end 20end
40 21
41local function get_test_type(rockspec) 22local function get_test_type(rockspec)
@@ -45,14 +26,14 @@ local function get_test_type(rockspec)
45 26
46 for _, test_module in ipairs(test_modules) do 27 for _, test_module in ipairs(test_modules) do
47 if test_module.detect_type() then 28 if test_module.detect_type() then
48 return test_modules.modtotype[test_module] 29 return test_modules[test_module]
49 end 30 end
50 end 31 end
51 32
52 return nil, "could not detect test type -- no test suite for " .. rockspec.package .. "?" 33 return nil, "could not detect test type -- no test suite for " .. rockspec.package .. "?"
53end 34end
54 35
55 36-- Run test suite as configured in rockspec in the current directory.
56function test.run_test_suite(rockspec_arg, test_type, args, prepare) 37function test.run_test_suite(rockspec_arg, test_type, args, prepare)
57 local rockspec 38 local rockspec
58 if type(rockspec_arg) == "string" then 39 if type(rockspec_arg) == "string" then
@@ -62,12 +43,13 @@ function test.run_test_suite(rockspec_arg, test_type, args, prepare)
62 return nil, err, errcode 43 return nil, err, errcode
63 end 44 end
64 else 45 else
46 assert(type(rockspec_arg) == "table")
65 rockspec = rockspec_arg 47 rockspec = rockspec_arg
66 end 48 end
67 49
68 if not test_type then 50 if not test_type then
69 local err 51 local err
70 test_type, err = get_test_type(rockspec) 52 test_type, err = get_test_type(rockspec, test_type)
71 if not test_type then 53 if not test_type then
72 return nil, err 54 return nil, err
73 end 55 end
@@ -80,30 +62,23 @@ function test.run_test_suite(rockspec_arg, test_type, args, prepare)
80 "test_dependencies", 62 "test_dependencies",
81 } 63 }
82 for _, dep_kind in ipairs(all_deps) do 64 for _, dep_kind in ipairs(all_deps) do
83 if (rockspec)[dep_kind] and next((rockspec)[dep_kind]) ~= nil then 65 if rockspec[dep_kind] and next(rockspec[dep_kind]) then
84 local _, err, errcode = deps.fulfill_dependencies(rockspec, dep_kind, "all") 66 local ok, err, errcode = deps.fulfill_dependencies(rockspec, dep_kind, "all")
85 if err then 67 if err then
86 return nil, err, errcode 68 return nil, err, errcode
87 end 69 end
88 end 70 end
89 end 71 end
90 72
91 local pok, test_mod 73 local mod_name = "luarocks.test." .. test_type
92 if test_type == "command" then 74 local pok, test_mod = pcall(require, mod_name)
93 pok, test_mod = pcall(require, "luarocks.test.command") 75 if not pok then
94 if not pok then 76 return nil, "failed loading test execution module " .. mod_name
95 return nil, "failed loading test execution module luarocks.test.command"
96 end
97 elseif test_type == "busted" then
98 pok, test_mod = pcall(require, "luarocks.test.busted")
99 if not pok then
100 return nil, "failed loading test execution module luarocks.test.busted"
101 end
102 end 77 end
103 78
104 if prepare then 79 if prepare then
105 if test_type == "busted" then 80 if test_type == "busted" then
106 return test_mod.run_tests(rockspec.test, { "--version" }) 81 return test_mod.run_tests(rockspec_arg, {"--version"})
107 else 82 else
108 return true 83 return true
109 end 84 end
@@ -112,7 +87,7 @@ function test.run_test_suite(rockspec_arg, test_type, args, prepare)
112 if type(flags) == "table" then 87 if type(flags) == "table" then
113 util.variable_substitutions(flags, rockspec.variables) 88 util.variable_substitutions(flags, rockspec.variables)
114 89
115 90 -- insert any flags given in test.flags at the front of args
116 for i = 1, #flags do 91 for i = 1, #flags do
117 table.insert(args, i, flags[i]) 92 table.insert(args, i, flags[i])
118 end 93 end
diff --git a/src/luarocks/test.lua b/src/luarocks/test.lua
index d074b950..7be3d520 100644
--- a/src/luarocks/test.lua
+++ b/src/luarocks/test.lua
@@ -1,22 +1,36 @@
1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local pcall = _tl_compat and _tl_compat.pcall or pcall; local table = _tl_compat and _tl_compat.table or table; local test = {}
1 2
2local test = {}
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
8
9
10
11
12
13
14
8local test_types = { 15local test_types = {
9 "busted", 16 "busted",
10 "command", 17 "command",
11} 18}
12 19
13local test_modules = {} 20local test_modules = {}
21local typetomod = {}
22local modtotype = {}
14 23
15for _, test_type in ipairs(test_types) do 24for _, test_type in ipairs(test_types) do
16 local mod = require("luarocks.test." .. test_type) 25 local mod
26 if test_type == "command" then
27 mod = require("luarocks.test.command")
28 elseif test_type == "busted" then
29 mod = require("luarocks.test.busted")
30 end
17 table.insert(test_modules, mod) 31 table.insert(test_modules, mod)
18 test_modules[test_type] = mod 32 typetomod[test_type] = mod
19 test_modules[mod] = test_type 33 modtotype[mod] = test_type
20end 34end
21 35
22local function get_test_type(rockspec) 36local function get_test_type(rockspec)
@@ -26,14 +40,14 @@ local function get_test_type(rockspec)
26 40
27 for _, test_module in ipairs(test_modules) do 41 for _, test_module in ipairs(test_modules) do
28 if test_module.detect_type() then 42 if test_module.detect_type() then
29 return test_modules[test_module] 43 return modtotype[test_module]
30 end 44 end
31 end 45 end
32 46
33 return nil, "could not detect test type -- no test suite for " .. rockspec.package .. "?" 47 return nil, "could not detect test type -- no test suite for " .. rockspec.package .. "?"
34end 48end
35 49
36-- Run test suite as configured in rockspec in the current directory. 50
37function test.run_test_suite(rockspec_arg, test_type, args, prepare) 51function test.run_test_suite(rockspec_arg, test_type, args, prepare)
38 local rockspec 52 local rockspec
39 if type(rockspec_arg) == "string" then 53 if type(rockspec_arg) == "string" then
@@ -43,13 +57,12 @@ function test.run_test_suite(rockspec_arg, test_type, args, prepare)
43 return nil, err, errcode 57 return nil, err, errcode
44 end 58 end
45 else 59 else
46 assert(type(rockspec_arg) == "table")
47 rockspec = rockspec_arg 60 rockspec = rockspec_arg
48 end 61 end
49 62
50 if not test_type then 63 if not test_type then
51 local err 64 local err
52 test_type, err = get_test_type(rockspec, test_type) 65 test_type, err = get_test_type(rockspec)
53 if not test_type then 66 if not test_type then
54 return nil, err 67 return nil, err
55 end 68 end
@@ -62,23 +75,30 @@ function test.run_test_suite(rockspec_arg, test_type, args, prepare)
62 "test_dependencies", 75 "test_dependencies",
63 } 76 }
64 for _, dep_kind in ipairs(all_deps) do 77 for _, dep_kind in ipairs(all_deps) do
65 if rockspec[dep_kind] and next(rockspec[dep_kind]) then 78 if (rockspec)[dep_kind] and next((rockspec)[dep_kind]) ~= nil then
66 local ok, err, errcode = deps.fulfill_dependencies(rockspec, dep_kind, "all") 79 local _, err, errcode = deps.fulfill_dependencies(rockspec, dep_kind, "all")
67 if err then 80 if err then
68 return nil, err, errcode 81 return nil, err, errcode
69 end 82 end
70 end 83 end
71 end 84 end
72 85
73 local mod_name = "luarocks.test." .. test_type 86 local pok, test_mod
74 local pok, test_mod = pcall(require, mod_name) 87 if test_type == "command" then
75 if not pok then 88 pok, test_mod = pcall(require, "luarocks.test.command")
76 return nil, "failed loading test execution module " .. mod_name 89 if not pok then
90 return nil, "failed loading test execution module luarocks.test.command"
91 end
92 elseif test_type == "busted" then
93 pok, test_mod = pcall(require, "luarocks.test.busted")
94 if not pok then
95 return nil, "failed loading test execution module luarocks.test.busted"
96 end
77 end 97 end
78 98
79 if prepare then 99 if prepare then
80 if test_type == "busted" then 100 if test_type == "busted" then
81 return test_mod.run_tests(rockspec_arg, {"--version"}) 101 return test_mod.run_tests(rockspec.test, { "--version" })
82 else 102 else
83 return true 103 return true
84 end 104 end
@@ -87,7 +107,7 @@ function test.run_test_suite(rockspec_arg, test_type, args, prepare)
87 if type(flags) == "table" then 107 if type(flags) == "table" then
88 util.variable_substitutions(flags, rockspec.variables) 108 util.variable_substitutions(flags, rockspec.variables)
89 109
90 -- insert any flags given in test.flags at the front of args 110
91 for i = 1, #flags do 111 for i = 1, #flags do
92 table.insert(args, i, flags[i]) 112 table.insert(args, i, flags[i])
93 end 113 end
diff --git a/src/luarocks/test.tl b/src/luarocks/test.tl
index 86d572d8..3345a7eb 100644
--- a/src/luarocks/test.tl
+++ b/src/luarocks/test.tl
@@ -1,9 +1,4 @@
1local record test 1local record test
2 record TestModules
3 {TestRunner}
4 typetomod: {string: TestRunner}
5 modtotype: {TestRunner: string}
6 end
7end 2end
8 3
9local fetch = require("luarocks.fetch") 4local fetch = require("luarocks.fetch")
@@ -17,14 +12,14 @@ local type Dependencies = r.Dependencies
17local type t = require("luarocks.core.types.testrunner") 12local type t = require("luarocks.core.types.testrunner")
18local type TestRunner = t.TestRunner 13local type TestRunner = t.TestRunner
19 14
20local type TestModules = test.TestModules
21
22local test_types = { 15local test_types = {
23 "busted", 16 "busted",
24 "command", 17 "command",
25} 18}
26 19
27local test_modules: TestModules = {} 20local test_modules: {TestRunner} = {}
21local typetomod: {string: TestRunner} = {}
22local modtotype: {TestRunner: string} = {}
28 23
29for _, test_type in ipairs(test_types) do 24for _, test_type in ipairs(test_types) do
30 local mod: TestRunner 25 local mod: TestRunner
@@ -34,8 +29,8 @@ for _, test_type in ipairs(test_types) do
34 mod = require("luarocks.test.busted") 29 mod = require("luarocks.test.busted")
35 end 30 end
36 table.insert(test_modules, mod) 31 table.insert(test_modules, mod)
37 test_modules.typetomod[test_type] = mod 32 typetomod[test_type] = mod
38 test_modules.modtotype[mod] = test_type 33 modtotype[mod] = test_type
39end 34end
40 35
41local function get_test_type(rockspec: Rockspec): string, string 36local function get_test_type(rockspec: Rockspec): string, string
@@ -45,7 +40,7 @@ local function get_test_type(rockspec: Rockspec): string, string
45 40
46 for _, test_module in ipairs(test_modules) do 41 for _, test_module in ipairs(test_modules) do
47 if test_module.detect_type() then 42 if test_module.detect_type() then
48 return test_modules.modtotype[test_module] 43 return modtotype[test_module]
49 end 44 end
50 end 45 end
51 46