diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/helpers/lua/dummy-registry/dummy2_package.lua | 19 | ||||
| -rw-r--r-- | tests/helpers/lua/dummy-registry/dummy_package.lua | 19 | ||||
| -rw-r--r-- | tests/mason-core/installer/installer_spec.lua | 84 | ||||
| -rw-r--r-- | tests/mason-core/package/package_spec.lua | 24 | ||||
| -rw-r--r-- | tests/mason-core/terminator_spec.lua | 18 |
5 files changed, 86 insertions, 78 deletions
diff --git a/tests/helpers/lua/dummy-registry/dummy2_package.lua b/tests/helpers/lua/dummy-registry/dummy2_package.lua index 424e47d7..793404ea 100644 --- a/tests/helpers/lua/dummy-registry/dummy2_package.lua +++ b/tests/helpers/lua/dummy-registry/dummy2_package.lua @@ -1,14 +1,17 @@ local Pkg = require "mason-core.package" return Pkg.new { + schema = "registry+v1", name = "dummy2", - desc = [[This is a dummy2 package.]], - categories = { Pkg.Cat.LSP }, - languages = { Pkg.Lang.Dummy2Lang }, + description = [[This is a dummy2 package.]], homepage = "https://example.com", - ---@async - ---@param ctx InstallContext - install = function(ctx) - ctx.receipt:with_primary_source { type = "dummy2" } - end, + licenses = { Pkg.License.MIT }, + languages = { Pkg.Lang.Dummy2Lang }, + categories = { Pkg.Cat.LSP }, + source = { + id = "pkg:mason/dummy2@1.0.0", + ---@async + ---@param ctx InstallContext + install = function(ctx) end, + }, } diff --git a/tests/helpers/lua/dummy-registry/dummy_package.lua b/tests/helpers/lua/dummy-registry/dummy_package.lua index b38d1cd8..52a709ad 100644 --- a/tests/helpers/lua/dummy-registry/dummy_package.lua +++ b/tests/helpers/lua/dummy-registry/dummy_package.lua @@ -1,14 +1,17 @@ local Pkg = require "mason-core.package" return Pkg.new { + schema = "registry+v1", name = "dummy", - desc = [[This is a dummy package.]], - categories = { Pkg.Cat.LSP }, - languages = { Pkg.Lang.DummyLang }, + description = [[This is a dummy package.]], homepage = "https://example.com", - ---@async - ---@param ctx InstallContext - install = function(ctx) - ctx.receipt:with_primary_source { type = "dummy" } - end, + licenses = { Pkg.License.MIT }, + languages = { Pkg.Lang.DummyLang }, + categories = { Pkg.Cat.LSP }, + source = { + id = "pkg:mason/dummy@1.0.0", + ---@async + ---@param ctx InstallContext + install = function(ctx) end, + }, } diff --git a/tests/mason-core/installer/installer_spec.lua b/tests/mason-core/installer/installer_spec.lua index 23eeb69e..04de82ba 100644 --- a/tests/mason-core/installer/installer_spec.lua +++ b/tests/mason-core/installer/installer_spec.lua @@ -25,12 +25,14 @@ describe("installer", function() spy.on(fs.async, "rename") local handle = InstallHandleGenerator "dummy" - spy.on(handle.package.spec, "install") + spy.on(handle.package.spec.source, "install") local result = installer.execute(handle, {}) assert.is_nil(result:err_or_nil()) - assert.spy(handle.package.spec.install).was_called(1) - assert.spy(handle.package.spec.install).was_called_with(match.instanceof(InstallContext)) + assert.spy(handle.package.spec.source.install).was_called(1) + assert + .spy(handle.package.spec.source.install) + .was_called_with(match.instanceof(InstallContext), match.is_table()) assert.spy(fs.async.mkdirp).was_called_with(path.package_build_prefix "dummy") assert.spy(fs.async.rename).was_called_with(path.package_build_prefix "dummy", path.package_prefix "dummy") end) @@ -45,8 +47,7 @@ describe("installer", function() error("something went wrong. don't try again.", 0) end) local handler = InstallHandleGenerator "dummy" - stub(handler.package.spec, "install") - handler.package.spec.install.invokes(installer_fn) + stub(handler.package.spec.source, "install", installer_fn) local result = installer.execute(handler, {}) assert.spy(installer_fn).was_called(1) assert.is_true(result:is_failure()) @@ -60,40 +61,45 @@ describe("installer", function() "should write receipt", async_test(function() spy.on(fs.async, "write_file") - local handler = InstallHandleGenerator "dummy" - ---@param ctx InstallContext - handler.package.spec.install = function(ctx) - ctx.receipt:with_primary_source { type = "source", source = {} } - + local handle = InstallHandleGenerator "dummy" + stub(handle.package.spec.source, "install", function(ctx) ctx.fs:write_file("target", "") ctx.fs:write_file("file.jar", "") ctx.fs:write_file("opt-cmd", "") - - ctx.links.bin = { - ["executable"] = "target", - } - ctx.links.share = { - ["package/file.jar"] = "file.jar", - } - ctx.links.opt = { - ["package/bin/opt-cmd"] = "opt-cmd", - } - end - installer.execute(handler, {}) + end) + handle.package.spec.bin = { + ["executable"] = "target", + } + handle.package.spec.share = { + ["package/file.jar"] = "file.jar", + } + handle.package.spec.opt = { + ["package/bin/opt-cmd"] = "opt-cmd", + } + installer.execute(handle, {}) + handle.package.spec.bin = {} + handle.package.spec.share = {} + handle.package.spec.opt = {} assert.spy(fs.async.write_file).was_called_with( - ("%s/mason-receipt.json"):format(handler.package:get_install_path()), + ("%s/mason-receipt.json"):format(handle.package:get_install_path()), match.capture(function(arg) ---@type InstallReceipt local receipt = vim.json.decode(arg) - assert.equals("dummy", receipt.name) - assert.same({ type = "source", source = {} }, receipt.primary_source) - assert.same({}, receipt.secondary_sources) - assert.same("1.1", receipt.schema_version) - assert.same({ - bin = { executable = "target" }, - share = { ["package/file.jar"] = "file.jar" }, - opt = { ["package/bin/opt-cmd"] = "opt-cmd" }, - }, receipt.links) + assert.is_true(match.tbl_containing { + name = "dummy", + primary_source = match.same { + type = handle.package.spec.schema, + id = handle.package.spec.source.id, + }, + secondary_sources = match.same {}, + schema_version = "1.1", + metrics = match.is_table(), + links = match.same { + bin = { executable = "target" }, + share = { ["package/file.jar"] = "file.jar" }, + opt = { ["package/bin/opt-cmd"] = "opt-cmd" }, + }, + }(receipt)) end) ) end) @@ -106,7 +112,7 @@ describe("installer", function() local capture = spy.new() local start = timestamp() local handle = InstallHandleGenerator "dummy" - handle.package.spec.install = function(ctx) + stub(handle.package.spec.source, "install", function(ctx) capture(installer.run_concurrently { function() a.sleep(100) @@ -121,8 +127,7 @@ describe("installer", function() return "three" end, }) - ctx.receipt:with_primary_source { type = "dummy" } - end + end) installer.execute(handle, {}) local stop = timestamp() local grace_ms = 25 @@ -136,11 +141,10 @@ describe("installer", function() async_test(function() spy.on(fs.async, "write_file") local handle = InstallHandleGenerator "dummy" - stub(handle.package.spec, "install", function(ctx) + stub(handle.package.spec.source, "install", function(ctx) ctx.stdio_sink.stdout "Hello stdout!\n" ctx.stdio_sink.stderr "Hello " ctx.stdio_sink.stderr "stderr!" - ctx.receipt:with_primary_source { type = "unmanaged" } end) installer.execute(handle, { debug = true }) assert @@ -153,7 +157,7 @@ describe("installer", function() "should raise spawn errors in strict mode", async_test(function() local handle = InstallHandleGenerator "dummy" - stub(handle.package.spec, "install", function(ctx) + stub(handle.package.spec.source, "install", function(ctx) ctx.spawn.bash { "-c", "exit 42" } end) local result = installer.execute(handle, { debug = true }) @@ -173,7 +177,7 @@ describe("installer", function() async_test(function() local handle = InstallHandleGenerator "dummy" local callback = spy.new() - stub(handle.package.spec, "install", function() + stub(handle.package.spec.source, "install", function() a.sleep(3000) end) @@ -197,7 +201,7 @@ describe("installer", function() async_test(function() local handle = InstallHandleGenerator "dummy" local install = spy.new() - stub(handle.package.spec, "install", install) + stub(handle.package.spec.source, "install", install) fs.sync.write_file(path.package_lock "dummy", "dummypid") local result = installer.execute(handle, { debug = true }) diff --git a/tests/mason-core/package/package_spec.lua b/tests/mason-core/package/package_spec.lua index a667cc58..67d49387 100644 --- a/tests/mason-core/package/package_spec.lua +++ b/tests/mason-core/package/package_spec.lua @@ -25,13 +25,19 @@ describe("package", function() if vim.fn.has "nvim-0.11" == 1 then it("should validate spec", function() + ---@type RegistryPackageSpec local valid_spec = { + schema = "registry+v1", name = "Package name", - desc = "Package description", + description = "Package description", homepage = "https://example.com", categories = { Pkg.Cat.LSP }, languages = { Pkg.Lang.Rust }, - install = function() end, + licenses = {}, + source = { + id = "pkg:mason/package@1", + install = function() end, + } } local function spec(fields) return setmetatable(fields, { __index = valid_spec }) @@ -44,9 +50,9 @@ describe("package", function() ) assert.equals( - "desc: expected string, got number", + "description: expected string, got number", assert.has_error(function() - Pkg.new(spec { desc = 23 }) + Pkg.new(spec { description = 23 }) end) ) @@ -70,13 +76,6 @@ describe("package", function() Pkg.new(spec { languages = 23 }) end) ) - - assert.equals( - "install: expected function, got number", - assert.has_error(function() - Pkg.new(spec { install = 23 }) - end) - ) end) end @@ -139,8 +138,7 @@ describe("package", function() "should fail to install package", async_test(function() local dummy = registry.get_package "dummy" - stub(dummy.spec, "install") - dummy.spec.install.invokes(function() + stub(dummy.spec.source, "install", function() error "I simply refuse to be installed." end) local package_install_success_handler = spy.new() diff --git a/tests/mason-core/terminator_spec.lua b/tests/mason-core/terminator_spec.lua index 66b48ba4..24c1ec25 100644 --- a/tests/mason-core/terminator_spec.lua +++ b/tests/mason-core/terminator_spec.lua @@ -15,7 +15,7 @@ describe("terminator", function() local dummy = registry.get_package "dummy" local dummy2 = registry.get_package "dummy2" for _, pkg in ipairs { dummy, dummy2 } do - stub(pkg.spec, "install", function() + stub(pkg.spec.source, "install", function() a.sleep(10000) end) end @@ -24,8 +24,8 @@ describe("terminator", function() local dummy2_handle = dummy2:install() assert.wait_for(function() - assert.spy(dummy.spec.install).was_called() - assert.spy(dummy2.spec.install).was_called() + assert.spy(dummy.spec.source.install).was_called() + assert.spy(dummy2.spec.source.install).was_called() end) terminator.terminate(5000) @@ -49,7 +49,7 @@ describe("terminator", function() local dummy = registry.get_package "dummy" local dummy2 = registry.get_package "dummy2" for _, pkg in ipairs { dummy, dummy2 } do - stub(pkg.spec, "install", function() + stub(pkg.spec.source, "install", function() a.sleep(10000) end) end @@ -58,8 +58,8 @@ describe("terminator", function() local dummy2_handle = dummy2:install() assert.wait_for(function() - assert.spy(dummy.spec.install).was_called() - assert.spy(dummy2.spec.install).was_called() + assert.spy(dummy.spec.source.install).was_called() + assert.spy(dummy2.spec.source.install).was_called() end) terminator.terminate(5000) @@ -92,8 +92,8 @@ describe("terminator", function() async_test(function() spy.on(InstallHandle, "kill") local dummy = registry.get_package "dummy" - stub(dummy.spec, "install") - dummy.spec.install.invokes(function(ctx) + stub(dummy.spec.source, "install") + dummy.spec.source.install.invokes(function(ctx) -- your signals have no power here ctx.spawn.bash { "-c", "function noop { :; }; trap noop SIGTERM; sleep 999999;" } end) @@ -101,7 +101,7 @@ describe("terminator", function() local handle = dummy:install() assert.wait_for(function() - assert.spy(dummy.spec.install).was_called() + assert.spy(dummy.spec.source.install).was_called() end) terminator.terminate(50) |
