From 9d4bebd145cbdf3185ed68ba1eb4140303eb093f Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Tue, 13 Aug 2024 19:53:11 +0300 Subject: test --- src/luarocks/test-incomplete.lua | 125 --------------------------------------- src/luarocks/test-original.lua | 100 +++++++++++++++++++++++++++++++ src/luarocks/test.lua | 52 +++++++++++----- src/luarocks/test.tl | 17 ++---- 4 files changed, 142 insertions(+), 152 deletions(-) delete mode 100644 src/luarocks/test-incomplete.lua create mode 100644 src/luarocks/test-original.lua (limited to 'src') diff --git a/src/luarocks/test-incomplete.lua b/src/luarocks/test-incomplete.lua deleted file mode 100644 index 762b98b5..00000000 --- a/src/luarocks/test-incomplete.lua +++ /dev/null @@ -1,125 +0,0 @@ -local _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 = {}, } - - - - - - - -local fetch = require("luarocks.fetch") -local deps = require("luarocks.deps") -local util = require("luarocks.util") - - - - - - - - - - -local test_types = { - "busted", - "command", -} - -local test_modules = {} - -for _, test_type in ipairs(test_types) do - local mod - if test_type == "command" then - mod = require("luarocks.test.command") - elseif test_type == "busted" then - mod = require("luarocks.test.busted") - end - table.insert(test_modules, mod) - test_modules.typetomod[test_type] = mod - test_modules.modtotype[mod] = test_type -end - -local function get_test_type(rockspec) - if rockspec.test and rockspec.test.type then - return rockspec.test.type - end - - for _, test_module in ipairs(test_modules) do - if test_module.detect_type() then - return test_modules.modtotype[test_module] - end - end - - return nil, "could not detect test type -- no test suite for " .. rockspec.package .. "?" -end - - -function test.run_test_suite(rockspec_arg, test_type, args, prepare) - local rockspec - if type(rockspec_arg) == "string" then - local err, errcode - rockspec, err, errcode = fetch.load_rockspec(rockspec_arg) - if err then - return nil, err, errcode - end - else - rockspec = rockspec_arg - end - - if not test_type then - local err - test_type, err = get_test_type(rockspec) - if not test_type then - return nil, err - end - end - assert(test_type) - - local all_deps = { - "dependencies", - "build_dependencies", - "test_dependencies", - } - for _, dep_kind in ipairs(all_deps) do - if (rockspec)[dep_kind] and next((rockspec)[dep_kind]) ~= nil then - local _, err, errcode = deps.fulfill_dependencies(rockspec, dep_kind, "all") - if err then - return nil, err, errcode - end - end - end - - local pok, test_mod - if test_type == "command" then - pok, test_mod = pcall(require, "luarocks.test.command") - if not pok then - return nil, "failed loading test execution module luarocks.test.command" - end - elseif test_type == "busted" then - pok, test_mod = pcall(require, "luarocks.test.busted") - if not pok then - return nil, "failed loading test execution module luarocks.test.busted" - end - end - - if prepare then - if test_type == "busted" then - return test_mod.run_tests(rockspec.test, { "--version" }) - else - return true - end - else - local flags = rockspec.test and rockspec.test.flags - if type(flags) == "table" then - util.variable_substitutions(flags, rockspec.variables) - - - for i = 1, #flags do - table.insert(args, i, flags[i]) - end - end - - return test_mod.run_tests(rockspec.test, args) - end -end - -return test diff --git a/src/luarocks/test-original.lua b/src/luarocks/test-original.lua new file mode 100644 index 00000000..d074b950 --- /dev/null +++ b/src/luarocks/test-original.lua @@ -0,0 +1,100 @@ + +local test = {} + +local fetch = require("luarocks.fetch") +local deps = require("luarocks.deps") +local util = require("luarocks.util") + +local test_types = { + "busted", + "command", +} + +local test_modules = {} + +for _, test_type in ipairs(test_types) do + local mod = require("luarocks.test." .. test_type) + table.insert(test_modules, mod) + test_modules[test_type] = mod + test_modules[mod] = test_type +end + +local function get_test_type(rockspec) + if rockspec.test and rockspec.test.type then + return rockspec.test.type + end + + for _, test_module in ipairs(test_modules) do + if test_module.detect_type() then + return test_modules[test_module] + end + end + + return nil, "could not detect test type -- no test suite for " .. rockspec.package .. "?" +end + +-- Run test suite as configured in rockspec in the current directory. +function test.run_test_suite(rockspec_arg, test_type, args, prepare) + local rockspec + if type(rockspec_arg) == "string" then + local err, errcode + rockspec, err, errcode = fetch.load_rockspec(rockspec_arg) + if err then + return nil, err, errcode + end + else + assert(type(rockspec_arg) == "table") + rockspec = rockspec_arg + end + + if not test_type then + local err + test_type, err = get_test_type(rockspec, test_type) + if not test_type then + return nil, err + end + end + assert(test_type) + + local all_deps = { + "dependencies", + "build_dependencies", + "test_dependencies", + } + for _, dep_kind in ipairs(all_deps) do + if rockspec[dep_kind] and next(rockspec[dep_kind]) then + local ok, err, errcode = deps.fulfill_dependencies(rockspec, dep_kind, "all") + if err then + return nil, err, errcode + end + end + end + + local mod_name = "luarocks.test." .. test_type + local pok, test_mod = pcall(require, mod_name) + if not pok then + return nil, "failed loading test execution module " .. mod_name + end + + if prepare then + if test_type == "busted" then + return test_mod.run_tests(rockspec_arg, {"--version"}) + else + return true + end + else + local flags = rockspec.test and rockspec.test.flags + if type(flags) == "table" then + util.variable_substitutions(flags, rockspec.variables) + + -- insert any flags given in test.flags at the front of args + for i = 1, #flags do + table.insert(args, i, flags[i]) + end + end + + return test_mod.run_tests(rockspec.test, args) + end +end + +return test 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 @@ +local _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 = {} -local test = {} local fetch = require("luarocks.fetch") local deps = require("luarocks.deps") local util = require("luarocks.util") + + + + + + + local test_types = { "busted", "command", } local test_modules = {} +local typetomod = {} +local modtotype = {} for _, test_type in ipairs(test_types) do - local mod = require("luarocks.test." .. test_type) + local mod + if test_type == "command" then + mod = require("luarocks.test.command") + elseif test_type == "busted" then + mod = require("luarocks.test.busted") + end table.insert(test_modules, mod) - test_modules[test_type] = mod - test_modules[mod] = test_type + typetomod[test_type] = mod + modtotype[mod] = test_type end local function get_test_type(rockspec) @@ -26,14 +40,14 @@ local function get_test_type(rockspec) for _, test_module in ipairs(test_modules) do if test_module.detect_type() then - return test_modules[test_module] + return modtotype[test_module] end end return nil, "could not detect test type -- no test suite for " .. rockspec.package .. "?" end --- Run test suite as configured in rockspec in the current directory. + function test.run_test_suite(rockspec_arg, test_type, args, prepare) local rockspec if type(rockspec_arg) == "string" then @@ -43,13 +57,12 @@ function test.run_test_suite(rockspec_arg, test_type, args, prepare) return nil, err, errcode end else - assert(type(rockspec_arg) == "table") rockspec = rockspec_arg end if not test_type then local err - test_type, err = get_test_type(rockspec, test_type) + test_type, err = get_test_type(rockspec) if not test_type then return nil, err end @@ -62,23 +75,30 @@ function test.run_test_suite(rockspec_arg, test_type, args, prepare) "test_dependencies", } for _, dep_kind in ipairs(all_deps) do - if rockspec[dep_kind] and next(rockspec[dep_kind]) then - local ok, err, errcode = deps.fulfill_dependencies(rockspec, dep_kind, "all") + if (rockspec)[dep_kind] and next((rockspec)[dep_kind]) ~= nil then + local _, err, errcode = deps.fulfill_dependencies(rockspec, dep_kind, "all") if err then return nil, err, errcode end end end - local mod_name = "luarocks.test." .. test_type - local pok, test_mod = pcall(require, mod_name) - if not pok then - return nil, "failed loading test execution module " .. mod_name + local pok, test_mod + if test_type == "command" then + pok, test_mod = pcall(require, "luarocks.test.command") + if not pok then + return nil, "failed loading test execution module luarocks.test.command" + end + elseif test_type == "busted" then + pok, test_mod = pcall(require, "luarocks.test.busted") + if not pok then + return nil, "failed loading test execution module luarocks.test.busted" + end end if prepare then if test_type == "busted" then - return test_mod.run_tests(rockspec_arg, {"--version"}) + return test_mod.run_tests(rockspec.test, { "--version" }) else return true end @@ -87,7 +107,7 @@ function test.run_test_suite(rockspec_arg, test_type, args, prepare) if type(flags) == "table" then util.variable_substitutions(flags, rockspec.variables) - -- insert any flags given in test.flags at the front of args + for i = 1, #flags do table.insert(args, i, flags[i]) 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 @@ local record test - record TestModules - {TestRunner} - typetomod: {string: TestRunner} - modtotype: {TestRunner: string} - end end local fetch = require("luarocks.fetch") @@ -17,14 +12,14 @@ local type Dependencies = r.Dependencies local type t = require("luarocks.core.types.testrunner") local type TestRunner = t.TestRunner -local type TestModules = test.TestModules - local test_types = { "busted", "command", } -local test_modules: TestModules = {} +local test_modules: {TestRunner} = {} +local typetomod: {string: TestRunner} = {} +local modtotype: {TestRunner: string} = {} for _, test_type in ipairs(test_types) do local mod: TestRunner @@ -34,8 +29,8 @@ for _, test_type in ipairs(test_types) do mod = require("luarocks.test.busted") end table.insert(test_modules, mod) - test_modules.typetomod[test_type] = mod - test_modules.modtotype[mod] = test_type + typetomod[test_type] = mod + modtotype[mod] = test_type end local function get_test_type(rockspec: Rockspec): string, string @@ -45,7 +40,7 @@ local function get_test_type(rockspec: Rockspec): string, string for _, test_module in ipairs(test_modules) do if test_module.detect_type() then - return test_modules.modtotype[test_module] + return modtotype[test_module] end end -- cgit v1.2.3-55-g6feb