diff options
| author | William Boman <william@redwill.se> | 2022-12-04 19:59:43 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-04 19:59:43 +0100 |
| commit | 98b9091b47bef1795392df0dbcbd9b33f6969c4b (patch) | |
| tree | 0f257f777bd530c7ba966c9afb34a97a126ce608 /tests | |
| parent | feat(mockdebug): write & link mock-debug-adapter executable (#723) (diff) | |
| download | mason-98b9091b47bef1795392df0dbcbd9b33f6969c4b.tar mason-98b9091b47bef1795392df0dbcbd9b33f6969c4b.tar.gz mason-98b9091b47bef1795392df0dbcbd9b33f6969c4b.tar.bz2 mason-98b9091b47bef1795392df0dbcbd9b33f6969c4b.tar.lz mason-98b9091b47bef1795392df0dbcbd9b33f6969c4b.tar.xz mason-98b9091b47bef1795392df0dbcbd9b33f6969c4b.tar.zst mason-98b9091b47bef1795392df0dbcbd9b33f6969c4b.zip | |
feat: show warning message when exiting neovim with active installations (#725)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/mason/terminator_spec.lua | 75 | ||||
| -rw-r--r-- | tests/minimal_init.vim | 2 |
2 files changed, 76 insertions, 1 deletions
diff --git a/tests/mason/terminator_spec.lua b/tests/mason/terminator_spec.lua new file mode 100644 index 00000000..9f243086 --- /dev/null +++ b/tests/mason/terminator_spec.lua @@ -0,0 +1,75 @@ +local stub = require "luassert.stub" +local spy = require "luassert.spy" +local a = require "mason-core.async" +local registry = require "mason-registry" +local terminator = require "mason.terminator" +local _ = require "mason-core.functional" +local InstallHandle = require "mason-core.installer.handle" + +describe("terminator", function() + before_each(function() + terminator.setup() + end) + + it( + "should terminate all active handles on nvim exit", + async_test(function() + local dummy = registry.get_package "dummy" + local dummy2 = registry.get_package "dummy2" + for _, pkg in ipairs { dummy, dummy2 } do + stub(pkg.spec, "install") + pkg.spec.install.invokes(function() + a.sleep(10000) + end) + end + + dummy:install() + dummy2:install() + spy.on(InstallHandle, "terminate") + + terminator.terminate() + a.scheduler() + + assert.spy(InstallHandle.terminate).was_called(2) + end) + ) + + it( + "should print warning messages", + async_test(function() + spy.on(vim.api, "nvim_echo") + spy.on(vim.api, "nvim_err_writeln") + local dummy = registry.get_package "dummy" + local dummy2 = registry.get_package "dummy2" + for _, pkg in ipairs { dummy, dummy2 } do + stub(pkg.spec, "install") + pkg.spec.install.invokes(function() + a.sleep(10000) + end) + end + + dummy:install() + dummy2:install() + spy.on(InstallHandle, "terminate") + + terminator.terminate() + + assert.spy(vim.api.nvim_echo).was_called(1) + assert.spy(vim.api.nvim_echo).was_called_with({ + { + "[mason.nvim] Neovim is exiting while packages are still installing. Terminating all installations…", + "WarningMsg", + }, + }, true, {}) + + a.scheduler() + + assert.spy(vim.api.nvim_err_writeln).was_called(1) + assert.spy(vim.api.nvim_err_writeln).was_called_with(_.dedent [[ + [mason.nvim] Neovim exited while the following packages were installing. Installation was aborted. + - dummy + - dummy2 + ]]) + end) + ) +end) diff --git a/tests/minimal_init.vim b/tests/minimal_init.vim index ab61d7ed..f099416c 100644 --- a/tests/minimal_init.vim +++ b/tests/minimal_init.vim @@ -18,7 +18,7 @@ lua require("test_helpers") lua <<EOF local index = require "mason-registry.index" index["dummy"] = "dummy_package" -index["dummy2"] = "dummy_package" +index["dummy2"] = "dummy2_package" require("mason").setup { install_root_dir = vim.env.INSTALL_ROOT_DIR, |
