diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/helpers/lua/luassertx.lua | 8 | ||||
| -rw-r--r-- | tests/mason-core/installer/installer_spec.lua | 26 |
2 files changed, 28 insertions, 6 deletions
diff --git a/tests/helpers/lua/luassertx.lua b/tests/helpers/lua/luassertx.lua index 3eba3fa4..d6d24d8e 100644 --- a/tests/helpers/lua/luassertx.lua +++ b/tests/helpers/lua/luassertx.lua @@ -64,7 +64,15 @@ local function instanceof(_, arguments, _) end end +local function capture(_, arguments, _) + return function(value) + arguments[1](value) + return true + end +end + assert:register("matcher", "tbl_containing", tbl_containing) assert:register("matcher", "list_containing", list_containing) assert:register("matcher", "instanceof", instanceof) +assert:register("matcher", "capture", capture) assert:register("assertion", "wait_for", wait_for) diff --git a/tests/mason-core/installer/installer_spec.lua b/tests/mason-core/installer/installer_spec.lua index 8dc9b516..ead08f18 100644 --- a/tests/mason-core/installer/installer_spec.lua +++ b/tests/mason-core/installer/installer_spec.lua @@ -57,12 +57,26 @@ describe("installer", function() "should write receipt", async_test(function() spy.on(fs.async, "write_file") - local handle = InstallHandleGenerator "dummy" - installer.execute(handle, {}) - assert.spy(fs.async.write_file).was_called(1) - assert - .spy(fs.async.write_file) - .was_called_with(("%s/mason-receipt.json"):format(handle.package:get_install_path()), match.is_string()) + local handler = InstallHandleGenerator "dummy" + ---@param ctx InstallContext + handler.package.spec.install = function(ctx) + ctx.receipt:with_primary_source { type = "source", metadata = {} } + ctx.fs:write_file("target", "script-contents") + ctx:link_bin("executable", "target") + end + installer.execute(handler, {}) + assert.spy(fs.async.write_file).was_called_with( + ("%s/mason-receipt.json"):format(handler.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", metadata = {} }, receipt.primary_source) + assert.same({}, receipt.secondary_sources) + assert.same("1.0", receipt.schema_version) + assert.same({ bin = { executable = "target" } }, receipt.links) + end) + ) end) ) |
