aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core/package
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-10-11 16:31:50 +0200
committerWilliam Boman <william@redwill.se>2025-02-19 09:22:40 +0100
commit047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc (patch)
treec50c22cd05d3605fc5a1e8eb902ffeb11e339697 /tests/mason-core/package
parentrefactor(receipt): change receipt structure and remove old builder APIs (#1521) (diff)
downloadmason-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/mason-core/package')
-rw-r--r--tests/mason-core/package/package_spec.lua123
1 files changed, 62 insertions, 61 deletions
diff --git a/tests/mason-core/package/package_spec.lua b/tests/mason-core/package/package_spec.lua
index 67d49387..622a2ee4 100644
--- a/tests/mason-core/package/package_spec.lua
+++ b/tests/mason-core/package/package_spec.lua
@@ -7,6 +7,16 @@ local spy = require "luassert.spy"
local stub = require "luassert.stub"
describe("package", function()
+ local snapshot
+
+ before_each(function()
+ snapshot = assert.snapshot()
+ end)
+
+ after_each(function()
+ snapshot:revert()
+ end)
+
before_each(function()
registry.get_package("dummy"):uninstall()
package.loaded["dummy_package"] = nil
@@ -37,7 +47,7 @@ describe("package", function()
source = {
id = "pkg:mason/package@1",
install = function() end,
- }
+ },
}
local function spec(fields)
return setmetatable(fields, { __index = valid_spec })
@@ -105,26 +115,25 @@ describe("package", function()
dummy.handle = nil
end)
- it(
- "should successfully install package",
- async_test(function()
- local dummy = registry.get_package "dummy"
- local package_install_success_handler = spy.new()
- local package_install_failed_handler = spy.new()
- local install_success_handler = spy.new()
- local install_failed_handler = spy.new()
- registry:once("package:install:success", package_install_success_handler)
- registry:once("package:install:failed", package_install_failed_handler)
- dummy:once("install:success", install_success_handler)
- dummy:once("install:failed", install_failed_handler)
+ it("should successfully install package", function()
+ local dummy = registry.get_package "dummy"
+ local package_install_success_handler = spy.new()
+ local package_install_failed_handler = spy.new()
+ local install_success_handler = spy.new()
+ local install_failed_handler = spy.new()
+ registry:once("package:install:success", package_install_success_handler)
+ registry:once("package:install:failed", package_install_failed_handler)
+ dummy:once("install:success", install_success_handler)
+ dummy:once("install:failed", install_failed_handler)
- local handle = dummy:install { version = "1337" }
+ local handle = dummy:install { version = "1337" }
- assert.wait_for(function()
- assert.is_true(handle:is_closed())
- assert.is_true(dummy:is_installed())
- end)
+ assert.wait(function()
+ assert.is_true(handle:is_closed())
+ assert.is_true(dummy:is_installed())
+ end)
+ assert.wait(function()
assert.spy(install_success_handler).was_called(1)
assert.spy(install_success_handler).was_called_with(match.is_ref(handle))
assert.spy(package_install_success_handler).was_called(1)
@@ -132,45 +141,45 @@ describe("package", function()
assert.spy(package_install_failed_handler).was_called(0)
assert.spy(install_failed_handler).was_called(0)
end)
- )
+ end)
- it(
- "should fail to install package",
- async_test(function()
- local dummy = registry.get_package "dummy"
- stub(dummy.spec.source, "install", function()
- error "I simply refuse to be installed."
- end)
- local package_install_success_handler = spy.new()
- local package_install_failed_handler = spy.new()
- local install_success_handler = spy.new()
- local install_failed_handler = spy.new()
- registry:once("package:install:success", package_install_success_handler)
- registry:once("package:install:failed", package_install_failed_handler)
- dummy:once("install:success", install_success_handler)
- dummy:once("install:failed", install_failed_handler)
+ it("should fail to install package", function()
+ local dummy = registry.get_package "dummy"
+ stub(dummy.spec.source, "install", function()
+ error("I simply refuse to be installed.", 0)
+ end)
+ local package_install_success_handler = spy.new()
+ local package_install_failed_handler = spy.new()
+ local install_success_handler = spy.new()
+ local install_failed_handler = spy.new()
+ registry:once("package:install:success", package_install_success_handler)
+ registry:once("package:install:failed", package_install_failed_handler)
+ dummy:once("install:success", install_success_handler)
+ dummy:once("install:failed", install_failed_handler)
- local handle = dummy:install { version = "1337" }
+ local handle = dummy:install { version = "1337" }
- assert.wait_for(function()
- assert.is_true(handle:is_closed())
- assert.is_false(dummy:is_installed())
- end)
+ assert.wait(function()
+ assert.is_true(handle:is_closed())
+ assert.is_false(dummy:is_installed())
+ end)
+ assert.wait(function()
assert.spy(install_failed_handler).was_called(1)
- assert.spy(install_failed_handler).was_called_with(match.is_ref(handle))
+ assert.spy(install_failed_handler).was_called_with(match.is_ref(handle), "I simply refuse to be installed.")
assert.spy(package_install_failed_handler).was_called(1)
- assert.spy(package_install_failed_handler).was_called_with(match.is_ref(dummy), match.is_ref(handle))
+ assert
+ .spy(package_install_failed_handler)
+ .was_called_with(match.is_ref(dummy), match.is_ref(handle), "I simply refuse to be installed.")
assert.spy(package_install_success_handler).was_called(0)
assert.spy(install_success_handler).was_called(0)
end)
- )
+ end)
- it(
- "should be able to start package installation outside of main loop",
- async_test(function()
- local dummy = registry.get_package "dummy"
+ it("should be able to start package installation outside of main loop", function()
+ local dummy = registry.get_package "dummy"
+ local handle = a.run_blocking(function()
-- Move outside the main loop
a.wait(function(resolve)
local timer = vim.loop.new_timer()
@@ -179,25 +188,19 @@ describe("package", function()
resolve()
end)
end)
-
assert.is_true(vim.in_fast_event())
- local handle = assert.is_not.has_error(function()
+ return assert.is_not.has_error(function()
return dummy:install()
end)
-
- assert.wait_for(function()
- assert.is_true(handle:is_closed())
- end)
end)
- )
+ end)
- it(
- "should be able to instantiate package outside of main loop",
- async_test(function()
- local dummy = registry.get_package "registry"
+ it("should be able to instantiate package outside of main loop", function()
+ local dummy = registry.get_package "registry"
- -- Move outside the main loop
+ -- Move outside the main loop
+ a.run_blocking(function ()
a.wait(function(resolve)
local timer = vim.loop.new_timer()
timer:start(0, 0, function()
@@ -207,12 +210,10 @@ describe("package", function()
end)
assert.is_true(vim.in_fast_event())
-
local pkg = assert.is_not.has_error(function()
return Pkg.new(dummy.spec)
end)
-
assert.same(dummy.spec, pkg.spec)
end)
- )
+ end)
end)