diff options
| author | William Boman <william@redwill.se> | 2023-10-11 16:31:50 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2025-02-19 09:22:40 +0100 |
| commit | 047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc (patch) | |
| tree | c50c22cd05d3605fc5a1e8eb902ffeb11e339697 /tests/helpers | |
| parent | refactor(receipt): change receipt structure and remove old builder APIs (#1521) (diff) | |
| download | mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.gz mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.bz2 mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.lz mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.xz mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.zst mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.zip | |
refactor!: refactor installer internals and add new Package class methods (#1523)
This contains the following changes:
1) `Package:install()` now accepts a second, optional, callback argument which is called when installation finishes
(successfully or not).
2) Adds a `Package:is_installing()` method.
This contains the following breaking changes:
1) `Package:install()` will now error when called while an installation is already ongoing. Use the new
`Package:is_installing()` method to check whether an installation is already running.
This also refactors large portions of the tests by removing test globals, removing async_test, and adding the
`mason-test` Lua module instead. Test helpers via globals are problematic to work with due to not being detected through
tools like the Lua language server without additional configuration. This has been replaced with a Lua module
`mason-test`. `async_test` has also been removed in favour of explicitly making use of the `mason-core.async` API. These
changes stands for a significant portion of the diff.
Diffstat (limited to 'tests/helpers')
| -rw-r--r-- | tests/helpers/lua/luassertx.lua | 21 | ||||
| -rw-r--r-- | tests/helpers/lua/test_helpers.lua | 70 |
2 files changed, 21 insertions, 70 deletions
diff --git a/tests/helpers/lua/luassertx.lua b/tests/helpers/lua/luassertx.lua index e9bc4e44..3de3bf15 100644 --- a/tests/helpers/lua/luassertx.lua +++ b/tests/helpers/lua/luassertx.lua @@ -2,6 +2,26 @@ local a = require "mason-core.async" local assert = require "luassert" local match = require "luassert.match" +local function wait(_, arguments) + ---@type (fun()) Function to execute until it does not error. + local assertions_fn = arguments[1] + ---@type number Timeout in milliseconds. Defaults to 5000. + local timeout = arguments[2] or 5000 + + local err + if + not vim.wait(timeout, function() + local ok, err_ = pcall(assertions_fn) + err = err_ + return ok + end, math.min(timeout, 100)) + then + error(err) + end + + return true +end + local function wait_for(_, arguments) ---@type (fun()) Function to execute until it does not error. local assertions_fn = arguments[1] @@ -76,3 +96,4 @@ assert:register("matcher", "list_containing", list_containing) assert:register("matcher", "instanceof", instanceof) assert:register("matcher", "capture", capture) assert:register("assertion", "wait_for", wait_for) +assert:register("assertion", "wait", wait) diff --git a/tests/helpers/lua/test_helpers.lua b/tests/helpers/lua/test_helpers.lua deleted file mode 100644 index c7d6f983..00000000 --- a/tests/helpers/lua/test_helpers.lua +++ /dev/null @@ -1,70 +0,0 @@ ----@diagnostic disable: lowercase-global -local spy = require "luassert.spy" -local util = require "luassert.util" - -local InstallContext = require "mason-core.installer.context" -local InstallHandle = require "mason-core.installer.handle" -local Result = require "mason-core.result" -local a = require "mason-core.async" -local path = require "mason-core.path" -local registry = require "mason-registry" - --- selene: allow(unused_variable) -function async_test(suspend_fn) - return function() - local ok, err = pcall(a.run_blocking, suspend_fn) - if not ok then - error(err, util.errorlevel()) - end - end -end - --- selene: allow(unscoped_variables, incorrect_standard_library_use) -mockx = { - just_runs = function() end, - returns = function(val) - return function() - return val - end - end, - throws = function(exception) - return function() - error(exception, 2) - end - end, -} - ----@param opts? PackageInstallOpts -function create_dummy_context(opts) - local ctx = InstallContextGenerator(InstallHandleGenerator "registry", opts) - ctx.cwd:set(path.package_build_prefix "registry") - ctx.spawn = setmetatable({}, { - __index = function(s, cmd) - s[cmd] = spy.new(function() - return Result.success { stdout = nil, stderr = nil } - end) - return s[cmd] - end, - }) - return ctx -end - --- selene: allow(unused_variable) ----@param package_name string -function InstallHandleGenerator(package_name) - return InstallHandle.new(registry.get_package(package_name)) -end - --- selene: allow(unused_variable) ----@param handle InstallHandle ----@param opts PackageInstallOpts? -function InstallContextGenerator(handle, opts) - local context = InstallContext.new(handle, opts or {}) - context.spawn = setmetatable({ strict_mode = true }, { - __index = function(self, cmd) - self[cmd] = spy.new(mockx.just_runs()) - return self[cmd] - end, - }) - return context -end |
