From 129207c5088d0c7a4143de20844a898267b471de Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 20 Apr 2018 13:14:36 -0300 Subject: rockspec format: add `test_dependencies` --- src/luarocks/cmd/show.lua | 13 +++++++++++++ src/luarocks/fetch.lua | 2 ++ src/luarocks/test.lua | 10 +++++++++- src/luarocks/type/rockspec.lua | 11 ++++++++++- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/luarocks/cmd/show.lua b/src/luarocks/cmd/show.lua index b76ff778..ffac440b 100644 --- a/src/luarocks/cmd/show.lua +++ b/src/luarocks/cmd/show.lua @@ -22,6 +22,7 @@ With these flags, return only the desired information: --modules all modules provided by this package as used by require() --deps packages this package depends on --build-deps build-only dependencies for this package +--test-deps dependencies for testing this package --rockspec the full path of the rockspec file --mversion the package version --rock-tree local tree where rock is installed @@ -118,6 +119,10 @@ function show.command(flags, name, version) for _, dep in ipairs(rockspec.build_dependencies) do util.printout(tostring(dep)) end + elseif flags["test-deps"] then + for _, dep in ipairs(rockspec.test_dependencies) do + util.printout(tostring(dep)) + end elseif flags["rockspec"] then util.printout(rockspec_file) elseif flags["mversion"] then util.printout(version) else @@ -162,6 +167,14 @@ function show.command(flags, name, version) end end + if #rockspec.test_dependencies > 0 then + util.printout() + util.printout("Tests depend on:") + for _, dep in ipairs(rockspec.test_dependencies) do + util.printout("\t"..tostring(dep).." "..installed_rock_label(dep, flags["tree"])) + end + end + local direct_deps = {} if #rockspec.dependencies > 0 then util.printout() diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 08998986..9ea2b487 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -240,6 +240,7 @@ function fetch.load_local_rockspec(filename, quick) util.platform_overrides(rockspec.build) util.platform_overrides(rockspec.dependencies) util.platform_overrides(rockspec.build_dependencies) + util.platform_overrides(rockspec.test_dependencies) util.platform_overrides(rockspec.external_dependencies) util.platform_overrides(rockspec.source) util.platform_overrides(rockspec.hooks) @@ -288,6 +289,7 @@ function fetch.load_local_rockspec(filename, quick) convert_dependencies(rockspec, "dependencies") convert_dependencies(rockspec, "build_dependencies") + convert_dependencies(rockspec, "test_dependencies") if not quick then path.configure_paths(rockspec) diff --git a/src/luarocks/test.lua b/src/luarocks/test.lua index 2a64a5d8..c7e3e013 100644 --- a/src/luarocks/test.lua +++ b/src/luarocks/test.lua @@ -2,6 +2,7 @@ local test = {} local fetch = require("luarocks.fetch") +local deps = require("luarocks.deps") local test_types = { "busted", @@ -49,7 +50,14 @@ function test.run_test_suite(rockspec_arg, args) if not test_type then return nil, err end - + + if next(rockspec.test_dependencies) then + local ok, err, errcode = deps.fulfill_dependencies(rockspec, "test_dependencies", "all") + if err then + return nil, err, errcode + end + end + local mod_name = "luarocks.test." .. test_type local pok, test_mod = pcall(require, mod_name) if not pok then diff --git a/src/luarocks/type/rockspec.lua b/src/luarocks/type/rockspec.lua index bb36cfc3..16ab911c 100644 --- a/src/luarocks/type/rockspec.lua +++ b/src/luarocks/type/rockspec.lua @@ -57,6 +57,15 @@ local rockspec_types = { _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)", }, }, + test_dependencies = { + _version = "3.0", + platforms = {}, -- recursively defined below + _any = { + _type = "string", + _name = "a valid dependency string", + _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)", + }, + }, supported_platforms = { _any = string_1, }, @@ -125,7 +134,7 @@ type_rockspec.order = {"rockspec_format", "package", "version", { "description", {"summary", "detailed", "homepage", "license" } }, "supported_platforms", "dependencies", "build_dependencies", "external_dependencies", { "build", {"type", "modules", "copy_directories", "platforms"} }, - { "test", {"type"} }, + "test_dependencies", { "test", {"type"} }, "hooks"} rockspec_types.build.platforms._any = rockspec_types.build -- cgit v1.2.3-55-g6feb