summaryrefslogtreecommitdiff
path: root/src/luarocks/test
diff options
context:
space:
mode:
authorMike Vink <mike@pionative.com>2025-02-03 21:29:42 +0100
committerMike Vink <mike@pionative.com>2025-02-03 21:29:42 +0100
commit5155816b7b925dec5d5feb1568b1d7ceb00938b9 (patch)
treedeca28ea15e79f6f804c3d90d2ba757881638af5 /src/luarocks/test
fetch tarballHEADmaster
Diffstat (limited to 'src/luarocks/test')
-rw-r--r--src/luarocks/test/busted.lua53
-rw-r--r--src/luarocks/test/command.lua52
2 files changed, 105 insertions, 0 deletions
diff --git a/src/luarocks/test/busted.lua b/src/luarocks/test/busted.lua
new file mode 100644
index 0000000..c73909c
--- /dev/null
+++ b/src/luarocks/test/busted.lua
@@ -0,0 +1,53 @@
+
+local busted = {}
+
+local fs = require("luarocks.fs")
+local deps = require("luarocks.deps")
+local path = require("luarocks.path")
+local dir = require("luarocks.dir")
+local queries = require("luarocks.queries")
+
+local unpack = table.unpack or unpack
+
+function busted.detect_type()
+ if fs.exists(".busted") then
+ return true
+ end
+ return false
+end
+
+function busted.run_tests(test, args)
+ if not test then
+ test = {}
+ end
+
+ local ok, bustedver, where = deps.fulfill_dependency(queries.new("busted"), nil, nil, nil, "test_dependencies")
+ if not ok then
+ return nil, bustedver
+ end
+
+ local busted_exe
+ if test.busted_executable then
+ busted_exe = test.busted_executable
+ else
+ busted_exe = dir.path(path.root_dir(where), "bin", "busted")
+
+ -- Windows fallback
+ local busted_bat = dir.path(path.root_dir(where), "bin", "busted.bat")
+
+ if not fs.exists(busted_exe) and not fs.exists(busted_bat) then
+ return nil, "'busted' executable failed to be installed"
+ end
+ end
+
+ local err
+ ok, err = fs.execute(busted_exe, unpack(args))
+ if ok then
+ return true
+ else
+ return nil, err or "test suite failed."
+ end
+end
+
+
+return busted
diff --git a/src/luarocks/test/command.lua b/src/luarocks/test/command.lua
new file mode 100644
index 0000000..bed6744
--- /dev/null
+++ b/src/luarocks/test/command.lua
@@ -0,0 +1,52 @@
+
+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