aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-12 23:58:27 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-12 23:58:27 +0300
commitb0fbb1bc377a3563cf995136321f480cc53414ca (patch)
tree2cd3cd23648061033fc7cf382cb8d9827ca0425a
parent7782e5d3519fd7a163ab09c8345be7813d117da1 (diff)
downloadluarocks-b0fbb1bc377a3563cf995136321f480cc53414ca.tar.gz
luarocks-b0fbb1bc377a3563cf995136321f480cc53414ca.tar.bz2
luarocks-b0fbb1bc377a3563cf995136321f480cc53414ca.zip
busted and command
-rw-r--r--src/luarocks/core/types/rockspec.tl3
-rw-r--r--src/luarocks/core/types/testrunner.d.tl10
-rw-r--r--src/luarocks/fs.d.tl2
-rw-r--r--src/luarocks/test.tl8
-rw-r--r--src/luarocks/test/busted-original.lua53
-rw-r--r--src/luarocks/test/busted.lua10
-rw-r--r--src/luarocks/test/busted.tl9
-rw-r--r--src/luarocks/test/command-original.lua52
-rw-r--r--src/luarocks/test/command.lua14
-rw-r--r--src/luarocks/test/command.tl5
10 files changed, 149 insertions, 17 deletions
diff --git a/src/luarocks/core/types/rockspec.tl b/src/luarocks/core/types/rockspec.tl
index 265d4cb1..37f2f240 100644
--- a/src/luarocks/core/types/rockspec.tl
+++ b/src/luarocks/core/types/rockspec.tl
@@ -55,6 +55,9 @@ local record rockspec
55 55
56 record Test 56 record Test
57 type: string 57 type: string
58 script: string
59 command: string
60 busted_executable: string
58 flags: {string} 61 flags: {string}
59 end 62 end
60 63
diff --git a/src/luarocks/core/types/testrunner.d.tl b/src/luarocks/core/types/testrunner.d.tl
new file mode 100644
index 00000000..0b6c05c9
--- /dev/null
+++ b/src/luarocks/core/types/testrunner.d.tl
@@ -0,0 +1,10 @@
1local type r = require("luarocks.core.types.rockspec")
2local type Test = r.Test
3
4local record testrunner
5 record TestRunner
6 detect_type: function(): boolean
7 run_tests: function(Test, {string}): boolean, string, string
8 end
9end
10return testrunner \ No newline at end of file
diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl
index dcfaa954..c2b2af33 100644
--- a/src/luarocks/fs.d.tl
+++ b/src/luarocks/fs.d.tl
@@ -16,7 +16,7 @@ local record fs
16 delete: function(string) 16 delete: function(string)
17 -- signing 17 -- signing
18 is_tool_available: function(string, string): string, string 18 is_tool_available: function(string, string): string, string
19 execute: function(...: string): boolean --? boolean? src/luarocks/signing.tl: 27 19 execute: function(...: string): boolean, string, string
20 make_temp_dir: function(string): string, string 20 make_temp_dir: function(string): string, string
21 change_dir: function(string): boolean, string 21 change_dir: function(string): boolean, string
22 pop_dir: function(): boolean 22 pop_dir: function(): boolean
diff --git a/src/luarocks/test.tl b/src/luarocks/test.tl
index b1a97495..b3f2a0fc 100644
--- a/src/luarocks/test.tl
+++ b/src/luarocks/test.tl
@@ -9,15 +9,19 @@ local type r = require("luarocks.core.types.rockspec")
9local type Rockspec = r.Rockspec 9local type Rockspec = r.Rockspec
10local type Test = r.Test 10local type Test = r.Test
11 11
12
13local type t = require("luarocks.core.types.testrunner")
14local type TestRunner = t.TestRunner
15
12local test_types = { 16local test_types = {
13 "busted", 17 "busted",
14 "command", 18 "command",
15} 19}
16 20
17local test_modules: {string | Test} = {} 21local test_modules: {string | TestRunner} = {}
18 22
19for _, test_type in ipairs(test_types) do 23for _, test_type in ipairs(test_types) do
20 local mod: Test 24 local mod: TestRunner
21 if test_type == "command" then 25 if test_type == "command" then
22 mod = require("luarocks.test.command") 26 mod = require("luarocks.test.command")
23 elseif test_type == "busted" then 27 elseif test_type == "busted" then
diff --git a/src/luarocks/test/busted-original.lua b/src/luarocks/test/busted-original.lua
new file mode 100644
index 00000000..c73909cf
--- /dev/null
+++ b/src/luarocks/test/busted-original.lua
@@ -0,0 +1,53 @@
1
2local busted = {}
3
4local fs = require("luarocks.fs")
5local deps = require("luarocks.deps")
6local path = require("luarocks.path")
7local dir = require("luarocks.dir")
8local queries = require("luarocks.queries")
9
10local unpack = table.unpack or unpack
11
12function busted.detect_type()
13 if fs.exists(".busted") then
14 return true
15 end
16 return false
17end
18
19function busted.run_tests(test, args)
20 if not test then
21 test = {}
22 end
23
24 local ok, bustedver, where = deps.fulfill_dependency(queries.new("busted"), nil, nil, nil, "test_dependencies")
25 if not ok then
26 return nil, bustedver
27 end
28
29 local busted_exe
30 if test.busted_executable then
31 busted_exe = test.busted_executable
32 else
33 busted_exe = dir.path(path.root_dir(where), "bin", "busted")
34
35 -- Windows fallback
36 local busted_bat = dir.path(path.root_dir(where), "bin", "busted.bat")
37
38 if not fs.exists(busted_exe) and not fs.exists(busted_bat) then
39 return nil, "'busted' executable failed to be installed"
40 end
41 end
42
43 local err
44 ok, err = fs.execute(busted_exe, unpack(args))
45 if ok then
46 return true
47 else
48 return nil, err or "test suite failed."
49 end
50end
51
52
53return busted
diff --git a/src/luarocks/test/busted.lua b/src/luarocks/test/busted.lua
index c73909cf..fc3dfe79 100644
--- a/src/luarocks/test/busted.lua
+++ b/src/luarocks/test/busted.lua
@@ -1,13 +1,15 @@
1 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 table = _tl_compat and _tl_compat.table or table; local _tl_table_unpack = unpack or table.unpack
2local busted = {} 2local busted = {}
3 3
4
4local fs = require("luarocks.fs") 5local fs = require("luarocks.fs")
5local deps = require("luarocks.deps") 6local deps = require("luarocks.deps")
6local path = require("luarocks.path") 7local path = require("luarocks.path")
7local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
8local queries = require("luarocks.queries") 9local queries = require("luarocks.queries")
9 10
10local unpack = table.unpack or unpack 11
12
11 13
12function busted.detect_type() 14function busted.detect_type()
13 if fs.exists(".busted") then 15 if fs.exists(".busted") then
@@ -32,7 +34,7 @@ function busted.run_tests(test, args)
32 else 34 else
33 busted_exe = dir.path(path.root_dir(where), "bin", "busted") 35 busted_exe = dir.path(path.root_dir(where), "bin", "busted")
34 36
35 -- Windows fallback 37
36 local busted_bat = dir.path(path.root_dir(where), "bin", "busted.bat") 38 local busted_bat = dir.path(path.root_dir(where), "bin", "busted.bat")
37 39
38 if not fs.exists(busted_exe) and not fs.exists(busted_bat) then 40 if not fs.exists(busted_exe) and not fs.exists(busted_bat) then
@@ -41,7 +43,7 @@ function busted.run_tests(test, args)
41 end 43 end
42 44
43 local err 45 local err
44 ok, err = fs.execute(busted_exe, unpack(args)) 46 ok, err = fs.execute(busted_exe, _tl_table_unpack(args))
45 if ok then 47 if ok then
46 return true 48 return true
47 else 49 else
diff --git a/src/luarocks/test/busted.tl b/src/luarocks/test/busted.tl
index 0870d178..a3f80644 100644
--- a/src/luarocks/test/busted.tl
+++ b/src/luarocks/test/busted.tl
@@ -8,6 +8,9 @@ local path = require("luarocks.path")
8local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
9local queries = require("luarocks.queries") 9local queries = require("luarocks.queries")
10 10
11local type r = require("luarocks.core.types.rockspec")
12local type Test = r.Test
13
11function busted.detect_type(): boolean 14function busted.detect_type(): boolean
12 if fs.exists(".busted") then 15 if fs.exists(".busted") then
13 return true 16 return true
@@ -15,7 +18,7 @@ function busted.detect_type(): boolean
15 return false 18 return false
16end 19end
17 20
18function busted.run_tests(test, args: {string}): boolean, string --! Test type 21function busted.run_tests(test: Test, args: {string}): boolean, string --! Test type
19 if not test then 22 if not test then
20 test = {} 23 test = {}
21 end 24 end
@@ -25,7 +28,7 @@ function busted.run_tests(test, args: {string}): boolean, string --! Test type
25 return nil, bustedver 28 return nil, bustedver
26 end 29 end
27 30
28 local busted_exe 31 local busted_exe: string
29 if test.busted_executable then 32 if test.busted_executable then
30 busted_exe = test.busted_executable 33 busted_exe = test.busted_executable
31 else 34 else
@@ -39,7 +42,7 @@ function busted.run_tests(test, args: {string}): boolean, string --! Test type
39 end 42 end
40 end 43 end
41 44
42 local err 45 local err: string
43 ok, err = fs.execute(busted_exe, table.unpack(args)) 46 ok, err = fs.execute(busted_exe, table.unpack(args))
44 if ok then 47 if ok then
45 return true 48 return true
diff --git a/src/luarocks/test/command-original.lua b/src/luarocks/test/command-original.lua
new file mode 100644
index 00000000..bed6744e
--- /dev/null
+++ b/src/luarocks/test/command-original.lua
@@ -0,0 +1,52 @@
1
2local command = {}
3
4local fs = require("luarocks.fs")
5local cfg = require("luarocks.core.cfg")
6
7local unpack = table.unpack or unpack
8
9function command.detect_type()
10 if fs.exists("test.lua") then
11 return true
12 end
13 return false
14end
15
16function command.run_tests(test, args)
17 if not test then
18 test = {
19 script = "test.lua"
20 }
21 end
22
23 if not test.script and not test.command then
24 test.script = "test.lua"
25 end
26
27 local ok
28
29 if test.script then
30 if type(test.script) ~= "string" then
31 return nil, "Malformed rockspec: 'script' expects a string"
32 end
33 if not fs.exists(test.script) then
34 return nil, "Test script " .. test.script .. " does not exist"
35 end
36 local lua = fs.Q(cfg.variables["LUA"]) -- get lua interpreter configured
37 ok = fs.execute(lua, test.script, unpack(args))
38 elseif test.command then
39 if type(test.command) ~= "string" then
40 return nil, "Malformed rockspec: 'command' expects a string"
41 end
42 ok = fs.execute(test.command, unpack(args))
43 end
44
45 if ok then
46 return true
47 else
48 return nil, "tests failed with non-zero exit code"
49 end
50end
51
52return command
diff --git a/src/luarocks/test/command.lua b/src/luarocks/test/command.lua
index bed6744e..b7f45cef 100644
--- a/src/luarocks/test/command.lua
+++ b/src/luarocks/test/command.lua
@@ -1,10 +1,12 @@
1 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 table = _tl_compat and _tl_compat.table or table; local _tl_table_unpack = unpack or table.unpack
2local command = {} 2local command = {}
3 3
4
4local fs = require("luarocks.fs") 5local fs = require("luarocks.fs")
5local cfg = require("luarocks.core.cfg") 6local cfg = require("luarocks.core.cfg")
6 7
7local unpack = table.unpack or unpack 8
9
8 10
9function command.detect_type() 11function command.detect_type()
10 if fs.exists("test.lua") then 12 if fs.exists("test.lua") then
@@ -16,7 +18,7 @@ end
16function command.run_tests(test, args) 18function command.run_tests(test, args)
17 if not test then 19 if not test then
18 test = { 20 test = {
19 script = "test.lua" 21 script = "test.lua",
20 } 22 }
21 end 23 end
22 24
@@ -33,13 +35,13 @@ function command.run_tests(test, args)
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"])
37 ok = fs.execute(lua, test.script, unpack(args)) 39 ok = fs.execute(lua, test.script, _tl_table_unpack(args))
38 elseif test.command then 40 elseif test.command then
39 if type(test.command) ~= "string" then 41 if type(test.command) ~= "string" then
40 return nil, "Malformed rockspec: 'command' expects a string" 42 return nil, "Malformed rockspec: 'command' expects a string"
41 end 43 end
42 ok = fs.execute(test.command, unpack(args)) 44 ok = fs.execute(test.command, _tl_table_unpack(args))
43 end 45 end
44 46
45 if ok then 47 if ok then
diff --git a/src/luarocks/test/command.tl b/src/luarocks/test/command.tl
index d7781580..1369cba4 100644
--- a/src/luarocks/test/command.tl
+++ b/src/luarocks/test/command.tl
@@ -5,6 +5,9 @@ end
5local fs = require("luarocks.fs") 5local fs = require("luarocks.fs")
6local cfg = require("luarocks.core.cfg") 6local cfg = require("luarocks.core.cfg")
7 7
8local type r = require("luarocks.core.types.rockspec")
9local type Test = r.Test
10
8function command.detect_type(): boolean 11function command.detect_type(): boolean
9 if fs.exists("test.lua") then 12 if fs.exists("test.lua") then
10 return true 13 return true
@@ -12,7 +15,7 @@ function command.detect_type(): boolean
12 return false 15 return false
13end 16end
14 17
15function command.run_tests(test, args): boolean, string --! Test type 18function command.run_tests(test: Test, args: {string}): boolean, string --! Test type
16 if not test then 19 if not test then
17 test = { 20 test = {
18 script = "test.lua" 21 script = "test.lua"