From e287f492cafc0fb7ec6b1e1a3c64ad8fa290a224 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 23 Apr 2018 10:59:52 -0300 Subject: test: auto-install busted if not found --- src/luarocks/test/busted.lua | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/test/busted.lua b/src/luarocks/test/busted.lua index 989f283f..a3aaed08 100644 --- a/src/luarocks/test/busted.lua +++ b/src/luarocks/test/busted.lua @@ -2,6 +2,10 @@ 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 @@ -16,7 +20,22 @@ function busted.run_tests(test, args) if not test then test = {} end - + + local ok, bustedver, where = deps.fulfill_dependency(queries.new("busted")) + 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") + if not fs.exists(busted_exe) then + return nil, "'busted' executable failed to be installed" + end + end + if type(test.flags) == "table" then -- insert any flags given in test.flags at the front of args for i = 1, #test.flags do @@ -24,7 +43,12 @@ function busted.run_tests(test, args) end end - return fs.execute("busted", unpack(args)) + local ok, err = fs.execute(busted_exe, unpack(args)) + if ok then + return true + else + return nil, err or "test suite failed." + end end -- cgit v1.2.3-55-g6feb