diff --git a/CHANGES.md b/CHANGES.md index fae2b8b..24fb390 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ Notable changes to `libtmux`. - Docs: The API export includes `examples/api/run.sh` for releases that use it to start tmux. Readers can run those releases’ examples with the supplied script. +- Docs: The API export identifies the numbered rock named by the selected + checkout’s `release.json`, even when older rockspecs are present. - Runtime: `Runtime:start_server` starts a private tmux server and resolves to an `OwnedServer` with its `server` handle, its `socket_path` and `stop()`. The server lives in a new directory under `root` (the system temporary diff --git a/scripts/docs/export.lua b/scripts/docs/export.lua index 5c65bde..1752e43 100644 --- a/scripts/docs/export.lua +++ b/scripts/docs/export.lua @@ -1,6 +1,7 @@ -- Export the public LuaLS model, the source guides and the examples as deterministic JSON, for -- the documentation site to render. local api_examples = require("docs.api_examples") +local release = require("release.release") local files = require("support.files") local fs = require("support.fs") local json = require("support.json") @@ -179,29 +180,16 @@ end ---@param source string ---@return table function M.rock_metadata(source) - local specs = {} - for _, name in ipairs(fs.list(source .. "/rockspecs")) do - if name:match("^libtmux%-.*%.rockspec$") then - specs[#specs + 1] = name - end - end - if #specs == 0 then - fail("could not find libtmux rockspec") - end - local release = specs[#specs] - for _, name in ipairs(specs) do - if not name:find("-scm-", 1, true) then - release = name - break - end - end + local candidate = release.candidate(source) + local source_tag = "v" .. release.identity(candidate) + local spec = "rockspecs/libtmux-" .. candidate .. ".rockspec" local version, tag - for _, line in ipairs(read_lines(source .. "/rockspecs/" .. release)) do + for _, line in ipairs(read_lines(source .. "/" .. spec)) do version = version or line:match('^version = "([^"]+)"') tag = tag or line:match('^%s+tag = "([^"]+)"') end - if not version or not tag then - fail("could not read rock version and source tag") + if version ~= candidate or tag ~= source_tag then + fail(spec .. " must declare version " .. candidate .. " and source tag " .. source_tag) end return { name = "libtmux", version = version, source_tag = tag } end diff --git a/scripts/docs/tests/test_export.lua b/scripts/docs/tests/test_export.lua index ca9ffce..c83f986 100644 --- a/scripts/docs/tests/test_export.lua +++ b/scripts/docs/tests/test_export.lua @@ -1,6 +1,7 @@ local test = require("luaunit") local export = require("docs.export") local files = require("support.files") +local fs = require("support.fs") local json = require("support.json") local repo = require("support.repo") local M = {} @@ -165,6 +166,29 @@ function M.test_the_rock_metadata_and_bundles_come_from_the_checkout() end end +function M.test_the_export_uses_the_rock_named_in_the_selected_release() + local root = fs.mkdtemp("libtmux-docs-version-") + fs.mkdir_p(root .. "/rockspecs") + files.write(root .. "/release.json", '{"package":"libtmux","version":"0.2.0beta1-2"}\n') + for _, version in ipairs({ "0.1.0-1", "0.2.0beta1-2", "0.3.0-1" }) do + local path = root .. "/rockspecs/libtmux-" .. version .. ".rockspec" + local tag = "v" .. assert(version:match("^(.+)%-")) + files.write(path, ('version = "%s"\nsource = {\n tag = "%s",\n}\n'):format(version, tag)) + end + local ok, metadata = pcall(export.rock_metadata, root) + local spec = root .. "/rockspecs/libtmux-0.2.0beta1-2.rockspec" + files.write(spec, (files.read(spec):gsub("v0%.2%.0beta1", "v0.1.0"))) + local accepted, failure = pcall(export.rock_metadata, root) + fs.remove_tree(root) + test.assertTrue(ok, tostring(metadata)) + test.assertEquals( + metadata, + { name = "libtmux", version = "0.2.0beta1-2", source_tag = "v0.2.0beta1" } + ) + test.assertFalse(accepted, "accepted a rockspec for a different source release") + test.assertStrContains(tostring(failure), "v0.2.0beta1") +end + function M.test_server_overview_names_exactly_the_class_members() local listed, declared = server_members(read("lua/libtmux/_internal/server.lua")) test.assertTrue(next(declared) ~= nil)