diff options
| author | William Boman <william@redwill.se> | 2023-11-07 00:29:18 +0100 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2025-02-19 12:15:48 +0100 |
| commit | 6a7662760c515c74f2c37fc825776ead65d307f9 (patch) | |
| tree | 0f4496d0678c7029b10236cbf48cc0f5ff63c1dc /tests/mason-core/installer | |
| parent | fix(pypi): remove -U flag and fix log message (diff) | |
| download | mason-6a7662760c515c74f2c37fc825776ead65d307f9.tar mason-6a7662760c515c74f2c37fc825776ead65d307f9.tar.gz mason-6a7662760c515c74f2c37fc825776ead65d307f9.tar.bz2 mason-6a7662760c515c74f2c37fc825776ead65d307f9.tar.lz mason-6a7662760c515c74f2c37fc825776ead65d307f9.tar.xz mason-6a7662760c515c74f2c37fc825776ead65d307f9.tar.zst mason-6a7662760c515c74f2c37fc825776ead65d307f9.zip | |
refactor!: change Package API
This changes the following public APIs:
**(_breaking_) Events on the `Package` class**
The `uninstall:success` event on the `Package` class now receives an `InstallReceipt` as argument, instead of an
`InstallHandle`. This receipt is an in-memory representation of what was uninstalled. There's also a new
`uninstall:failed` event for situations where uninstallation for some
reason fails. Note: this also applies to the registry events (i.e.
`package:uninstall:success` and `package:uninstall:failed`).
---
**(_breaking_) `Package:uninstall()` is now asynchronous and receives two new arguments, similarly to `Package:install()`**
While package uninstallations remain synchronous under the hood, the public API has been changed from synchronous ->
asynchronous. Users of this method are recommended to provide a callback in situations where code needs to execute after
uninstallation fully completes.
---
**(_breaking_) `Package:get_install_path()` has been removed.
---
**`Package:install()` now takes an optional callback**
This callback allows consumers to be informed whether installation was successful or not without having to go through a
different, low-level, API. See below for a comparison between the old and new APIs:
```lua
-- before
local handle = pkg:install()
handle:once("closed", function ()
-- ...
end)
-- after
pkg:install({}, function (success, result)
-- ...
end)
```
Diffstat (limited to 'tests/mason-core/installer')
| -rw-r--r-- | tests/mason-core/installer/InstallHandle_spec.lua (renamed from tests/mason-core/installer/handle_spec.lua) | 4 | ||||
| -rw-r--r-- | tests/mason-core/installer/InstallRunner_spec.lua (renamed from tests/mason-core/installer/runner_spec.lua) | 226 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compiler_spec.lua (renamed from tests/mason-core/installer/registry/installer_spec.lua) | 22 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compilers/cargo_spec.lua (renamed from tests/mason-core/installer/registry/compilers/cargo_spec.lua) | 6 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compilers/composer_spec.lua (renamed from tests/mason-core/installer/registry/compilers/composer_spec.lua) | 4 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compilers/gem_spec.lua (renamed from tests/mason-core/installer/registry/compilers/gem_spec.lua) | 4 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compilers/generic/build_spec.lua (renamed from tests/mason-core/installer/registry/compilers/generic/build_spec.lua) | 4 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compilers/generic/download_spec.lua (renamed from tests/mason-core/installer/registry/compilers/generic/download_spec.lua) | 6 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compilers/github/build_spec.lua (renamed from tests/mason-core/installer/registry/compilers/github/build_spec.lua) | 48 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compilers/github/release_spec.lua (renamed from tests/mason-core/installer/registry/compilers/github/release_spec.lua) | 18 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compilers/golang_spec.lua (renamed from tests/mason-core/installer/registry/compilers/golang_spec.lua) | 4 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compilers/luarocks_spec.lua (renamed from tests/mason-core/installer/registry/compilers/luarocks_spec.lua) | 4 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compilers/npm_spec.lua (renamed from tests/mason-core/installer/registry/compilers/npm_spec.lua) | 4 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compilers/nuget_spec.lua (renamed from tests/mason-core/installer/registry/compilers/nuget_spec.lua) | 4 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compilers/opam_spec.lua (renamed from tests/mason-core/installer/registry/compilers/opam_spec.lua) | 4 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compilers/openvsx_spec.lua (renamed from tests/mason-core/installer/registry/compilers/openvsx_spec.lua) | 0 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/compilers/pypi_spec.lua (renamed from tests/mason-core/installer/registry/compilers/pypi_spec.lua) | 4 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/expr_spec.lua (renamed from tests/mason-core/installer/registry/expr_spec.lua) | 0 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/link_spec.lua (renamed from tests/mason-core/installer/registry/link_spec.lua) | 0 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/util_spec.lua (renamed from tests/mason-core/installer/registry/util_spec.lua) | 0 | ||||
| -rw-r--r-- | tests/mason-core/installer/context_spec.lua | 10 | ||||
| -rw-r--r-- | tests/mason-core/installer/linker_spec.lua | 20 |
22 files changed, 214 insertions, 182 deletions
diff --git a/tests/mason-core/installer/handle_spec.lua b/tests/mason-core/installer/InstallHandle_spec.lua index 780b1cc7..914309b2 100644 --- a/tests/mason-core/installer/handle_spec.lua +++ b/tests/mason-core/installer/InstallHandle_spec.lua @@ -1,9 +1,9 @@ -local InstallHandle = require "mason-core.installer.handle" +local InstallHandle = require "mason-core.installer.InstallHandle" local mock = require "luassert.mock" local spy = require "luassert.spy" local stub = require "luassert.stub" -describe("installer handle", function() +describe("InstallHandle ::", function() local snapshot before_each(function() diff --git a/tests/mason-core/installer/runner_spec.lua b/tests/mason-core/installer/InstallRunner_spec.lua index f4acdcc1..696f7b34 100644 --- a/tests/mason-core/installer/runner_spec.lua +++ b/tests/mason-core/installer/InstallRunner_spec.lua @@ -1,15 +1,17 @@ -local InstallHandle = require "mason-core.installer.handle" -local InstallLocation = require "mason-core.installer.location" -local InstallRunner = require "mason-core.installer.runner" +local InstallHandle = require "mason-core.installer.InstallHandle" +local InstallLocation = require "mason-core.installer.InstallLocation" +local InstallRunner = require "mason-core.installer.InstallRunner" local fs = require "mason-core.fs" local match = require "luassert.match" +local receipt = require "mason-core.receipt" local spy = require "luassert.spy" local stub = require "luassert.stub" local Semaphore = require("mason-core.async.control").Semaphore local a = require "mason-core.async" local registry = require "mason-registry" +local test_helpers = require "mason-test.helpers" -describe("install runner ::", function() +describe("InstallRunner ::", function() local dummy = registry.get_package "dummy" local dummy2 = registry.get_package "dummy2" @@ -17,32 +19,39 @@ describe("install runner ::", function() before_each(function() snapshot = assert.snapshot() + if dummy:is_installed() then + test_helpers.sync_uninstall(dummy) + end + if dummy2:is_installed() then + test_helpers.sync_uninstall(dummy2) + end end) after_each(function() snapshot:revert() end) - before_each(function() - dummy:uninstall() - dummy2:uninstall() - end) - describe("locking ::", function() it("should respect semaphore locks", function() local semaphore = Semaphore:new(1) local location = InstallLocation.global() - local dummy_handle = InstallHandle:new(dummy) - local runner_1 = InstallRunner:new(location, dummy_handle, semaphore) - local runner_2 = InstallRunner:new(location, InstallHandle:new(dummy2), semaphore) + local dummy_handle = InstallHandle:new(dummy, location) + local runner_1 = InstallRunner:new(dummy_handle, semaphore) + local runner_2 = InstallRunner:new(InstallHandle:new(dummy2, location), semaphore) - stub(dummy.spec.source, "install", function() - a.sleep(10000) + stub(dummy.spec.source, "install", function(ctx) + ctx:await(function() end) end) - spy.on(dummy2.spec.source, "install") + spy.on(dummy2.spec.source, "install", function() end) - runner_1:execute {} - runner_2:execute {} + local callback1 = spy.new() + local callback2 = spy.new() + local run = a.scope(function() + runner_1:execute({}, callback1) + runner_2:execute({}, callback2) + end) + + run() assert.wait(function() assert.spy(dummy.spec.source.install).was_called(1) @@ -54,17 +63,22 @@ describe("install runner ::", function() assert.wait(function() assert.spy(dummy2.spec.source.install).was_called(1) end) + + assert.wait(function() + assert.spy(callback1).was_called() + assert.spy(callback2).was_called() + end) end) it("should write lockfile", function() local semaphore = Semaphore:new(1) local location = InstallLocation.global() - local dummy_handle = InstallHandle:new(dummy) - local runner = InstallRunner:new(location, dummy_handle, semaphore) + local dummy_handle = InstallHandle:new(dummy, location) + local runner = InstallRunner:new(dummy_handle, semaphore) spy.on(fs.async, "write_file") - runner:execute {} + test_helpers.sync_runner_execute(runner, {}) assert.wait(function() assert.spy(fs.async.write_file).was_called_with(location:lockfile(dummy.name), vim.fn.getpid()) @@ -74,16 +88,15 @@ describe("install runner ::", function() it("should abort installation if installation lock exists", function() local semaphore = Semaphore:new(1) local location = InstallLocation.global() - local dummy_handle = InstallHandle:new(dummy) - local runner = InstallRunner:new(location, dummy_handle, semaphore) + local dummy_handle = InstallHandle:new(dummy, location) + local runner = InstallRunner:new(dummy_handle, semaphore) stub(fs.async, "file_exists") stub(fs.async, "read_file") fs.async.file_exists.on_call_with(location:lockfile(dummy.name)).returns(true) fs.async.read_file.on_call_with(location:lockfile(dummy.name)).returns "1337" - local callback = spy.new() - runner:execute({}, callback) + local callback = test_helpers.sync_runner_execute(runner, {}) assert.wait(function() assert.spy(callback).was_called() @@ -97,28 +110,30 @@ describe("install runner ::", function() it("should not abort installation if installation lock exists with force=true", function() local semaphore = Semaphore:new(1) local location = InstallLocation.global() - local dummy_handle = InstallHandle:new(dummy) - local runner = InstallRunner:new(location, dummy_handle, semaphore) + local dummy_handle = InstallHandle:new(dummy, location) + local runner = InstallRunner:new(dummy_handle, semaphore) stub(fs.async, "file_exists") stub(fs.async, "read_file") fs.async.file_exists.on_call_with(location:lockfile(dummy.name)).returns(true) fs.async.read_file.on_call_with(location:lockfile(dummy.name)).returns "1337" - local callback = spy.new() - runner:execute({ force = true }, callback) + local callback = test_helpers.sync_runner_execute(runner, { force = true }) assert.wait(function() assert.spy(callback).was_called() - assert.spy(callback).was_called_with(true, nil) + assert.spy(callback).was_called_with(true, match.instanceof(receipt.InstallReceipt)) end) end) it("should release lock after successful installation", function() local semaphore = Semaphore:new(1) local location = InstallLocation.global() - local dummy_handle = InstallHandle:new(dummy) - local runner = InstallRunner:new(location, dummy_handle, semaphore) + local dummy_handle = InstallHandle:new(dummy, location) + local runner = InstallRunner:new(dummy_handle, semaphore) + stub(dummy.spec.source, "install", function() + a.sleep(1000) + end) local callback = spy.new() runner:execute({}, callback) @@ -127,7 +142,7 @@ describe("install runner ::", function() assert.is_true(fs.sync.file_exists(location:lockfile(dummy.name))) end) assert.wait(function() - assert.spy(callback).was_called() + assert.spy(callback).was_called_with(true, match.instanceof(receipt.InstallReceipt)) end) assert.is_false(fs.sync.file_exists(location:lockfile(dummy.name))) end) @@ -135,49 +150,17 @@ describe("install runner ::", function() it("should initialize install location", function() local location = InstallLocation.global() - local runner = InstallRunner:new(location, InstallHandle:new(registry.get_package "dummy"), Semaphore:new(1)) + local runner = InstallRunner:new(InstallHandle:new(dummy, location), Semaphore:new(1)) spy.on(location, "initialize") - runner:execute {} + test_helpers.sync_runner_execute(runner, {}) assert.wait(function() assert.spy(location.initialize).was_called(1) end) end) - describe("receipt ::", function() - it("should write receipt", function() - local location = InstallLocation.global() - local runner = - InstallRunner:new(location, InstallHandle:new(registry.get_package "dummy"), Semaphore:new(1)) - - runner:execute {} - - assert.wait(function() - local receipt_file = location:package "dummy/mason-receipt.json" - assert.is_true(fs.sync.file_exists(receipt_file)) - assert.is_true(match.tbl_containing { - name = "dummy", - schema_version = "1.2", - metrics = match.tbl_containing { - completion_time = match.is_number(), - start_time = match.is_number(), - }, - source = match.same { - id = "pkg:mason/dummy@1.0.0", - type = "registry+v1", - }, - links = match.same { - bin = {}, - opt = {}, - share = {}, - }, - }(vim.json.decode(fs.sync.read_file(receipt_file)))) - end) - end) - end) - it("should emit failures", function() local registry_spy = spy.new() local package_spy = spy.new() @@ -185,115 +168,128 @@ describe("install runner ::", function() dummy:once("install:failed", package_spy) local location = InstallLocation.global() - local handle = InstallHandle:new(registry.get_package "dummy") - local runner = InstallRunner:new(location, handle, Semaphore:new(1)) + local handle = InstallHandle:new(dummy, location) + local runner = InstallRunner:new(handle, Semaphore:new(1)) stub(dummy.spec.source, "install", function() error("I've made a mistake.", 0) end) - local callback = spy.new() - runner:execute({}, callback) + local callback = test_helpers.sync_runner_execute(runner, {}) - assert.wait(function() - assert.spy(registry_spy).was_called(1) - assert.spy(registry_spy).was_called_with(match.is_ref(dummy), match.is_ref(handle), "I've made a mistake.") - assert.spy(package_spy).was_called(1) - assert.spy(package_spy).was_called_with(match.is_ref(handle), "I've made a mistake.") + assert.spy(registry_spy).was_called(1) + assert.spy(registry_spy).was_called_with(match.is_ref(dummy), "I've made a mistake.") + assert.spy(package_spy).was_called(1) + assert.spy(package_spy).was_called_with "I've made a mistake." - assert.spy(callback).was_called(1) - assert.spy(callback).was_called_with(false, "I've made a mistake.") - end, 10) + assert.spy(callback).was_called(1) + assert.spy(callback).was_called_with(false, "I've made a mistake.") end) it("should terminate installation", function() local location = InstallLocation.global() - local handle = InstallHandle:new(registry.get_package "dummy") - local runner = InstallRunner:new(location, handle, Semaphore:new(1)) + local handle = InstallHandle:new(dummy, location) + local runner = InstallRunner:new(handle, Semaphore:new(1)) local capture = spy.new() stub(dummy.spec.source, "install", function() - capture() + capture(1) handle:terminate() a.sleep(0) - capture() + capture(2) end) - local callback = spy.new() - - runner:execute({}, callback) + local callback = test_helpers.sync_runner_execute(runner, {}) - assert.wait(function() - assert.spy(callback).was_called(1) - assert.spy(callback).was_called_with(false, "Installation was aborted.") - - assert.spy(capture).was_called(1) - end) + assert.spy(callback).was_called_with(false, "Installation was aborted.") + assert.spy(capture).was_called(1) + assert.spy(capture).was_called_with(1) end) it("should write debug logs when debug=true", function() local location = InstallLocation.global() - local handle = InstallHandle:new(registry.get_package "dummy") - local runner = InstallRunner:new(location, handle, Semaphore:new(1)) + local handle = InstallHandle:new(dummy, location) + local runner = InstallRunner:new(handle, Semaphore:new(1)) stub(dummy.spec.source, "install", function(ctx) ctx.stdio_sink.stdout "Hello " ctx.stdio_sink.stderr "world!" end) - local callback = spy.new() - runner:execute({ debug = true }, callback) + local callback = test_helpers.sync_runner_execute(runner, { debug = true }) - assert.wait(function() - assert.spy(callback).was_called() - assert.spy(callback).was_called_with(true, nil) - end) + assert.spy(callback).was_called_with(true, match.instanceof(receipt.InstallReceipt)) assert.is_true(fs.sync.file_exists(location:package "dummy/mason-debug.log")) assert.equals("Hello world!", fs.sync.read_file(location:package "dummy/mason-debug.log")) end) it("should not retain installation directory on failure", function() local location = InstallLocation.global() - local handle = InstallHandle:new(registry.get_package "dummy") - local runner = InstallRunner:new(location, handle, Semaphore:new(1)) + local handle = InstallHandle:new(dummy, location) + local runner = InstallRunner:new(handle, Semaphore:new(1)) stub(dummy.spec.source, "install", function(ctx) ctx.stdio_sink.stderr "Something will go terribly wrong.\n" error("This went terribly wrong.", 0) end) - local callback = spy.new() - runner:execute({}, callback) + local callback = test_helpers.sync_runner_execute(runner, {}) - assert.wait(function() - assert.spy(callback).was_called() - assert.spy(callback).was_called_with(false, "This went terribly wrong.") - end) + assert.spy(callback).was_called_with(false, "This went terribly wrong.") assert.is_false(fs.sync.dir_exists(location:staging "dummy")) assert.is_false(fs.sync.dir_exists(location:package "dummy")) end) it("should retain installation directory on failure and debug=true", function() local location = InstallLocation.global() - local handle = InstallHandle:new(registry.get_package "dummy") - local runner = InstallRunner:new(location, handle, Semaphore:new(1)) + local handle = InstallHandle:new(dummy, location) + local runner = InstallRunner:new(handle, Semaphore:new(1)) stub(dummy.spec.source, "install", function(ctx) ctx.stdio_sink.stderr "Something will go terribly wrong.\n" error("This went terribly wrong.", 0) end) - local callback = spy.new() - runner:execute({ debug = true }, callback) + local callback = test_helpers.sync_runner_execute(runner, { debug = true }) - assert.wait(function() - assert.spy(callback).was_called() - assert.spy(callback).was_called_with(false, "This went terribly wrong.") - end) + assert.spy(callback).was_called_with(false, "This went terribly wrong.") assert.is_true(fs.sync.dir_exists(location:staging "dummy")) assert.equals( "Something will go terribly wrong.\nThis went terribly wrong.\n", fs.sync.read_file(location:staging "dummy/mason-debug.log") ) end) + + describe("receipt ::", function() + it("should write receipt", function() + local location = InstallLocation.global() + local runner = InstallRunner:new(InstallHandle:new(dummy, location), Semaphore:new(1)) + + test_helpers.sync_runner_execute(runner, {}) + + local receipt_file = location:package "dummy/mason-receipt.json" + assert.is_true(fs.sync.file_exists(receipt_file)) + assert.is_true(match.tbl_containing { + name = "dummy", + schema_version = "2.0", + install_options = match.same {}, + metrics = match.tbl_containing { + completion_time = match.is_number(), + start_time = match.is_number(), + }, + source = match.same { + id = "pkg:mason/dummy@1.0.0", + type = "registry+v1", + raw = { + id = "pkg:mason/dummy@1.0.0", + }, + }, + links = match.same { + bin = {}, + opt = {}, + share = {}, + }, + }(vim.json.decode(fs.sync.read_file(receipt_file)))) + end) + end) end) diff --git a/tests/mason-core/installer/registry/installer_spec.lua b/tests/mason-core/installer/compiler/compiler_spec.lua index 93c91444..d7e18b25 100644 --- a/tests/mason-core/installer/registry/installer_spec.lua +++ b/tests/mason-core/installer/compiler/compiler_spec.lua @@ -35,7 +35,7 @@ local dummy_compiler = { end, } -describe("registry installer :: parsing", function() +describe("registry compiler :: parsing", function() it("should parse valid package specs", function() compiler.register_compiler("dummy", dummy_compiler) @@ -122,7 +122,7 @@ describe("registry installer :: parsing", function() it("should handle PLATFORM_UNSUPPORTED", function() compiler.register_compiler("dummy", dummy_compiler) - local result = compiler.compile({ + local result = compiler.compile_installer({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -136,7 +136,7 @@ describe("registry installer :: parsing", function() it("should error upon parsing failures", function() compiler.register_compiler("dummy", dummy_compiler) - local result = compiler.compile({ + local result = compiler.compile_installer({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -148,7 +148,7 @@ describe("registry installer :: parsing", function() end) end) -describe("registry installer :: compiling", function() +describe("registry compiler :: compiling", function() local snapshot before_each(function() @@ -166,7 +166,7 @@ describe("registry installer :: compiling", function() ---@type PackageInstallOpts local opts = {} - local result = compiler.compile({ + local result = compiler.compile_installer({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -190,7 +190,7 @@ describe("registry installer :: compiling", function() ---@type PackageInstallOpts local opts = { version = "v2.0.0" } - local result = compiler.compile({ + local result = compiler.compile_installer({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -222,7 +222,7 @@ describe("registry installer :: compiling", function() ---@type PackageInstallOpts local opts = { version = "v13.3.7" } - local result = compiler.compile({ + local result = compiler.compile_installer({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -234,7 +234,7 @@ describe("registry installer :: compiling", function() local ctx = test_helpers.create_context { install_opts = opts } local err = assert.has_error(function() - ctx:execute(installer_fn) + ctx:execute(installer_fn):get_or_throw() end) assert.equals([[Version "v13.3.7" is not available.]], err) @@ -255,7 +255,7 @@ describe("registry installer :: compiling", function() ---@type PackageInstallOpts local opts = {} - local result = compiler.compile({ + local result = compiler.compile_installer({ schema = "registry+v1", source = { id = "pkg:dummy/package-name@v1.2.3", @@ -268,7 +268,7 @@ describe("registry installer :: compiling", function() local ctx = test_helpers.create_context() local err = assert.has_error(function() - ctx:execute(installer_fn) + ctx:execute(installer_fn):get_or_throw() end) assert.equals("This is a failure.", err) end) @@ -292,7 +292,7 @@ describe("registry installer :: compiling", function() ---@type PackageInstallOpts local opts = {} - local result = compiler.compile(spec, opts) + local result = compiler.compile_installer(spec, opts) assert.is_true(result:is_success()) local installer_fn = result:get_or_nil() diff --git a/tests/mason-core/installer/registry/compilers/cargo_spec.lua b/tests/mason-core/installer/compiler/compilers/cargo_spec.lua index 69ac446d..7cdb7ee4 100644 --- a/tests/mason-core/installer/registry/compilers/cargo_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/cargo_spec.lua @@ -14,7 +14,7 @@ local function purl(overrides) return vim.tbl_deep_extend("force", purl, overrides) end -describe("cargo provider :: parsing", function() +describe("cargo compiler :: parsing", function() it("should parse package", function() assert.same( Result.success { @@ -93,7 +93,7 @@ describe("cargo provider :: parsing", function() end) end) -describe("cargo provider :: installing", function() +describe("cargo compiler :: installing", function() local snapshot before_each(function() @@ -129,7 +129,7 @@ describe("cargo provider :: installing", function() end) end) -describe("cargo provider :: versions", function() +describe("cargo compiler :: versions", function() local snapshot before_each(function() diff --git a/tests/mason-core/installer/registry/compilers/composer_spec.lua b/tests/mason-core/installer/compiler/compilers/composer_spec.lua index c184adf5..ae130dc3 100644 --- a/tests/mason-core/installer/registry/compilers/composer_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/composer_spec.lua @@ -13,7 +13,7 @@ local function purl(overrides) return vim.tbl_deep_extend("force", purl, overrides) end -describe("composer provider :: parsing", function() +describe("composer compiler :: parsing", function() it("should parse package", function() assert.same( Result.success { @@ -25,7 +25,7 @@ describe("composer provider :: parsing", function() end) end) -describe("composer provider :: installing", function() +describe("composer compiler :: installing", function() local snapshot before_each(function() diff --git a/tests/mason-core/installer/registry/compilers/gem_spec.lua b/tests/mason-core/installer/compiler/compilers/gem_spec.lua index b38bba33..9d99da00 100644 --- a/tests/mason-core/installer/registry/compilers/gem_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/gem_spec.lua @@ -13,7 +13,7 @@ local function purl(overrides) return vim.tbl_deep_extend("force", purl, overrides) end -describe("gem provider :: parsing", function() +describe("gem compiler :: parsing", function() it("should parse package", function() assert.same( Result.success { @@ -30,7 +30,7 @@ describe("gem provider :: parsing", function() end) end) -describe("gem provider :: installing", function() +describe("gem compiler :: installing", function() local snapshot before_each(function() diff --git a/tests/mason-core/installer/registry/compilers/generic/build_spec.lua b/tests/mason-core/installer/compiler/compilers/generic/build_spec.lua index 8b8baeab..63a400d1 100644 --- a/tests/mason-core/installer/registry/compilers/generic/build_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/generic/build_spec.lua @@ -13,7 +13,7 @@ local function purl(overrides) return vim.tbl_deep_extend("force", purl, overrides) end -describe("generic provider :: build :: parsing", function() +describe("generic compiler :: build :: parsing", function() it("should parse single build target", function() assert.same( Result.success { @@ -118,7 +118,7 @@ describe("generic provider :: build :: parsing", function() end) end) -describe("generic provider :: build :: installing", function() +describe("generic compiler :: build :: installing", function() local snapshot before_each(function() diff --git a/tests/mason-core/installer/registry/compilers/generic/download_spec.lua b/tests/mason-core/installer/compiler/compilers/generic/download_spec.lua index 4046d898..afe25086 100644 --- a/tests/mason-core/installer/registry/compilers/generic/download_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/generic/download_spec.lua @@ -1,7 +1,7 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" -local match = require "luassert.match" local generic = require "mason-core.installer.compiler.compilers.generic" +local match = require "luassert.match" local stub = require "luassert.stub" local test_helpers = require "mason-test.helpers" @@ -14,7 +14,7 @@ local function purl(overrides) return vim.tbl_deep_extend("force", purl, overrides) end -describe("generic provider :: download :: parsing", function() +describe("generic compiler :: download :: parsing", function() it("should parse single download target", function() assert.same( Result.success { @@ -98,7 +98,7 @@ describe("generic provider :: download :: parsing", function() end) end) -describe("generic provider :: download :: installing", function() +describe("generic compiler :: download :: installing", function() local snapshot before_each(function() diff --git a/tests/mason-core/installer/registry/compilers/github/build_spec.lua b/tests/mason-core/installer/compiler/compilers/github/build_spec.lua index 82271fee..8315c272 100644 --- a/tests/mason-core/installer/registry/compilers/github/build_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/github/build_spec.lua @@ -1,6 +1,8 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" local github = require "mason-core.installer.compiler.compilers.github" +local stub = require "luassert.stub" +local test_helpers = require "mason-test.helpers" ---@param overrides Purl local function purl(overrides) @@ -11,7 +13,7 @@ local function purl(overrides) return vim.tbl_deep_extend("force", purl, overrides) end -describe("github provider :: build :: parsing", function() +describe("github compiler :: build :: parsing", function() it("should parse build source", function() assert.same( Result.success { @@ -56,3 +58,47 @@ describe("github provider :: build :: parsing", function() ) end) end) + +describe("github compiler :: build :: installing", function() + local snapshot + + before_each(function() + snapshot = assert.snapshot() + end) + + after_each(function() + snapshot:revert() + end) + + it("should install github build sources", function() + local ctx = test_helpers.create_context() + local std = require "mason-core.installer.managers.std" + local common = require "mason-core.installer.managers.common" + stub(std, "clone", mockx.returns(Result.success())) + stub(common, "run_build_instruction", mockx.returns(Result.success())) + + local result = ctx:execute(function() + return github.install(ctx, { + repo = "namespace/name", + rev = "2023-03-09", + build = { + run = [[npm install && npm run compile]], + env = { + SOME_VALUE = "here", + }, + }, + }, purl()) + end) + + assert.is_true(result:is_success()) + assert.spy(std.clone).was_called(1) + assert.spy(std.clone).was_called_with("namespace/name", { rev = "2023-03-09" }) + assert.spy(common.run_build_instruction).was_called(1) + assert.spy(common.run_build_instruction).was_called_with { + run = [[npm install && npm run compile]], + env = { + SOME_VALUE = "here", + }, + } + end) +end) diff --git a/tests/mason-core/installer/registry/compilers/github/release_spec.lua b/tests/mason-core/installer/compiler/compilers/github/release_spec.lua index 7ea9f42e..a59a6b79 100644 --- a/tests/mason-core/installer/registry/compilers/github/release_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/github/release_spec.lua @@ -16,7 +16,7 @@ local function purl(overrides) return vim.tbl_deep_extend("force", purl, overrides) end -describe("github provider :: release :: parsing", function() +describe("github compiler :: release :: parsing", function() it("should parse release asset source", function() assert.same( Result.success { @@ -211,6 +211,7 @@ describe("github provider :: release :: parsing", function() version_overrides = { { constraint = "semver:<=1.0.0", + id = "pkg:github/owner/repo@1.0.0", asset = { { target = "darwin_x64", @@ -225,7 +226,7 @@ describe("github provider :: release :: parsing", function() assert.is_true(result:is_success()) assert.same({ - id = "pkg:github/owner/repo@1.2.3", + id = "pkg:github/owner/repo@1.0.0", asset = { target = "darwin_x64", file = "old-asset.tar.gz", @@ -236,17 +237,6 @@ describe("github provider :: release :: parsing", function() out_file = "old-asset.tar.gz", }, }, - version_overrides = { - { - constraint = "semver:<=1.0.0", - asset = { - { - target = "darwin_x64", - file = "old-asset.tar.gz", - }, - }, - }, - }, repo = "owner/repo", }, parsed.source) end) @@ -279,7 +269,7 @@ describe("github provider :: release :: parsing", function() end) end) -describe("github provider :: release :: installing", function() +describe("github compiler :: release :: installing", function() local snapshot before_each(function() diff --git a/tests/mason-core/installer/registry/compilers/golang_spec.lua b/tests/mason-core/installer/compiler/compilers/golang_spec.lua index 8a3abc8a..fa474870 100644 --- a/tests/mason-core/installer/registry/compilers/golang_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/golang_spec.lua @@ -13,7 +13,7 @@ local function purl(overrides) return vim.tbl_deep_extend("force", purl, overrides) end -describe("golang provider :: parsing", function() +describe("golang compiler :: parsing", function() it("should parse package", function() assert.same( Result.success { @@ -26,7 +26,7 @@ describe("golang provider :: parsing", function() end) end) -describe("golang provider :: installing", function() +describe("golang compiler :: installing", function() local snapshot before_each(function() diff --git a/tests/mason-core/installer/registry/compilers/luarocks_spec.lua b/tests/mason-core/installer/compiler/compilers/luarocks_spec.lua index b8642fcf..25bcbf94 100644 --- a/tests/mason-core/installer/registry/compilers/luarocks_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/luarocks_spec.lua @@ -14,7 +14,7 @@ local function purl(overrides) return vim.tbl_deep_extend("force", purl, overrides) end -describe("luarocks provider :: parsing", function() +describe("luarocks compiler :: parsing", function() it("should parse package", function() assert.same( Result.success { @@ -52,7 +52,7 @@ describe("luarocks provider :: parsing", function() end) end) -describe("luarocks provider :: installing", function() +describe("luarocks compiler :: installing", function() local snapshot before_each(function() diff --git a/tests/mason-core/installer/registry/compilers/npm_spec.lua b/tests/mason-core/installer/compiler/compilers/npm_spec.lua index 680df5bc..94d67801 100644 --- a/tests/mason-core/installer/registry/compilers/npm_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/npm_spec.lua @@ -13,7 +13,7 @@ local function purl(overrides) return vim.tbl_deep_extend("force", purl, overrides) end -describe("npm provider :: parsing", function() +describe("npm compiler :: parsing", function() it("should parse package", function() assert.same( Result.success { @@ -26,7 +26,7 @@ describe("npm provider :: parsing", function() end) end) -describe("npm provider :: installing", function() +describe("npm compiler :: installing", function() local snapshot before_each(function() diff --git a/tests/mason-core/installer/registry/compilers/nuget_spec.lua b/tests/mason-core/installer/compiler/compilers/nuget_spec.lua index f514e666..973c0932 100644 --- a/tests/mason-core/installer/registry/compilers/nuget_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/nuget_spec.lua @@ -13,7 +13,7 @@ local function purl(overrides) return vim.tbl_deep_extend("force", purl, overrides) end -describe("nuget provider :: parsing", function() +describe("nuget compiler :: parsing", function() it("should parse package", function() assert.same( Result.success { @@ -25,7 +25,7 @@ describe("nuget provider :: parsing", function() end) end) -describe("nuget provider :: installing", function() +describe("nuget compiler :: installing", function() local snapshot before_each(function() diff --git a/tests/mason-core/installer/registry/compilers/opam_spec.lua b/tests/mason-core/installer/compiler/compilers/opam_spec.lua index c2c7638e..7b041a9e 100644 --- a/tests/mason-core/installer/registry/compilers/opam_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/opam_spec.lua @@ -13,7 +13,7 @@ local function purl(overrides) return vim.tbl_deep_extend("force", purl, overrides) end -describe("opam provider :: parsing", function() +describe("opam compiler :: parsing", function() it("should parse package", function() assert.same( Result.success { @@ -25,7 +25,7 @@ describe("opam provider :: parsing", function() end) end) -describe("opam provider :: installing", function() +describe("opam compiler :: installing", function() local snapshot before_each(function() diff --git a/tests/mason-core/installer/registry/compilers/openvsx_spec.lua b/tests/mason-core/installer/compiler/compilers/openvsx_spec.lua index d3868a69..d3868a69 100644 --- a/tests/mason-core/installer/registry/compilers/openvsx_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/openvsx_spec.lua diff --git a/tests/mason-core/installer/registry/compilers/pypi_spec.lua b/tests/mason-core/installer/compiler/compilers/pypi_spec.lua index 61742b4e..7e5b8e1d 100644 --- a/tests/mason-core/installer/registry/compilers/pypi_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/pypi_spec.lua @@ -14,7 +14,7 @@ local function purl(overrides) return vim.tbl_deep_extend("force", purl, overrides) end -describe("pypi provider :: parsing", function() +describe("pypi compiler :: parsing", function() it("should parse package", function() settings.set { pip = { @@ -43,7 +43,7 @@ describe("pypi provider :: parsing", function() end) end) -describe("pypi provider :: installing", function() +describe("pypi compiler :: installing", function() local snapshot before_each(function() diff --git a/tests/mason-core/installer/registry/expr_spec.lua b/tests/mason-core/installer/compiler/expr_spec.lua index 944a5983..944a5983 100644 --- a/tests/mason-core/installer/registry/expr_spec.lua +++ b/tests/mason-core/installer/compiler/expr_spec.lua diff --git a/tests/mason-core/installer/registry/link_spec.lua b/tests/mason-core/installer/compiler/link_spec.lua index 62777bc9..62777bc9 100644 --- a/tests/mason-core/installer/registry/link_spec.lua +++ b/tests/mason-core/installer/compiler/link_spec.lua diff --git a/tests/mason-core/installer/registry/util_spec.lua b/tests/mason-core/installer/compiler/util_spec.lua index be687f36..be687f36 100644 --- a/tests/mason-core/installer/registry/util_spec.lua +++ b/tests/mason-core/installer/compiler/util_spec.lua diff --git a/tests/mason-core/installer/context_spec.lua b/tests/mason-core/installer/context_spec.lua index 9c1805cb..d753c05f 100644 --- a/tests/mason-core/installer/context_spec.lua +++ b/tests/mason-core/installer/context_spec.lua @@ -104,7 +104,7 @@ cmd.exe /C echo %GREETING% %*]] assert.spy(ctx.write_shell_exec_wrapper).was_called_with( match.is_ref(ctx), "my-wrapper-script", - ("node %q"):format(path.concat { dummy:get_install_path(), js_rel_path }) + ("node %q"):format(path.concat { ctx:get_install_path(), js_rel_path }) ) end) @@ -122,7 +122,7 @@ cmd.exe /C echo %GREETING% %*]] assert.spy(ctx.write_shell_exec_wrapper).was_called_with( match.is_ref(ctx), "my-wrapper-script", - ("ruby %q"):format(path.concat { dummy:get_install_path(), js_rel_path }) + ("ruby %q"):format(path.concat { ctx:get_install_path(), js_rel_path }) ) end) @@ -157,7 +157,7 @@ cmd.exe /C echo %GREETING% %*]] assert.spy(ctx.write_shell_exec_wrapper).was_called_with( match.is_ref(ctx), "my-wrapper-script", - ("%q -m my-module"):format(path.concat { pypi.venv_path(dummy:get_install_path()), "python" }) + ("%q -m my-module"):format(path.concat { pypi.venv_path(ctx:get_install_path()), "python" }) ) end) @@ -196,7 +196,7 @@ cmd.exe /C echo %GREETING% %*]] .was_called_with( match.is_ref(ctx), "my-wrapper-script", - ("%q"):format(path.concat { dummy:get_install_path(), exec_rel_path }) + ("%q"):format(path.concat { ctx:get_install_path(), exec_rel_path }) ) end) @@ -229,7 +229,7 @@ cmd.exe /C echo %GREETING% %*]] assert.spy(ctx.write_shell_exec_wrapper).was_called_with( match.is_ref(ctx), "my-wrapper-script", - ("php %q"):format(path.concat { dummy:get_install_path(), php_rel_path }) + ("php %q"):format(path.concat { ctx:get_install_path(), php_rel_path }) ) end) diff --git a/tests/mason-core/installer/linker_spec.lua b/tests/mason-core/installer/linker_spec.lua index 9d3afeac..2177f6a3 100644 --- a/tests/mason-core/installer/linker_spec.lua +++ b/tests/mason-core/installer/linker_spec.lua @@ -50,9 +50,9 @@ describe("linker", function() fs.async.file_exists.on_call_with(ctx.location:bin "my-executable").returns(false) fs.async.file_exists.on_call_with(ctx.location:bin "another-executable").returns(false) fs.async.file_exists - .on_call_with(path.concat { dummy:get_install_path(), "nested", "path", "my-executable" }) + .on_call_with(path.concat { ctx:get_install_path(), "nested", "path", "my-executable" }) .returns(true) - fs.async.file_exists.on_call_with(path.concat { dummy:get_install_path(), "another-executable" }).returns(true) + fs.async.file_exists.on_call_with(path.concat { ctx:get_install_path(), "another-executable" }).returns(true) ctx:link_bin("my-executable", path.concat { "nested", "path", "my-executable" }) ctx:link_bin("another-executable", "another-executable") @@ -86,9 +86,9 @@ describe("linker", function() fs.async.file_exists.on_call_with(ctx.location:bin "my-executable").returns(false) fs.async.file_exists.on_call_with(ctx.location:bin "another-executable").returns(false) fs.async.file_exists - .on_call_with(path.concat { dummy:get_install_path(), "nested", "path", "my-executable" }) + .on_call_with(path.concat { ctx:get_install_path(), "nested", "path", "my-executable" }) .returns(true) - fs.async.file_exists.on_call_with(path.concat { dummy:get_install_path(), "another-executable" }).returns(true) + fs.async.file_exists.on_call_with(path.concat { ctx:get_install_path(), "another-executable" }).returns(true) ctx:link_bin("my-executable", path.concat { "nested", "path", "my-executable" }) ctx:link_bin("another-executable", "another-executable") @@ -126,9 +126,9 @@ describe("linker", function() fs.async.dir_exists.on_call_with(ctx.location:share "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 { ctx: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" }) + .on_call_with(path.concat { ctx:get_install_path(), "nested", "path", "to", "share-file" }) .returns(true) ctx.links.share["nested/path/share-file"] = path.concat { "nested", "path", "to", "share-file" } @@ -171,9 +171,9 @@ describe("linker", function() fs.async.dir_exists.on_call_with(ctx.location:share "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 { ctx: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" }) + .on_call_with(path.concat { ctx:get_install_path(), "nested", "path", "to", "share-file" }) .returns(true) ctx.links.share["nested/path/share-file"] = path.concat { "nested", "path", "to", "share-file" } @@ -186,9 +186,9 @@ describe("linker", function() assert.spy(fs.async.copy_file).was_called(2) assert .spy(fs.async.copy_file) - .was_called_with(path.concat { dummy:get_install_path(), "share-file" }, ctx.location:share "share-file", { excl = true }) + .was_called_with(path.concat { ctx:get_install_path(), "share-file" }, ctx.location:share "share-file", { excl = true }) assert.spy(fs.async.copy_file).was_called_with( - path.concat { dummy:get_install_path(), "nested", "path", "to", "share-file" }, + path.concat { ctx:get_install_path(), "nested", "path", "to", "share-file" }, ctx.location:share "nested/path/share-file", { excl = true } ) |
