Skip to content

Commit 2ceadd8

Browse files
authored
feat(tests): use mason.nvim v2 (#17)
1 parent f81ed28 commit 2ceadd8

2 files changed

Lines changed: 17 additions & 30 deletions

File tree

tests/action.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,17 @@ runs:
9898
shell: bash
9999
run: |
100100
git clone https://github.com/mason-org/mason.nvim "$GITHUB_ACTION_PATH/mason.nvim"
101-
git -C "$GITHUB_ACTION_PATH/mason.nvim" checkout v1.x
102101
103102
- if: ${{ steps.prepare.outputs.PACKAGES != '' }}
104103
uses: rhysd/action-setup-vim@v1
105104
with:
106105
neovim: true
107-
version: v0.7.0
106+
# Minimum supported mason.nvim version
107+
version: v0.10.0
108108

109109
- if: ${{ steps.prepare.outputs.PACKAGES != '' }}
110110
shell: bash
111+
name: mason.nvim healthcheck
111112
id: healthchecks
112113
run: |
113114
nvim --headless \
@@ -117,6 +118,7 @@ runs:
117118
-c qa
118119
119120
- if: ${{ steps.prepare.outputs.PACKAGES != '' }}
121+
name: Install yq
120122
shell: bash
121123
run: |
122124
nvim --headless \
@@ -126,11 +128,13 @@ runs:
126128
-c qa
127129
128130
- if: ${{ steps.prepare.outputs.PACKAGES != '' }}
131+
name: Run package tests
129132
run: nvim --headless -c "luafile $GITHUB_ACTION_PATH/test-runner.lua" -c 1cq
130133
shell: bash
131134
env:
132135
PACKAGES: ${{ steps.prepare.outputs.PACKAGES }}
133136
TARGET: ${{ inputs.target }}
137+
REGISTRY: ${{ github.workspace }}
134138
MASON_VERBOSE_LOGS: "1"
135139
# This is only needed by r-languageserver due to (somewhat unclear) requirements in remotes::install_github().
136140
GITHUB_PAT: ${{ inputs.GITHUB_TOKEN }}

tests/test-runner.lua

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ if GITHUB_ACTION_PATH then
1010
vim.opt.rtp:prepend(GITHUB_ACTION_PATH .. "/mason.nvim")
1111
end
1212

13-
local Pkg = require "mason-core.package"
14-
local spawn = require "mason-core.spawn"
13+
local registry = require "mason-registry"
1514
local _ = require "mason-core.functional"
16-
local fs = require "mason-core.fs"
17-
local path = require "mason-core.path"
1815
local a = require "mason-core.async"
19-
local registry_installer = require "mason-core.installer.registry"
16+
local compiler = require "mason-core.installer.compiler"
2017
local Result = require "mason-core.result"
2118
local platform = require "mason-core.platform"
2219
local Purl = require "mason-core.purl"
@@ -45,30 +42,14 @@ local log = setmetatable({}, {
4542

4643
require("mason").setup {
4744
log_level = vim.log.levels[DEBUG and "DEBUG" or "INFO"],
45+
registries = {
46+
"file:" .. vim.env.REGISTRY
47+
}
4848
}
49+
registry.refresh()
4950

5051
local yq = vim.fn.exepath "yq"
5152

52-
---@param pkg_path string
53-
local function parse_package_spec(pkg_path)
54-
return Result.try(function(try)
55-
local raw_yaml = fs.async.read_file(path.concat { vim.loop.cwd(), pkg_path })
56-
local raw_spec = try(spawn[yq] {
57-
"-o",
58-
"json",
59-
on_spawn = function(_, stdio)
60-
local stdin = stdio[1]
61-
stdin:write(raw_yaml, function()
62-
stdin:shutdown()
63-
end)
64-
end,
65-
})
66-
local spec = vim.json.decode(raw_spec.stdout)
67-
spec.schema = "registry+v1"
68-
return Pkg.new(spec)
69-
end)
70-
end
71-
7253
local is_not_empty = _.complement(_.equals "")
7354

7455
---@param pkg Package
@@ -102,7 +83,7 @@ local function get_targets(pkg)
10283

10384
if VERSION then
10485
for _, target in ipairs(targets) do
105-
if registry_installer.parse(pkg.spec, { target = target, version = VERSION }):is_success() then
86+
if compiler.parse(pkg.spec, { target = target, version = VERSION }):is_success() then
10687
return Result.success { { target = target, version = VERSION } }
10788
else
10889
return Result.failure(("Unsupported platform (version=%s)."):format(VERSION))
@@ -117,7 +98,7 @@ local function get_targets(pkg)
11798
if
11899
Purl.parse(source.id)
119100
:and_then(function(purl)
120-
return registry_installer
101+
return compiler
121102
.parse(pkg.spec, { target = target, version = purl.version })
122103
:on_success(function()
123104
table.insert(resolved_targets, { target = target, version = purl.version })
@@ -143,7 +124,9 @@ local ok, err = pcall(a.run_blocking, function()
143124
log.info("Testing packages", packages)
144125

145126
for __, pkg_path in ipairs(packages) do
146-
local pkg = try(parse_package_spec(pkg_path))
127+
-- Turns "packages/rust-analyzer/package.yaml" into "rust-analyzer"
128+
local pkg_name = vim.fn.fnamemodify(pkg_path, ":h:t")
129+
local pkg = registry.get_package(pkg_name)
147130
a.scheduler()
148131
get_targets(pkg)
149132
:on_success(function(targets)

0 commit comments

Comments
 (0)