aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-02-17 20:08:45 +0100
committerGitHub <noreply@github.com>2023-02-17 20:08:45 +0100
commitf3d90e3b7580a2d1b47a1f9b905808e22a7fac87 (patch)
treed8d1822c88f8f8da9a11cdb45cb3207530510662 /tests
parentchore(workflows): change autogenerate commit message (#1004) (diff)
downloadmason-f3d90e3b7580a2d1b47a1f9b905808e22a7fac87.tar
mason-f3d90e3b7580a2d1b47a1f9b905808e22a7fac87.tar.gz
mason-f3d90e3b7580a2d1b47a1f9b905808e22a7fac87.tar.bz2
mason-f3d90e3b7580a2d1b47a1f9b905808e22a7fac87.tar.lz
mason-f3d90e3b7580a2d1b47a1f9b905808e22a7fac87.tar.xz
mason-f3d90e3b7580a2d1b47a1f9b905808e22a7fac87.tar.zst
mason-f3d90e3b7580a2d1b47a1f9b905808e22a7fac87.zip
feat(installer): add share links (#965)
* feat(installer): add share links Adds the ability to symlink share files to ~/.local/share/nvim/mason/share (default location). This is currently not used by any packages but will be soon (e.g. linking .jar files to a canonical location on the fs). This also includes the following changes: - fix(windows): correctly unlink executables Prior to this change, executables on Windows would not be removed when uninstalling a package. - refactor(installer): use Result interfaces The motivation behind this is to move away from exceptions and pcalls to leverage the Result interface. This allows for better error messaging during installation, as well as improved composability of actions that may or may not fail. - refactor(bin): use absolute paths in exec wrapper scripts While relative paths are preferred and will end up returning in the future, they i) cannot be guaranteed for all packages, and ii) is somewhat complicated to produce due to lack of std APIs. Moving the entire Mason installation directory was never officially supported anyway. - feat(installer): add "force" flag When this flag is true, any existing executables or share files will be overridden if they exist (i.e. mangle another package installation). * refactor(result): always return Result objects in Result.try The rationale here used to be that exceptions in Result.try() blocks were treated truly as exceptions that should interrupt code execution per Lua's traditional error handling semantics. However, Lua code is somewhat prone to raise exceptions when you don't expect it to (especially when interacting with loosely documented external APIs). Combine this with the fact that code that invokes Result.try() blocks generally doesn't `pcall` and only relies on the Result API to handle errors, you end up with code that only gracefully handles one class of errors (the well-known ones). * test(terminator): sleep in tests to avoid race condition I've no idea why this doesn't pass in CI, works just fine locally.
Diffstat (limited to 'tests')
-rw-r--r--tests/mason-core/installer/installer_spec.lua8
-rw-r--r--tests/mason-core/installer/linker_spec.lua77
-rw-r--r--tests/mason-core/managers/cargo_spec.lua6
-rw-r--r--tests/mason-core/managers/composer_spec.lua2
-rw-r--r--tests/mason-core/managers/dotnet_spec.lua2
-rw-r--r--tests/mason-core/managers/gem_spec.lua2
-rw-r--r--tests/mason-core/managers/git_spec.lua4
-rw-r--r--tests/mason-core/managers/github_spec.lua4
-rw-r--r--tests/mason-core/managers/go_spec.lua2
-rw-r--r--tests/mason-core/managers/luarocks_spec.lua4
-rw-r--r--tests/mason-core/managers/npm_spec.lua4
-rw-r--r--tests/mason-core/managers/opam_spec.lua2
-rw-r--r--tests/mason-core/managers/pip3_spec.lua7
-rw-r--r--tests/mason-core/result_spec.lua29
-rw-r--r--tests/mason-core/terminator_spec.lua28
15 files changed, 144 insertions, 37 deletions
diff --git a/tests/mason-core/installer/installer_spec.lua b/tests/mason-core/installer/installer_spec.lua
index c9c44d24..1092ebd1 100644
--- a/tests/mason-core/installer/installer_spec.lua
+++ b/tests/mason-core/installer/installer_spec.lua
@@ -1,6 +1,7 @@
local stub = require "luassert.stub"
local spy = require "luassert.spy"
local match = require "luassert.match"
+local stub = require "luassert.stub"
local fs = require "mason-core.fs"
local a = require "mason-core.async"
local path = require "mason-core.path"
@@ -44,7 +45,8 @@ describe("installer", function()
error("something went wrong. don't try again.", 0)
end)
local handler = InstallHandleGenerator "dummy"
- handler.package.spec.install = installer_fn
+ stub(handler.package.spec, "install")
+ handler.package.spec.install.invokes(installer_fn)
local result = installer.execute(handler, {})
assert.spy(installer_fn).was_called(1)
assert.is_true(result:is_failure())
@@ -74,8 +76,8 @@ describe("installer", function()
assert.equals("dummy", receipt.name)
assert.same({ type = "source", metadata = {} }, receipt.primary_source)
assert.same({}, receipt.secondary_sources)
- assert.same("1.0", receipt.schema_version)
- assert.same({ bin = { executable = "target" } }, receipt.links)
+ assert.same("1.1", receipt.schema_version)
+ assert.same({ bin = { executable = "target" }, share = {} }, receipt.links)
end)
)
end)
diff --git a/tests/mason-core/installer/linker_spec.lua b/tests/mason-core/installer/linker_spec.lua
index 5d3abd29..57dba607 100644
--- a/tests/mason-core/installer/linker_spec.lua
+++ b/tests/mason-core/installer/linker_spec.lua
@@ -12,9 +12,9 @@ EXIT /b
SETLOCAL
CALL :find_dp0
-endLocal & goto #_undefined_# 2>NUL || title %%COMSPEC%% & "%%dp0%%\%s" %%*]]
+endLocal & goto #_undefined_# 2>NUL || title %%COMSPEC%% & "%s" %%*]]
-describe("installer", function()
+describe("linker", function()
---@module "mason-core.installer.linker"
local linker
---@module "mason-core.platform"
@@ -48,16 +48,17 @@ describe("installer", function()
local ctx = InstallContextGenerator(handle)
ctx:link_bin("my-executable", path.concat { "nested", "path", "my-executable" })
ctx:link_bin("another-executable", "another-executable")
- linker.link(ctx)
+ assert.is_true(linker.link(ctx):is_success())
assert.spy(fs.async.write_file).was_called(0)
assert.spy(fs.async.symlink).was_called(2)
assert
.spy(fs.async.symlink)
- .was_called_with("../packages/dummy/another-executable", path.bin_prefix "another-executable")
- assert
- .spy(fs.async.symlink)
- .was_called_with("../packages/dummy/nested/path/my-executable", path.bin_prefix "my-executable")
+ .was_called_with(path.concat { dummy:get_install_path(), "another-executable" }, path.bin_prefix "another-executable")
+ assert.spy(fs.async.symlink).was_called_with(
+ path.concat { dummy:get_install_path(), "nested", "path", "my-executable" },
+ path.bin_prefix "my-executable"
+ )
end)
)
@@ -88,19 +89,63 @@ describe("installer", function()
local ctx = InstallContextGenerator(handle)
ctx:link_bin("my-executable", path.concat { "nested", "path", "my-executable" })
ctx:link_bin("another-executable", "another-executable")
- linker.link(ctx)
+ assert.is_true(linker.link(ctx):is_success())
assert.spy(fs.async.symlink).was_called(0)
assert.spy(fs.async.write_file).was_called(2)
+ assert.spy(fs.async.write_file).was_called_with(
+ path.bin_prefix "another-executable.cmd",
+ WIN_CMD_SCRIPT:format(path.concat { dummy:get_install_path(), "another-executable" })
+ )
+ assert.spy(fs.async.write_file).was_called_with(
+ path.bin_prefix "my-executable.cmd",
+ WIN_CMD_SCRIPT:format(path.concat { dummy:get_install_path(), "nested", "path", "my-executable" })
+ )
+ end)
+ )
+
+ it(
+ "should symlink share files",
+ async_test(function()
+ local dummy = registry.get_package "dummy"
+ stub(fs.async, "mkdirp")
+ stub(fs.async, "dir_exists")
+ stub(fs.async, "file_exists")
+ stub(fs.async, "symlink")
+ stub(fs.async, "write_file")
+
+ -- mock non-existent dest files
+ fs.async.file_exists.on_call_with(path.share_prefix "share-file").returns(false)
+ fs.async.file_exists.on_call_with(path.share_prefix(path.concat { "nested", "share-file" })).returns(false)
+
+ fs.async.dir_exists.on_call_with(path.share_prefix()).returns(false)
+ fs.async.dir_exists.on_call_with(path.share_prefix "nested/path").returns(false)
+
+ -- mock existent source files
+ fs.async.file_exists.on_call_with(path.concat { dummy:get_install_path(), "share-file" }).returns(true)
+ fs.async.file_exists
+ .on_call_with(path.concat { dummy:get_install_path(), "nested", "path", "to", "share-file" })
+ .returns(true)
+
+ local handle = InstallHandleGenerator "dummy"
+ local ctx = InstallContextGenerator(handle)
+ ctx:link_share("nested/path/share-file", path.concat { "nested", "path", "to", "share-file" })
+ ctx:link_share("share-file", "share-file")
+ assert.is_true(linker.link(ctx):is_success())
+
+ assert.spy(fs.async.write_file).was_called(0)
+ assert.spy(fs.async.symlink).was_called(2)
assert
- .spy(fs.async.write_file)
- .was_called_with(path.bin_prefix "another-executable.cmd", WIN_CMD_SCRIPT:format "../packages/dummy/another-executable")
- assert
- .spy(fs.async.write_file)
- .was_called_with(
- path.bin_prefix "my-executable.cmd",
- WIN_CMD_SCRIPT:format "../packages/dummy/nested/path/my-executable"
- )
+ .spy(fs.async.symlink)
+ .was_called_with(path.concat { dummy:get_install_path(), "share-file" }, path.share_prefix "share-file")
+ assert.spy(fs.async.symlink).was_called_with(
+ path.concat { dummy:get_install_path(), "nested", "path", "to", "share-file" },
+ path.share_prefix "nested/path/share-file"
+ )
+
+ assert.spy(fs.async.mkdirp).was_called(2)
+ assert.spy(fs.async.mkdirp).was_called_with(path.share_prefix())
+ assert.spy(fs.async.mkdirp).was_called_with(path.share_prefix "nested/path")
end)
)
end)
diff --git a/tests/mason-core/managers/cargo_spec.lua b/tests/mason-core/managers/cargo_spec.lua
index b5b07cf1..bdf1bb09 100644
--- a/tests/mason-core/managers/cargo_spec.lua
+++ b/tests/mason-core/managers/cargo_spec.lua
@@ -18,6 +18,7 @@ describe("cargo manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, cargo.crate "my-crate")
assert.spy(ctx.spawn.cargo).was_called(1)
assert.spy(ctx.spawn.cargo).was_called_with {
@@ -38,6 +39,7 @@ describe("cargo manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, cargo.crate("my-crate", { git = { url = "https://my-crate.git" } }))
assert.spy(ctx.spawn.cargo).was_called(1)
assert.spy(ctx.spawn.cargo).was_called_with {
@@ -58,6 +60,7 @@ describe("cargo manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, cargo.crate("crate-name", { git = { url = "https://my-crate.git" } }))
assert.spy(ctx.spawn.cargo).was_called(1)
assert.spy(ctx.spawn.cargo).was_called_with {
@@ -78,6 +81,7 @@ describe("cargo manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, cargo.crate("my-crate", { features = "lsp" }))
assert.spy(ctx.spawn.cargo).was_called(1)
assert.spy(ctx.spawn.cargo).was_called_with {
@@ -100,6 +104,7 @@ describe("cargo manager", function()
stub(github, "tag")
github.tag.returns { tag = "v2.1.1", with_receipt = mockx.just_runs }
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(
ctx,
cargo.crate("my-crate", {
@@ -128,6 +133,7 @@ describe("cargo manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, cargo.crate "main-package")
assert.same({
type = "cargo",
diff --git a/tests/mason-core/managers/composer_spec.lua b/tests/mason-core/managers/composer_spec.lua
index 44841061..9097c3d5 100644
--- a/tests/mason-core/managers/composer_spec.lua
+++ b/tests/mason-core/managers/composer_spec.lua
@@ -14,6 +14,7 @@ describe("composer manager", function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
ctx.fs.file_exists = spy.new(mockx.returns(false))
+ installer.prepare_installer(ctx)
installer.exec_in_context(
ctx,
composer.packages { "main-package", "supporting-package", "supporting-package2" }
@@ -40,6 +41,7 @@ describe("composer manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(
ctx,
composer.packages { "main-package", "supporting-package", "supporting-package2" }
diff --git a/tests/mason-core/managers/dotnet_spec.lua b/tests/mason-core/managers/dotnet_spec.lua
index df3f5386..e61bebb8 100644
--- a/tests/mason-core/managers/dotnet_spec.lua
+++ b/tests/mason-core/managers/dotnet_spec.lua
@@ -7,6 +7,7 @@ describe("dotnet manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, dotnet.package "main-package")
assert.spy(ctx.spawn.dotnet).was_called(1)
assert.spy(ctx.spawn.dotnet).was_called_with {
@@ -26,6 +27,7 @@ describe("dotnet manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, dotnet.package "main-package")
assert.same({
type = "dotnet",
diff --git a/tests/mason-core/managers/gem_spec.lua b/tests/mason-core/managers/gem_spec.lua
index 93973b3e..ea497794 100644
--- a/tests/mason-core/managers/gem_spec.lua
+++ b/tests/mason-core/managers/gem_spec.lua
@@ -15,6 +15,7 @@ describe("gem manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, gem.packages { "main-package", "supporting-package", "supporting-package2" })
assert.spy(ctx.spawn.gem).was_called(1)
assert.spy(ctx.spawn.gem).was_called_with(match.tbl_containing {
@@ -38,6 +39,7 @@ describe("gem manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, gem.packages { "main-package", "supporting-package", "supporting-package2" })
assert.same({
type = "gem",
diff --git a/tests/mason-core/managers/git_spec.lua b/tests/mason-core/managers/git_spec.lua
index ec157ecc..fc0a5167 100644
--- a/tests/mason-core/managers/git_spec.lua
+++ b/tests/mason-core/managers/git_spec.lua
@@ -14,6 +14,7 @@ describe("git manager", function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
local err = assert.has_error(function()
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, function()
git.clone {}
end)
@@ -28,6 +29,7 @@ describe("git manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, function()
git.clone { "https://github.com/williamboman/mason.nvim.git" }
end)
@@ -48,6 +50,7 @@ describe("git manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "1337" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, function()
git.clone { "https://github.com/williamboman/mason.nvim.git" }
end)
@@ -76,6 +79,7 @@ describe("git manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, function()
git.clone({ "https://github.com/williamboman/mason.nvim.git" }).with_receipt()
end)
diff --git a/tests/mason-core/managers/github_spec.lua b/tests/mason-core/managers/github_spec.lua
index 05c8af3a..f2f85210 100644
--- a/tests/mason-core/managers/github_spec.lua
+++ b/tests/mason-core/managers/github_spec.lua
@@ -14,6 +14,7 @@ describe("github release file", function()
stub(client, "fetch_latest_release")
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
+ installer.prepare_installer(ctx)
local source = installer.exec_in_context(ctx, function()
return github.release_file {
repo = "williamboman/mason.nvim",
@@ -39,6 +40,7 @@ describe("github release file", function()
}))
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
+ installer.prepare_installer(ctx)
local source = installer.exec_in_context(ctx, function()
return github.release_file {
repo = "williamboman/mason.nvim",
@@ -66,6 +68,7 @@ describe("github release version", function()
stub(client, "fetch_latest_release")
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
+ installer.prepare_installer(ctx)
local source = installer.exec_in_context(ctx, function()
return github.release_version {
repo = "williamboman/mason.nvim",
@@ -85,6 +88,7 @@ describe("github release version", function()
client.fetch_latest_release.returns(Result.success { tag_name = "v42" })
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
+ installer.prepare_installer(ctx)
local source = installer.exec_in_context(ctx, function()
return github.release_version {
repo = "williamboman/mason.nvim",
diff --git a/tests/mason-core/managers/go_spec.lua b/tests/mason-core/managers/go_spec.lua
index 6a7f0a9c..5ca1bfb8 100644
--- a/tests/mason-core/managers/go_spec.lua
+++ b/tests/mason-core/managers/go_spec.lua
@@ -13,6 +13,7 @@ describe("go manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, go.packages { "main-package", "supporting-package", "supporting-package2" })
assert.spy(ctx.spawn.go).was_called(3)
assert.spy(ctx.spawn.go).was_called_with {
@@ -41,6 +42,7 @@ describe("go manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, go.packages { "main-package", "supporting-package", "supporting-package2" })
assert.same({
type = "go",
diff --git a/tests/mason-core/managers/luarocks_spec.lua b/tests/mason-core/managers/luarocks_spec.lua
index 98376adc..67cddbc0 100644
--- a/tests/mason-core/managers/luarocks_spec.lua
+++ b/tests/mason-core/managers/luarocks_spec.lua
@@ -8,6 +8,7 @@ describe("luarocks manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, luarocks.package "lua-cjson")
assert.spy(ctx.spawn.luarocks).was_called(1)
assert.spy(ctx.spawn.luarocks).was_called_with {
@@ -27,6 +28,7 @@ describe("luarocks manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "1.2.3" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, luarocks.package "lua-cjson")
assert.spy(ctx.spawn.luarocks).was_called(1)
assert.spy(ctx.spawn.luarocks).was_called_with {
@@ -46,6 +48,7 @@ describe("luarocks manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, luarocks.package("lua-cjson", { dev = true }))
assert.spy(ctx.spawn.luarocks).was_called(1)
assert.spy(ctx.spawn.luarocks).was_called_with {
@@ -65,6 +68,7 @@ describe("luarocks manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, luarocks.package("luaformatter", { server = "https://luarocks.org/dev" }))
assert.spy(ctx.spawn.luarocks).was_called(1)
assert.spy(ctx.spawn.luarocks).was_called_with {
diff --git a/tests/mason-core/managers/npm_spec.lua b/tests/mason-core/managers/npm_spec.lua
index 6bfa518d..144adaf3 100644
--- a/tests/mason-core/managers/npm_spec.lua
+++ b/tests/mason-core/managers/npm_spec.lua
@@ -15,6 +15,7 @@ describe("npm manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, npm.packages { "main-package", "supporting-package", "supporting-package2" })
assert.spy(ctx.spawn.npm).was_called_with(match.tbl_containing {
"install",
@@ -34,6 +35,7 @@ describe("npm manager", function()
local ctx = InstallContextGenerator(handle)
ctx.fs.file_exists = mockx.returns(false)
ctx.fs.dir_exists = mockx.returns(false)
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, function()
npm.install { "main-package", "supporting-package", "supporting-package2" }
end)
@@ -51,6 +53,7 @@ describe("npm manager", function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
ctx.fs.append_file = spy.new(mockx.just_runs())
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, npm.packages { "main-package", "supporting-package", "supporting-package2" })
assert.spy(ctx.fs.append_file).was_called(1)
assert.spy(ctx.fs.append_file).was_called_with(ctx.fs, ".npmrc", "global-style=true")
@@ -62,6 +65,7 @@ describe("npm manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, npm.packages { "main-package", "supporting-package", "supporting-package2" })
assert.same({
type = "npm",
diff --git a/tests/mason-core/managers/opam_spec.lua b/tests/mason-core/managers/opam_spec.lua
index 22d0a55b..f0eb96db 100644
--- a/tests/mason-core/managers/opam_spec.lua
+++ b/tests/mason-core/managers/opam_spec.lua
@@ -8,6 +8,7 @@ describe("opam manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(
ctx,
opam.packages { "main-package", "supporting-package", "supporting-package2" }
@@ -32,6 +33,7 @@ describe("opam manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(
ctx,
opam.packages { "main-package", "supporting-package", "supporting-package2" }
diff --git a/tests/mason-core/managers/pip3_spec.lua b/tests/mason-core/managers/pip3_spec.lua
index 7422084f..b6baf346 100644
--- a/tests/mason-core/managers/pip3_spec.lua
+++ b/tests/mason-core/managers/pip3_spec.lua
@@ -29,6 +29,7 @@ describe("pip3 manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(
ctx,
pip3.packages { "main-package", "supporting-package", "supporting-package2" }
@@ -68,6 +69,7 @@ describe("pip3 manager", function()
ctx.spawn.python = spy.new(mockx.throws())
ctx.spawn[vim.g.python3_host_prog] = spy.new(mockx.throws())
local err = assert.has_error(function()
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, pip3.packages { "package" })
end)
vim.g.python3_host_prog = nil
@@ -89,6 +91,7 @@ describe("pip3 manager", function()
ctx.spawn.python = spy.new(mockx.returns {})
ctx.spawn[vim.g.python3_host_prog] = spy.new(mockx.returns {})
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, pip3.packages { "package" })
vim.g.python3_host_prog = nil
assert.spy(ctx.spawn.python3).was_called(0)
@@ -106,6 +109,7 @@ describe("pip3 manager", function()
ctx.spawn.python = spy.new(mockx.returns {})
ctx.spawn[vim.env.HOME .. "/python3"] = spy.new(mockx.returns {})
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, pip3.packages { "package" })
a.scheduler()
vim.g.python3_host_prog = nil
@@ -123,6 +127,7 @@ describe("pip3 manager", function()
}
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, pip3.packages { "package" })
assert.spy(ctx.spawn.python).was_called(1)
assert.spy(ctx.spawn.python).was_called_with {
@@ -148,6 +153,7 @@ describe("pip3 manager", function()
}
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
+ installer.prepare_installer(ctx)
installer.exec_in_context(ctx, pip3.packages { "package" })
assert.spy(ctx.spawn.python).was_called(2)
assert.spy(ctx.spawn.python).was_called_with {
@@ -178,6 +184,7 @@ describe("pip3 manager", function()
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
+ installer.prepare_installer(ctx)
installer.exec_in_context(
ctx,
pip3.packages { "main-package", "supporting-package", "supporting-package2" }
diff --git a/tests/mason-core/result_spec.lua b/tests/mason-core/result_spec.lua
index b2900753..70495bb7 100644
--- a/tests/mason-core/result_spec.lua
+++ b/tests/mason-core/result_spec.lua
@@ -242,13 +242,12 @@ describe("Result.try", function()
end)
)
- local err = assert.has_error(function()
- Result.try(function(try)
- local err = try(Result.success "42")
- error(err)
- end)
+ local failure = Result.try(function(try)
+ local err = try(Result.success "42")
+ error(err, 0)
end)
- assert.equals("42", err)
+ assert.is_true(failure:is_failure())
+ assert.equals("42", failure:err_or_nil())
end)
it(
@@ -263,14 +262,13 @@ describe("Result.try", function()
return hello .. world
end)
)
- local err = assert.has_error(function()
- Result.try(function(try)
- a.sleep(10)
- local err = try(Result.success "42")
- error(err)
- end)
+ local failure = Result.try(function(try)
+ a.sleep(10)
+ local err = try(Result.success "42")
+ error(err)
end)
- assert.equals("42", err)
+ assert.is_true(failure:is_failure())
+ assert.is_true(match.matches ": 42$"(failure:err_or_nil()))
end)
)
@@ -310,9 +308,12 @@ describe("Result.try", function()
Result.try(function(try)
a.sleep(10)
local greeting = try(Result.success "Hello from the %s!")
+ a.sleep(10)
return greeting:format(try(Result.try(function(try)
a.sleep(10)
- return try(Result.success "underworld")
+ local value = try(Result.success "underworld")
+ a.sleep(10)
+ return value
end)))
end)
)
diff --git a/tests/mason-core/terminator_spec.lua b/tests/mason-core/terminator_spec.lua
index f40b2746..a04372e4 100644
--- a/tests/mason-core/terminator_spec.lua
+++ b/tests/mason-core/terminator_spec.lua
@@ -11,6 +11,8 @@ describe("terminator", function()
it(
"should terminate all active handles on nvim exit",
async_test(function()
+ -- TODO: Tests on CI fail for some reason - sleeping helps
+ a.sleep(500)
spy.on(InstallHandle, "terminate")
local dummy = registry.get_package "dummy"
local dummy2 = registry.get_package "dummy2"
@@ -21,18 +23,26 @@ describe("terminator", function()
end)
end
- dummy:install()
- dummy2:install()
+ local dummy_handle = dummy:install()
+ local dummy2_handle = dummy2:install()
terminator.terminate(5000)
a.scheduler()
assert.spy(InstallHandle.terminate).was_called(2)
+ assert.spy(InstallHandle.terminate).was_called_with(match.is_ref(dummy_handle))
+ assert.spy(InstallHandle.terminate).was_called_with(match.is_ref(dummy2_handle))
+ assert.wait_for(function()
+ assert.is_true(dummy_handle:is_closed())
+ assert.is_true(dummy2_handle:is_closed())
+ end)
end)
)
it(
"should print warning messages",
async_test(function()
+ -- TODO: Tests on CI fail for some reason - sleeping helps
+ a.sleep(500)
spy.on(vim.api, "nvim_echo")
spy.on(vim.api, "nvim_err_writeln")
spy.on(InstallHandle, "terminate")
@@ -45,8 +55,8 @@ describe("terminator", function()
end)
end
- dummy:install()
- dummy2:install()
+ local dummy_handle = dummy:install()
+ local dummy2_handle = dummy2:install()
terminator.terminate(5000)
assert.spy(vim.api.nvim_echo).was_called(1)
@@ -65,12 +75,18 @@ describe("terminator", function()
- dummy
- dummy2
]])
+ assert.wait_for(function()
+ assert.is_true(dummy_handle:is_closed())
+ assert.is_true(dummy2_handle:is_closed())
+ end)
end)
)
it(
"should send SIGTERM and then SIGKILL after grace period",
async_test(function()
+ -- TODO: Tests on CI fail for some reason - sleeping helps
+ a.sleep(500)
spy.on(InstallHandle, "kill")
local dummy = registry.get_package "dummy"
stub(dummy.spec, "install")
@@ -91,6 +107,10 @@ describe("terminator", function()
assert.spy(InstallHandle.kill).was_called_with(match.is_ref(handle), 15) -- SIGTERM
assert.spy(InstallHandle.kill).was_called_with(match.is_ref(handle), 9) -- SIGKILL
end)
+
+ assert.wait_for(function()
+ assert.is_true(handle:is_closed())
+ end)
end)
)
end)