diff options
| author | William Boman <william@redwill.se> | 2022-07-13 03:34:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-13 01:34:33 +0000 |
| commit | 720016d4fa525770d13e0933b05c919a5939622c (patch) | |
| tree | cb2885c26c0104c1398b26cc387e3eb264faaed1 /tests | |
| parent | feat: add cspell spell checker (#65) (diff) | |
| download | mason-720016d4fa525770d13e0933b05c919a5939622c.tar mason-720016d4fa525770d13e0933b05c919a5939622c.tar.gz mason-720016d4fa525770d13e0933b05c919a5939622c.tar.bz2 mason-720016d4fa525770d13e0933b05c919a5939622c.tar.lz mason-720016d4fa525770d13e0933b05c919a5939622c.tar.xz mason-720016d4fa525770d13e0933b05c919a5939622c.tar.zst mason-720016d4fa525770d13e0933b05c919a5939622c.zip | |
fix(api): fix the :MasonUninstall command (#66)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/helpers/lua/dummy2_package.lua | 14 | ||||
| -rw-r--r-- | tests/mason/api/command_spec.lua | 77 | ||||
| -rw-r--r-- | tests/minimal_init.vim | 1 |
3 files changed, 92 insertions, 0 deletions
diff --git a/tests/helpers/lua/dummy2_package.lua b/tests/helpers/lua/dummy2_package.lua new file mode 100644 index 00000000..424e47d7 --- /dev/null +++ b/tests/helpers/lua/dummy2_package.lua @@ -0,0 +1,14 @@ +local Pkg = require "mason-core.package" + +return Pkg.new { + name = "dummy2", + desc = [[This is a dummy2 package.]], + categories = { Pkg.Cat.LSP }, + languages = { Pkg.Lang.Dummy2Lang }, + homepage = "https://example.com", + ---@async + ---@param ctx InstallContext + install = function(ctx) + ctx.receipt:with_primary_source { type = "dummy2" } + end, +} diff --git a/tests/mason/api/command_spec.lua b/tests/mason/api/command_spec.lua new file mode 100644 index 00000000..06b2e5db --- /dev/null +++ b/tests/mason/api/command_spec.lua @@ -0,0 +1,77 @@ +local spy = require "luassert.spy" +local match = require "luassert.match" +local log = require "mason-core.log" + +local a = require "mason-core.async" +local api = require "mason.api.command" +local registry = require "mason-registry" +local Pkg = require "mason-core.package" + +describe(":Mason", function() + it( + "should open the UI window", + async_test(function() + api.Mason() + a.scheduler() + local win = vim.api.nvim_get_current_win() + local buf = vim.api.nvim_win_get_buf(win) + assert.equals("mason.nvim", vim.api.nvim_buf_get_option(buf, "filetype")) + end) + ) +end) + +describe(":MasonInstall", function() + it( + "should install the provided packages", + async_test(function() + local dummy = registry.get_package "dummy" + local dummy2 = registry.get_package "dummy2" + spy.on(Pkg, "install") + api.MasonInstall { fargs = { "dummy@1.0.0", "dummy2" } } + assert.spy(Pkg.install).was_called(2) + assert.spy(Pkg.install).was_called_with(match.is_ref(dummy), { version = "1.0.0" }) + assert + .spy(Pkg.install) + .was_called_with(match.is_ref(dummy2), match.tbl_containing { version = match.is_nil() }) + end) + ) + + it( + "should open the UI window", + async_test(function() + local dummy = registry.get_package "dummy" + spy.on(dummy, "install") + api.MasonInstall { fargs = { "dummy" } } + local win = vim.api.nvim_get_current_win() + local buf = vim.api.nvim_win_get_buf(win) + assert.equals("mason.nvim", vim.api.nvim_buf_get_option(buf, "filetype")) + end) + ) +end) + +describe(":MasonUninstall", function() + it( + "should uninstall the provided packages", + async_test(function() + local dummy = registry.get_package "dummy" + local dummy2 = registry.get_package "dummy" + spy.on(Pkg, "uninstall") + api.MasonUninstall { fargs = { "dummy", "dummy2" } } + assert.spy(Pkg.uninstall).was_called(2) + assert.spy(Pkg.uninstall).was_called_with(match.is_ref(dummy)) + assert.spy(Pkg.uninstall).was_called_with(match.is_ref(dummy2)) + end) + ) +end) + +describe(":MasonLog", function() + it("should open the log file", function() + api.MasonLog() + assert.equals(2, #vim.api.nvim_list_tabpages()) + local win = vim.api.nvim_get_current_win() + local buf = vim.api.nvim_win_get_buf(win) + vim.api.nvim_buf_call(buf, function() + assert.equals(log.outfile, vim.fn.expand "%") + end) + end) +end) diff --git a/tests/minimal_init.vim b/tests/minimal_init.vim index 86ed2ba2..1a4bfb31 100644 --- a/tests/minimal_init.vim +++ b/tests/minimal_init.vim @@ -18,6 +18,7 @@ lua require("test_helpers") lua <<EOF local index = require "mason-registry.index" index["dummy"] = "dummy_package" +index["dummy2"] = "dummy_package" require("mason").setup { install_root_dir = os.getenv("INSTALL_ROOT_DIR"), |
