diff options
| author | William Boman <william@redwill.se> | 2023-09-11 00:05:44 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2025-02-16 09:32:29 +0100 |
| commit | 2275067747a118d6002f421cb54f28affbc0ef98 (patch) | |
| tree | 79bc1c2580ba96cc1b19e71f2b31f7c4c8ab490c /tests | |
| parent | chore(main): release 1.11.0 (#1658) (diff) | |
| download | mason-2275067747a118d6002f421cb54f28affbc0ef98.tar mason-2275067747a118d6002f421cb54f28affbc0ef98.tar.gz mason-2275067747a118d6002f421cb54f28affbc0ef98.tar.bz2 mason-2275067747a118d6002f421cb54f28affbc0ef98.tar.lz mason-2275067747a118d6002f421cb54f28affbc0ef98.tar.xz mason-2275067747a118d6002f421cb54f28affbc0ef98.tar.zst mason-2275067747a118d6002f421cb54f28affbc0ef98.zip | |
refactor!: remove old managers (#1497)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/mason-core/installer/context_spec.lua | 8 | ||||
| -rw-r--r-- | tests/mason-core/installer/managers/powershell_spec.lua (renamed from tests/mason-core/managers/powershell_spec.lua) | 4 | ||||
| -rw-r--r-- | tests/mason-core/managers/cargo_spec.lua | 350 | ||||
| -rw-r--r-- | tests/mason-core/managers/composer_spec.lua | 173 | ||||
| -rw-r--r-- | tests/mason-core/managers/dotnet_spec.lua | 38 | ||||
| -rw-r--r-- | tests/mason-core/managers/gem_spec.lua | 190 | ||||
| -rw-r--r-- | tests/mason-core/managers/git_spec.lua | 181 | ||||
| -rw-r--r-- | tests/mason-core/managers/github_client_spec.lua | 23 | ||||
| -rw-r--r-- | tests/mason-core/managers/github_spec.lua | 103 | ||||
| -rw-r--r-- | tests/mason-core/managers/go_spec.lua | 171 | ||||
| -rw-r--r-- | tests/mason-core/managers/luarocks_spec.lua | 139 | ||||
| -rw-r--r-- | tests/mason-core/managers/npm_spec.lua | 206 | ||||
| -rw-r--r-- | tests/mason-core/managers/opam_spec.lua | 57 | ||||
| -rw-r--r-- | tests/mason-core/managers/pip3_spec.lua | 284 |
14 files changed, 5 insertions, 1922 deletions
diff --git a/tests/mason-core/installer/context_spec.lua b/tests/mason-core/installer/context_spec.lua index af99089f..646f7e30 100644 --- a/tests/mason-core/installer/context_spec.lua +++ b/tests/mason-core/installer/context_spec.lua @@ -1,8 +1,7 @@ local match = require "luassert.match" local path = require "mason-core.path" -local pip3 = require "mason-core.managers.pip3" +local pypi = require "mason-core.installer.managers.pypi" local registry = require "mason-registry" -local std = require "mason-core.managers.std" local stub = require "luassert.stub" describe("installer", function() @@ -21,9 +20,9 @@ describe("installer", function() stub(ctx.fs, "write_file") stub(ctx.fs, "file_exists") stub(ctx.fs, "dir_exists") + stub(ctx.fs, "chmod_exec") ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), "my-executable").returns(false) ctx.fs.dir_exists.on_call_with(match.is_ref(ctx.fs), "my-executable").returns(false) - stub(std, "chmod") ctx:write_shell_exec_wrapper("my-executable", "bash -c 'echo $GREETING'", { GREETING = "Hello World!", @@ -52,7 +51,6 @@ exec bash -c 'echo $GREETING' "$@"]] stub(ctx.fs, "dir_exists") ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), "my-executable").returns(false) ctx.fs.dir_exists.on_call_with(match.is_ref(ctx.fs), "my-executable").returns(false) - stub(std, "chmod") ctx:write_shell_exec_wrapper("my-executable", "cmd.exe /C echo %GREETING%", { GREETING = "Hello World!", @@ -156,7 +154,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 { pip3.venv_path(dummy:get_install_path()), "python" }) + ("%q -m my-module"):format(path.concat { pypi.venv_path(dummy:get_install_path()), "python" }) ) end) diff --git a/tests/mason-core/managers/powershell_spec.lua b/tests/mason-core/installer/managers/powershell_spec.lua index 56ec243e..86bbe1f9 100644 --- a/tests/mason-core/managers/powershell_spec.lua +++ b/tests/mason-core/installer/managers/powershell_spec.lua @@ -6,8 +6,8 @@ local stub = require "luassert.stub" describe("powershell manager", function() local function powershell() - package.loaded["mason-core.managers.powershell"] = nil - return require "mason-core.managers.powershell" + package.loaded["mason-core.installer.managers.powershell"] = nil + return require "mason-core.installer.managers.powershell" end it("should use pwsh if available", function() diff --git a/tests/mason-core/managers/cargo_spec.lua b/tests/mason-core/managers/cargo_spec.lua deleted file mode 100644 index 92d04588..00000000 --- a/tests/mason-core/managers/cargo_spec.lua +++ /dev/null @@ -1,350 +0,0 @@ -local Result = require "mason-core.result" -local _ = require "mason-core.functional" -local cargo = require "mason-core.managers.cargo" -local cargo_client = require "mason-core.managers.cargo.client" -local github = require "mason-core.managers.github" -local github_client = require "mason-core.managers.github.client" -local installer = require "mason-core.installer" -local match = require "luassert.match" -local mock = require "luassert.mock" -local path = require "mason-core.path" -local spawn = require "mason-core.spawn" -local spy = require "luassert.spy" -local stub = require "luassert.stub" - -describe("cargo manager", function() - it( - "should call cargo install", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, cargo.crate "my-crate") - assert.spy(ctx.spawn.cargo).was_called(1) - assert.spy(ctx.spawn.cargo).was_called_with { - "install", - "--root", - ".", - "--locked", - { "--version", "42.13.37" }, - vim.NIL, -- --git - vim.NIL, -- --features - "my-crate", - } - end) - ) - - it( - "should call cargo install with git source", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, cargo.crate("my-crate", { git = { url = "https://my-crate.git" } })) - assert.spy(ctx.spawn.cargo).was_called(1) - assert.spy(ctx.spawn.cargo).was_called_with { - "install", - "--root", - ".", - "--locked", - vim.NIL, -- version - { "--git", "https://my-crate.git" }, - vim.NIL, -- --features - "my-crate", - } - end) - ) - - it( - "should call cargo install with git source and a specific crate", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, cargo.crate("crate-name", { git = { url = "https://my-crate.git" } })) - assert.spy(ctx.spawn.cargo).was_called(1) - assert.spy(ctx.spawn.cargo).was_called_with { - "install", - "--root", - ".", - "--locked", - vim.NIL, -- version - { "--git", "https://my-crate.git" }, - vim.NIL, -- --features - "crate-name", - } - end) - ) - - it( - "should respect options", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, cargo.crate("my-crate", { features = "lsp" })) - assert.spy(ctx.spawn.cargo).was_called(1) - assert.spy(ctx.spawn.cargo).was_called_with { - "install", - "--root", - ".", - "--locked", - { "--version", "42.13.37" }, - vim.NIL, -- --git - { "--features", "lsp" }, - "my-crate", - } - end) - ) - - it( - "should target tagged git crates", - async_test(function() - local handle = InstallHandleGenerator "dummy" - stub(github, "tag") - github.tag.returns { tag = "v2.1.1", with_receipt = mockx.just_runs } - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context( - ctx, - cargo.crate("my-crate", { - git = { - url = "https://github.com/crate/my-crate", - tag = true, - }, - features = "lsp", - }) - ) - assert.spy(ctx.spawn.cargo).was_called_with { - "install", - "--root", - ".", - "--locked", - { "--tag", "v2.1.1" }, - { "--git", "https://github.com/crate/my-crate" }, -- --git - { "--features", "lsp" }, - "my-crate", - } - end) - ) - - it( - "should provide receipt information", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, cargo.crate "main-package") - assert.same({ - type = "cargo", - package = "main-package", - }, ctx.receipt.primary_source) - end) - ) -end) - -describe("cargo version check", function() - it("parses cargo installed packages output", function() - assert.same( - { - ["bat"] = { name = "bat", version = "0.18.3" }, - ["exa"] = { name = "exa", version = "0.10.1" }, - ["git-select-branch"] = { name = "git-select-branch", version = "0.1.1" }, - ["hello_world"] = { name = "hello_world", version = "0.0.1" }, - ["rust-analyzer"] = { - name = "rust-analyzer", - version = "187bee0b", - github_ref = { owner = "rust-lang", repo = "rust-analyzer", ref = "187bee0b" }, - }, - ["move-analyzer"] = { - name = "move-analyzer", - version = "3cef7fa8", - github_ref = { owner = "move-language", repo = "move", ref = "3cef7fa8" }, - }, - ["stylua"] = { name = "stylua", version = "0.11.2" }, - ["zoxide"] = { name = "zoxide", version = "0.5.0" }, - }, - cargo.parse_installed_crates(_.dedent [[ - bat v0.18.3: - bat - exa v0.10.1: - exa - git-select-branch v0.1.1: - git-select-branch - hello_world v0.0.1 (/private/var/folders/ky/s6yyhm_d24d0jsrql4t8k4p40000gn/T/tmp.LGbguATJHj): - hello_world - move-analyzer v1.0.0 (https://github.com/move-language/move#3cef7fa8): - move-analyzer - rust-analyzer v0.0.0 (https://github.com/rust-lang/rust-analyzer?tag=2022-09-19#187bee0b): - rust-analyzer - stylua v0.11.2: - stylua - zoxide v0.5.0: - zoxide - ]]) - ) - end) - - it( - "should return current version", - async_test(function() - stub(spawn, "cargo") - spawn.cargo.returns(Result.success { - stdout = _.dedent [[ - flux-lsp v0.8.8 (https://github.com/influxdata/flux-lsp#4e452f07): - flux-lsp - ]], - }) - - local result = cargo.get_installed_primary_package_version( - mock.new { - primary_source = mock.new { - type = "cargo", - package = "https://github.com/influxdata/flux-lsp", - }, - }, - path.package_prefix "dummy" - ) - - assert.spy(spawn.cargo).was_called(1) - assert.spy(spawn.cargo).was_called_with(match.tbl_containing { - "install", - "--list", - "--root", - ".", - cwd = path.package_prefix "dummy", - }) - assert.is_true(result:is_success()) - assert.equals("4e452f07", result:get_or_nil()) - end) - ) - - it( - "should return outdated primary package", - async_test(function() - stub(spawn, "cargo") - spawn.cargo.returns(Result.success { - stdout = _.dedent [[ - lelwel v0.4.0: - lelwel-ls - ]], - }) - stub(cargo_client, "fetch_crate") - cargo_client.fetch_crate.returns(Result.success { - crate = { - id = "lelwel", - max_stable_version = "0.4.2", - max_version = "0.4.2", - newest_version = "0.4.2", - }, - }) - - local result = cargo.check_outdated_primary_package( - mock.new { - primary_source = mock.new { - type = "cargo", - package = "lelwel", - }, - }, - path.package_prefix "dummy" - ) - - assert.spy(spawn.cargo).was_called(1) - assert.spy(spawn.cargo).was_called_with(match.tbl_containing { - "install", - "--list", - "--root", - ".", - cwd = path.package_prefix "dummy", - }) - assert.is_true(result:is_success()) - assert.is_true(match.tbl_containing { - current_version = "0.4.0", - latest_version = "0.4.2", - name = "lelwel", - }(result:get_or_nil())) - end) - ) - - it( - "should recognize up-to-date crates", - async_test(function() - stub(spawn, "cargo") - spawn.cargo.returns(Result.success { - stdout = _.dedent [[ - lelwel v0.4.0: - lelwel-ls - ]], - }) - stub(cargo_client, "fetch_crate") - cargo_client.fetch_crate.returns(Result.success { - crate = { - id = "lelwel", - max_stable_version = "0.4.0", - max_version = "0.4.0", - newest_version = "0.4.0", - }, - }) - - local result = cargo.check_outdated_primary_package( - mock.new { - primary_source = mock.new { - type = "cargo", - package = "lelwel", - }, - }, - path.package_prefix "dummy" - ) - - assert.is_true(result:is_failure()) - assert.equals("Primary package is not outdated.", result:err_or_nil()) - end) - ) - - it( - "should return outdated primary package from git source", - async_test(function() - stub(spawn, "cargo") - spawn.cargo.returns(Result.success { - stdout = _.dedent [[ - move-analyzer v1.0.0 (https://github.com/move-language/move#3cef7fa8): - move-analyzer - ]], - }) - - stub(github_client, "fetch_commits") - github_client.fetch_commits - .on_call_with("move-language/move", { page = 1, per_page = 1 }) - .returns(Result.success { - { - sha = "b243f1fb", - }, - }) - - local result = cargo.check_outdated_primary_package( - mock.new { - primary_source = mock.new { - type = "cargo", - package = "move-analyzer", - }, - }, - path.package_prefix "dummy" - ) - - assert.spy(spawn.cargo).was_called(1) - assert.spy(spawn.cargo).was_called_with(match.tbl_containing { - "install", - "--list", - "--root", - ".", - cwd = path.package_prefix "dummy", - }) - assert.is_true(result:is_success()) - assert.is_true(match.tbl_containing { - current_version = "3cef7fa8", - latest_version = "b243f1fb", - name = "move-analyzer", - }(result:get_or_nil())) - end) - ) -end) diff --git a/tests/mason-core/managers/composer_spec.lua b/tests/mason-core/managers/composer_spec.lua deleted file mode 100644 index 5e5b97ba..00000000 --- a/tests/mason-core/managers/composer_spec.lua +++ /dev/null @@ -1,173 +0,0 @@ -local Result = require "mason-core.result" -local composer = require "mason-core.managers.composer" -local installer = require "mason-core.installer" -local mock = require "luassert.mock" -local path = require "mason-core.path" -local spawn = require "mason-core.spawn" -local spy = require "luassert.spy" -local stub = require "luassert.stub" - -describe("composer manager", function() - it( - "should call composer require", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - ctx.fs.file_exists = spy.new(mockx.returns(false)) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context( - ctx, - composer.packages { "main-package", "supporting-package", "supporting-package2" } - ) - assert.spy(ctx.spawn.composer).was_called(2) - assert.spy(ctx.spawn.composer).was_called_with { - "init", - "--no-interaction", - "--stability=stable", - } - assert.spy(ctx.spawn.composer).was_called_with { - "require", - { - "main-package:42.13.37", - "supporting-package", - "supporting-package2", - }, - } - end) - ) - - it( - "should provide receipt information", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context( - ctx, - composer.packages { "main-package", "supporting-package", "supporting-package2" } - ) - assert.same({ - type = "composer", - package = "main-package", - }, ctx.receipt.primary_source) - assert.same({ - { - type = "composer", - package = "supporting-package", - }, - { - type = "composer", - package = "supporting-package2", - }, - }, ctx.receipt.secondary_sources) - end) - ) -end) - -describe("composer version check", function() - it( - "should return current version", - async_test(function() - stub(spawn, "composer") - spawn.composer.returns(Result.success { - stdout = [[ - { - "name": "vimeo/psalm", - "versions": [ - "4.0.0" - ] - } - ]], - }) - - local result = composer.get_installed_primary_package_version( - mock.new { - primary_source = mock.new { - type = "composer", - package = "vimeo/psalm", - }, - }, - path.package_prefix "dummy" - ) - - assert.spy(spawn.composer).was_called(1) - assert.spy(spawn.composer).was_called_with { - "info", - "--format=json", - "vimeo/psalm", - cwd = path.package_prefix "dummy", - } - assert.is_true(result:is_success()) - assert.equals("4.0.0", result:get_or_nil()) - end) - ) - - it( - "should return outdated primary package", - async_test(function() - stub(spawn, "composer") - spawn.composer.returns(Result.success { - stdout = [[ - { - "installed": [ - { - "name": "vimeo/psalm", - "version": "4.0.0", - "latest": "4.22.0", - "latest-status": "semver-safe-update", - "description": "A static analysis tool for finding errors in PHP applications" - } - ] - } - ]], - }) - - local result = composer.check_outdated_primary_package( - mock.new { - primary_source = mock.new { - type = "composer", - package = "vimeo/psalm", - }, - }, - path.package_prefix "dummy" - ) - - assert.spy(spawn.composer).was_called(1) - assert.spy(spawn.composer).was_called_with { - "outdated", - "--no-interaction", - "--format=json", - cwd = path.package_prefix "dummy", - } - assert.is_true(result:is_success()) - assert.same({ - name = "vimeo/psalm", - current_version = "4.0.0", - latest_version = "4.22.0", - }, result:get_or_nil()) - end) - ) - - it( - "should return failure if primary package is not outdated", - async_test(function() - stub(spawn, "composer") - spawn.composer.returns(Result.success { - stdout = [[{"installed": []}]], - }) - - local result = composer.check_outdated_primary_package( - mock.new { - primary_source = mock.new { - type = "composer", - package = "vimeo/psalm", - }, - }, - path.package_prefix "dummy" - ) - - assert.is_true(result:is_failure()) - assert.equals("Primary package is not outdated.", result:err_or_nil()) - end) - ) -end) diff --git a/tests/mason-core/managers/dotnet_spec.lua b/tests/mason-core/managers/dotnet_spec.lua deleted file mode 100644 index b6e0f8c0..00000000 --- a/tests/mason-core/managers/dotnet_spec.lua +++ /dev/null @@ -1,38 +0,0 @@ -local dotnet = require "mason-core.managers.dotnet" -local installer = require "mason-core.installer" - -describe("dotnet manager", function() - it( - "should call dotnet tool update", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, dotnet.package "main-package") - assert.spy(ctx.spawn.dotnet).was_called(1) - assert.spy(ctx.spawn.dotnet).was_called_with { - "tool", - "update", - "--ignore-failed-sources", - "--tool-path", - ".", - { "--version", "42.13.37" }, - "main-package", - } - end) - ) - - it( - "should provide receipt information", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, dotnet.package "main-package") - assert.same({ - type = "dotnet", - package = "main-package", - }, ctx.receipt.primary_source) - end) - ) -end) diff --git a/tests/mason-core/managers/gem_spec.lua b/tests/mason-core/managers/gem_spec.lua deleted file mode 100644 index a99bf5e9..00000000 --- a/tests/mason-core/managers/gem_spec.lua +++ /dev/null @@ -1,190 +0,0 @@ -local Result = require "mason-core.result" -local _ = require "mason-core.functional" -local api = require "mason-registry.api" -local gem = require "mason-core.managers.gem" -local installer = require "mason-core.installer" -local match = require "luassert.match" -local mock = require "luassert.mock" -local spawn = require "mason-core.spawn" -local spy = require "luassert.spy" -local stub = require "luassert.stub" - -describe("gem manager", function() - it( - "should call gem install", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, gem.packages { "main-package", "supporting-package", "supporting-package2" }) - assert.spy(ctx.spawn.gem).was_called(1) - assert.spy(ctx.spawn.gem).was_called_with(match.tbl_containing { - "install", - "--no-user-install", - "--no-format-executable", - "--install-dir=.", - "--bindir=bin", - "--no-document", - match.tbl_containing { - "main-package:42.13.37", - "supporting-package", - "supporting-package2", - }, - }) - end) - ) - - it( - "should provide receipt information", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, gem.packages { "main-package", "supporting-package", "supporting-package2" }) - assert.same({ - type = "gem", - package = "main-package", - }, ctx.receipt.primary_source) - assert.same({ - { - type = "gem", - package = "supporting-package", - }, - { - type = "gem", - package = "supporting-package2", - }, - }, ctx.receipt.secondary_sources) - end) - ) -end) - -describe("gem version check", function() - it( - "should return current version", - async_test(function() - stub(spawn, "gem") - spawn.gem.returns(Result.success { - stdout = _.dedent [[ - shellwords (default: 0.1.0) - singleton (default: 0.1.1) - solargraph (0.44.0) - stringio (default: 3.0.1) - strscan (default: 3.0.1) - ]], - }) - - local result = gem.get_installed_primary_package_version( - mock.new { - primary_source = mock.new { - type = "gem", - package = "solargraph", - }, - }, - "/tmp/install/dir" - ) - - assert.spy(spawn.gem).was_called(1) - assert.spy(spawn.gem).was_called_with(match.tbl_containing { - "list", - cwd = "/tmp/install/dir", - env = match.tbl_containing { - GEM_HOME = "/tmp/install/dir", - GEM_PATH = "/tmp/install/dir", - PATH = match.matches "^/tmp/install/dir/bin:.*$", - }, - }) - assert.is_true(result:is_success()) - assert.equals("0.44.0", result:get_or_nil()) - end) - ) - - it( - "should return outdated primary package", - async_test(function() - stub(spawn, "gem") - spawn.gem.returns(Result.success { - stdout = _.dedent [[ - shellwords (default: 0.1.0) - singleton (default: 0.1.1) - solargraph (0.44.0) - stringio (default: 3.0.1) - strscan (default: 3.0.1) - ]], - }) - stub(api, "get") - api.get.on_call_with("/api/rubygems/solargraph/versions/latest").returns(Result.success { - name = "solargraph", - version = "0.44.3", - }) - - local result = gem.check_outdated_primary_package( - mock.new { - primary_source = mock.new { - type = "gem", - package = "solargraph", - }, - }, - "/tmp/install/dir" - ) - - assert.is_true(result:is_success()) - assert.same({ - name = "solargraph", - current_version = "0.44.0", - latest_version = "0.44.3", - }, result:get_or_nil()) - end) - ) - - it( - "should return failure if primary package is not outdated", - async_test(function() - stub(spawn, "gem") - spawn.gem.returns(Result.success { - stdout = _.dedent [[ - shellwords (default: 0.1.0) - singleton (default: 0.1.1) - solargraph (0.44.0) - stringio (default: 3.0.1) - strscan (default: 3.0.1) - ]], - }) - stub(api, "get") - api.get.on_call_with("/api/rubygems/solargraph/versions/latest").returns(Result.success { - name = "solargraph", - version = "0.44.0", - }) - - local result = gem.check_outdated_primary_package( - mock.new { - primary_source = mock.new { - type = "gem", - package = "solargraph", - }, - }, - "/tmp/install/dir" - ) - - assert.is_true(result:is_failure()) - assert.equals("Primary package is not outdated.", result:err_or_nil()) - end) - ) - - it("should parse gem list output", function() - assert.same( - { - ["solargraph"] = "0.44.3", - ["unicode-display_width"] = "2.1.0", - }, - gem.parse_gem_list_output [[ - -*** LOCAL GEMS *** - -nokogiri (1.13.3 arm64-darwin) -solargraph (0.44.3) -unicode-display_width (2.1.0) -]] - ) - end) -end) diff --git a/tests/mason-core/managers/git_spec.lua b/tests/mason-core/managers/git_spec.lua deleted file mode 100644 index 50d2470f..00000000 --- a/tests/mason-core/managers/git_spec.lua +++ /dev/null @@ -1,181 +0,0 @@ -local Result = require "mason-core.result" -local _ = require "mason-core.functional" -local installer = require "mason-core.installer" -local mock = require "luassert.mock" -local spawn = require "mason-core.spawn" -local stub = require "luassert.stub" - -local git = require "mason-core.managers.git" - -describe("git manager", function() - it( - "should fail if no git repo provided", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - local err = assert.has_error(function() - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, function() - git.clone {} - end) - end) - assert.equals("No git URL provided.", err) - assert.spy(ctx.spawn.git).was_not_called() - end) - ) - - it( - "should clone provided repo", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, function() - git.clone { "https://github.com/williamboman/mason.nvim.git" } - end) - assert.spy(ctx.spawn.git).was_called(1) - assert.spy(ctx.spawn.git).was_called_with { - "clone", - "--depth", - "1", - vim.NIL, - "https://github.com/williamboman/mason.nvim.git", - ".", - } - end) - ) - - it( - "should fetch and checkout revision if requested", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "1337" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, function() - git.clone { "https://github.com/williamboman/mason.nvim.git" } - end) - assert.spy(ctx.spawn.git).was_called(3) - assert.spy(ctx.spawn.git).was_called_with { - "clone", - "--depth", - "1", - vim.NIL, - "https://github.com/williamboman/mason.nvim.git", - ".", - } - assert.spy(ctx.spawn.git).was_called_with { - "fetch", - "--depth", - "1", - "origin", - "1337", - } - assert.spy(ctx.spawn.git).was_called_with { "checkout", "FETCH_HEAD" } - end) - ) - - it( - "should provide receipt information", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, function() - git.clone({ "https://github.com/williamboman/mason.nvim.git" }).with_receipt() - end) - assert.same({ - type = "git", - remote = "https://github.com/williamboman/mason.nvim.git", - }, ctx.receipt.primary_source) - assert.is_true(#ctx.receipt.secondary_sources == 0) - end) - ) -end) - -describe("git version check", function() - it( - "should return current version", - async_test(function() - stub(spawn, "git") - spawn.git.returns(Result.success { - stdout = [[19c668c]], - }) - - local result = git.get_installed_revision({ type = "git" }, "/tmp/install/dir") - - assert.spy(spawn.git).was_called(1) - assert.spy(spawn.git).was_called_with { "rev-parse", "--short", "HEAD", cwd = "/tmp/install/dir" } - assert.is_true(result:is_success()) - assert.equals("19c668c", result:get_or_nil()) - end) - ) - - it( - "should check for outdated git clone", - async_test(function() - stub(spawn, "git") - spawn.git.returns(Result.success { - stdout = _.dedent [[ - 728307a74cd5f2dec7ca2ca164785c25673d6328 - 19c668cd10695b243b09452f0dfd53570c1a2e7d - ]], - }) - - local result = git.check_outdated_git_clone( - mock.new { - primary_source = mock.new { - type = "git", - remote = "https://github.com/williamboman/mason.nvim.git", - }, - }, - "/tmp/install/dir" - ) - - assert.spy(spawn.git).was_called(2) - assert.spy(spawn.git).was_called_with { - "fetch", - "origin", - "HEAD", - cwd = "/tmp/install/dir", - } - assert.spy(spawn.git).was_called_with { - "rev-parse", - "FETCH_HEAD", - "HEAD", - cwd = "/tmp/install/dir", - } - assert.is_true(result:is_success()) - assert.same({ - name = "https://github.com/williamboman/mason.nvim.git", - current_version = "19c668cd10695b243b09452f0dfd53570c1a2e7d", - latest_version = "728307a74cd5f2dec7ca2ca164785c25673d6328", - }, result:get_or_nil()) - end) - ) - - it( - "should return failure if clone is not outdated", - async_test(function() - stub(spawn, "git") - spawn.git.returns(Result.success { - stdout = _.dedent [[ - 19c668cd10695b243b09452f0dfd53570c1a2e7d - 19c668cd10695b243b09452f0dfd53570c1a2e7d - ]], - }) - - local result = git.check_outdated_git_clone( - mock.new { - primary_source = mock.new { - type = "git", - remote = "https://github.com/williamboman/mason.nvim.git", - }, - }, - "/tmp/install/dir" - ) - - assert.is_true(result:is_failure()) - assert.equals("Git clone is up to date.", result:err_or_nil()) - end) - ) -end) diff --git a/tests/mason-core/managers/github_client_spec.lua b/tests/mason-core/managers/github_client_spec.lua deleted file mode 100644 index d07a0e74..00000000 --- a/tests/mason-core/managers/github_client_spec.lua +++ /dev/null @@ -1,23 +0,0 @@ -local Result = require "mason-core.result" -local client = require "mason-core.managers.github.client" -local spawn = require "mason-core.spawn" -local stub = require "luassert.stub" - -describe("github client", function() - it("should provide query parameters in api calls", function() - stub(spawn, "gh") - spawn.gh.returns(Result.success { stdout = "response data" }) - client.api_call("repos/some/repo", { - params = { - page = 23, - page_limit = 82, - }, - }) - assert.spy(spawn.gh).was_called(1) - assert.spy(spawn.gh).was_called_with { - "api", - "repos/some/repo?page=23&page_limit=82", - env = { CLICOLOR_FORCE = 0 }, - } - end) -end) diff --git a/tests/mason-core/managers/github_spec.lua b/tests/mason-core/managers/github_spec.lua deleted file mode 100644 index 852c3ff6..00000000 --- a/tests/mason-core/managers/github_spec.lua +++ /dev/null @@ -1,103 +0,0 @@ -local mock = require "luassert.mock" -local stub = require "luassert.stub" - -local Optional = require "mason-core.optional" -local Result = require "mason-core.result" -local github = require "mason-core.managers.github" -local installer = require "mason-core.installer" -local providers = require "mason-core.providers" - -describe("github release file", function() - it( - "should use provided version", - async_test(function() - stub(providers.github, "get_latest_release") - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - installer.prepare_installer(ctx):get_or_throw() - local source = installer.exec_in_context(ctx, function() - return github.release_file { - repo = "williamboman/mason.nvim", - asset_file = "program.exe", - version = Optional.of "13.37", - } - end) - assert.spy(providers.github.get_latest_release).was_not_called() - assert.equals("13.37", source.release) - assert.equals( - "https://github.com/williamboman/mason.nvim/releases/download/13.37/program.exe", - source.download_url - ) - end) - ) - - it( - "should use use dynamic asset_file", - async_test(function() - stub(providers.github, "get_latest_release") - providers.github.get_latest_release.returns(Result.success(mock.new { - tag_name = "im_the_tag", - })) - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - installer.prepare_installer(ctx):get_or_throw() - local source = installer.exec_in_context(ctx, function() - return github.release_file { - repo = "williamboman/mason.nvim", - asset_file = function(version) - return version .. "_for_reals" - end, - } - end) - assert.spy(providers.github.get_latest_release).was_called(1) - assert.spy(providers.github.get_latest_release).was_called_with "williamboman/mason.nvim" - assert.equals("im_the_tag", source.release) - assert.equals("im_the_tag_for_reals", source.asset_file) - assert.equals( - "https://github.com/williamboman/mason.nvim/releases/download/im_the_tag/im_the_tag_for_reals", - source.download_url - ) - end) - ) -end) - -describe("github release version", function() - it( - "should use provided version", - async_test(function() - stub(providers.github, "get_latest_release") - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - installer.prepare_installer(ctx):get_or_throw() - local source = installer.exec_in_context(ctx, function() - return github.release_version { - repo = "williamboman/mason.nvim", - version = Optional.of "13.37", - } - end) - assert.spy(providers.github.get_latest_release).was_not_called() - assert.equals("13.37", source.release) - end) - ) - - it( - "should fetch latest release from GitHub API", - async_test(function() - async_test(function() - stub(providers.github, "get_latest_release") - providers.github.get_latest_release.returns(Result.success { tag_name = "v42" }) - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - installer.prepare_installer(ctx):get_or_throw() - local source = installer.exec_in_context(ctx, function() - return github.release_version { - repo = "williamboman/mason.nvim", - } - end) - assert.spy(providers.github.get_latest_release).was_called(1) - assert.spy(providers.github.get_latest_release).was_called_with "williamboman/mason.nvim" - assert.equals("v42", source.release) - end) - end) - ) -end) diff --git a/tests/mason-core/managers/go_spec.lua b/tests/mason-core/managers/go_spec.lua deleted file mode 100644 index fd3ca043..00000000 --- a/tests/mason-core/managers/go_spec.lua +++ /dev/null @@ -1,171 +0,0 @@ -local Result = require "mason-core.result" -local go = require "mason-core.managers.go" -local installer = require "mason-core.installer" -local mock = require "luassert.mock" -local path = require "mason-core.path" -local spawn = require "mason-core.spawn" -local spy = require "luassert.spy" -local stub = require "luassert.stub" - -describe("go manager", function() - it( - "should call go install", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, go.packages { "main-package", "supporting-package", "supporting-package2" }) - assert.spy(ctx.spawn.go).was_called(3) - assert.spy(ctx.spawn.go).was_called_with { - "install", - "-v", - "main-package@42.13.37", - env = { GOBIN = path.package_build_prefix "dummy" }, - } - assert.spy(ctx.spawn.go).was_called_with { - "install", - "-v", - "supporting-package@latest", - env = { GOBIN = path.package_build_prefix "dummy" }, - } - assert.spy(ctx.spawn.go).was_called_with { - "install", - "-v", - "supporting-package2@latest", - env = { GOBIN = path.package_build_prefix "dummy" }, - } - end) - ) - - it( - "should provide receipt information", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, go.packages { "main-package", "supporting-package", "supporting-package2" }) - assert.same({ - type = "go", - package = "main-package", - }, ctx.receipt.primary_source) - assert.same({ - { - type = "go", - package = "supporting-package", - }, - { - type = "go", - package = "supporting-package2", - }, - }, ctx.receipt.secondary_sources) - end) - ) -end) - -describe("go version check", function() - local go_version_output = [[ -gopls: go1.18 - path golang.org/x/tools/cmd - mod golang.org/x/tools/cmd v0.8.1 h1:q5nDpRopYrnF4DN/1o8ZQ7Oar4Yd4I5OtGMx5RyV2/8= - dep github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= - dep mvdan.cc/xurls/v2 v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc= - build -compiler=gc - build GOOS=darwin -]] - - it("should parse go version output", function() - local parsed = go.parse_mod_version_output(go_version_output) - assert.same({ - path = { ["golang.org/x/tools/cmd"] = "" }, - mod = { ["golang.org/x/tools/cmd"] = "v0.8.1" }, - dep = { ["github.com/google/go-cmp"] = "v0.5.7", ["mvdan.cc/xurls/v2"] = "v2.4.0" }, - build = { ["-compiler=gc"] = "", ["GOOS=darwin"] = "" }, - }, parsed) - end) - - it( - "should return current version", - async_test(function() - stub(spawn, "go") - spawn.go.returns(Result.success { stdout = go_version_output }) - - local result = go.get_installed_primary_package_version( - mock.new { - primary_source = mock.new { - type = "go", - package = "golang.org/x/tools/cmd/gopls/...", - }, - }, - path.package_prefix "dummy" - ) - - assert.spy(spawn.go).was_called(1) - assert.spy(spawn.go).was_called_with { - "version", - "-m", - "gopls", - cwd = path.package_prefix "dummy", - } - assert.is_true(result:is_success()) - assert.equals("v0.8.1", result:get_or_nil()) - end) - ) - - it( - "should return outdated primary package", - async_test(function() - stub(spawn, "go") - spawn.go - .on_call_with({ - "list", - "-json", - "-m", - "golang.org/x/tools/cmd@latest", - cwd = path.package_prefix "dummy", - }) - .returns(Result.success { - stdout = ([[ - { - "Path": %q, - "Version": "v2.0.0" - } - ]]):format(path.package_prefix "dummy"), - }) - spawn.go - .on_call_with({ - "version", - "-m", - "gopls", - cwd = path.package_prefix "dummy", - }) - .returns(Result.success { - stdout = go_version_output, - }) - - local result = go.check_outdated_primary_package( - mock.new { - primary_source = mock.new { - type = "go", - package = "golang.org/x/tools/cmd/gopls/...", - }, - }, - path.package_prefix "dummy" - ) - - assert.is_true(result:is_success()) - assert.same({ - name = "golang.org/x/tools/cmd", - current_version = "v0.8.1", - latest_version = "v2.0.0", - }, result:get_or_nil()) - end) - ) - - it("should parse package mod names", function() - assert.equals("github.com/cweill/gotests", go.parse_package_mod "github.com/cweill/gotests/...") - assert.equals("golang.org/x/tools/gopls", go.parse_package_mod "golang.org/x/tools/gopls/...") - assert.equals("golang.org/x/crypto", go.parse_package_mod "golang.org/x/crypto/...") - assert.equals("github.com/go-delve/delve", go.parse_package_mod "github.com/go-delve/delve/cmd/dlv") - assert.equals("mvdan.cc/sh/v3", go.parse_package_mod "mvdan.cc/sh/v3/cmd/shfmt") - end) -end) diff --git a/tests/mason-core/managers/luarocks_spec.lua b/tests/mason-core/managers/luarocks_spec.lua deleted file mode 100644 index d89f65fa..00000000 --- a/tests/mason-core/managers/luarocks_spec.lua +++ /dev/null @@ -1,139 +0,0 @@ -local a = require "mason-core.async" -local installer = require "mason-core.installer" -local luarocks = require "mason-core.managers.luarocks" -local path = require "mason-core.path" - -describe("luarocks manager", function() - before_each(function() - a.run_blocking(installer.create_prefix_dirs) - end) - - it( - "should install provided package", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, luarocks.package "lua-cjson") - assert.spy(ctx.spawn.luarocks).was_called(1) - assert.spy(ctx.spawn.luarocks).was_called_with { - "install", - "--tree", - path.package_prefix "dummy", - vim.NIL, -- --dev flag - vim.NIL, -- --server flag - "lua-cjson", - vim.NIL, -- version - } - end) - ) - - it( - "should install provided version", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "1.2.3" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, luarocks.package "lua-cjson") - assert.spy(ctx.spawn.luarocks).was_called(1) - assert.spy(ctx.spawn.luarocks).was_called_with { - "install", - "--tree", - path.package_prefix "dummy", - vim.NIL, -- --dev flag - vim.NIL, -- --server flag - "lua-cjson", - "1.2.3", - } - end) - ) - - it( - "should provide --dev flag", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, luarocks.package("lua-cjson", { dev = true })) - assert.spy(ctx.spawn.luarocks).was_called(1) - assert.spy(ctx.spawn.luarocks).was_called_with { - "install", - "--tree", - path.package_prefix "dummy", - "--dev", - vim.NIL, -- --server flag - "lua-cjson", - vim.NIL, -- version - } - end) - ) - - it( - "should provide --server flag", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, luarocks.package("luaformatter", { server = "https://luarocks.org/dev" })) - assert.spy(ctx.spawn.luarocks).was_called(1) - assert.spy(ctx.spawn.luarocks).was_called_with { - "install", - "--tree", - path.package_prefix "dummy", - vim.NIL, -- --dev flag - "--server=https://luarocks.org/dev", - "luaformatter", - vim.NIL, -- version - } - end) - ) - - it("should parse outdated luarocks", function() - assert.same( - { - { - name = "lua-cjson", - installed = "2.1.0-1", - available = "2.1.0.6-1", - repo = "https://luarocks.org", - }, - { - name = "lua-resty-influx-mufanh", - installed = "0.2.1-0", - available = "0.2.1-1", - repo = "https://luarocks.org", - }, - }, - luarocks.parse_outdated_rocks [[lua-cjson 2.1.0-1 2.1.0.6-1 https://luarocks.org -lua-resty-influx-mufanh 0.2.1-0 0.2.1-1 https://luarocks.org]] - ) - end) - - it("should parse listed luarocks", function() - assert.same( - { - { - package = "lua-cjson", - version = "2.1.0-1", - arch = "installed", - nrepo = "/my/luarock/loc", - }, - { - package = "lua-resty-http", - version = "0.17.0.beta.1-0", - arch = "installed", - nrepo = "/my/luarock/loc", - }, - { - package = "lua-resty-influx-mufanh", - version = "0.2.1-0", - arch = "installed", - nrepo = "/my/luarock/loc", - }, - }, - luarocks.parse_installed_rocks [[lua-cjson 2.1.0-1 installed /my/luarock/loc -lua-resty-http 0.17.0.beta.1-0 installed /my/luarock/loc -lua-resty-influx-mufanh 0.2.1-0 installed /my/luarock/loc]] - ) - end) -end) diff --git a/tests/mason-core/managers/npm_spec.lua b/tests/mason-core/managers/npm_spec.lua deleted file mode 100644 index 31500ac7..00000000 --- a/tests/mason-core/managers/npm_spec.lua +++ /dev/null @@ -1,206 +0,0 @@ -local Result = require "mason-core.result" -local api = require "mason-registry.api" -local installer = require "mason-core.installer" -local match = require "luassert.match" -local mock = require "luassert.mock" -local npm = require "mason-core.managers.npm" -local path = require "mason-core.path" -local spawn = require "mason-core.spawn" -local spy = require "luassert.spy" -local stub = require "luassert.stub" - -describe("npm manager", function() - it( - "should call npm install", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, npm.packages { "main-package", "supporting-package", "supporting-package2" }) - assert.spy(ctx.spawn.npm).was_called_with(match.tbl_containing { - "install", - match.tbl_containing { - "main-package@42.13.37", - "supporting-package", - "supporting-package2", - }, - }) - end) - ) - - it( - "should call npm init if node_modules and package.json doesnt exist", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - ctx.fs.file_exists = mockx.returns(false) - ctx.fs.dir_exists = mockx.returns(false) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, function() - npm.install { "main-package", "supporting-package", "supporting-package2" } - end) - assert.spy(ctx.spawn.npm).was_called_with { - "init", - "--yes", - "--scope=mason", - } - end) - ) - - it( - "should append .npmrc file", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - ctx.fs.append_file = spy.new(mockx.just_runs()) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, npm.packages { "main-package", "supporting-package", "supporting-package2" }) - assert.spy(ctx.fs.append_file).was_called(1) - assert.spy(ctx.fs.append_file).was_called_with(ctx.fs, ".npmrc", "global-style=true") - end) - ) - - it( - "should provide receipt information", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, npm.packages { "main-package", "supporting-package", "supporting-package2" }) - assert.same({ - type = "npm", - package = "main-package", - }, ctx.receipt.primary_source) - assert.same({ - { - type = "npm", - package = "supporting-package", - }, - { - type = "npm", - package = "supporting-package2", - }, - }, ctx.receipt.secondary_sources) - end) - ) -end) - -describe("npm version check", function() - it( - "should return current version", - async_test(function() - stub(spawn, "npm", function() - return Result.success { - stdout = [[ - { - "name": "bash", - "dependencies": { - "bash-language-server": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/bash-language-server/-/bash-language-server-2.0.0.tgz" - } - } - } - ]], - } - end) - - local result = npm.get_installed_primary_package_version( - mock.new { - primary_source = mock.new { - type = "npm", - package = "bash-language-server", - }, - }, - path.package_prefix "dummy" - ) - - assert.spy(spawn.npm).was_called(1) - assert.spy(spawn.npm).was_called_with { "ls", "--json", cwd = path.package_prefix "dummy" } - assert.is_true(result:is_success()) - assert.equals("2.0.0", result:get_or_nil()) - end) - ) - - it( - "should return outdated primary package", - async_test(function() - stub(api, "get") - api.get.on_call_with("/api/npm/bash-language-server/versions/latest").returns(Result.success { - name = "bash-language-server", - version = "2.0.0", - }) - stub(spawn, "npm", function() - return Result.success { - stdout = [[ - { - "name": "bash", - "dependencies": { - "bash-language-server": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/bash-language-server/-/bash-language-server-1.17.0.tgz" - } - } - } - ]], - } - end) - - local result = npm.check_outdated_primary_package( - mock.new { - primary_source = mock.new { - type = "npm", - package = "bash-language-server", - }, - }, - path.package_prefix "dummy" - ) - - assert.is_true(result:is_success()) - assert.same({ - name = "bash-language-server", - current_version = "1.17.0", - latest_version = "2.0.0", - }, result:get_or_nil()) - end) - ) - - it( - "should return failure if primary package is not outdated", - async_test(function() - stub(spawn, "npm", function() - return Result.success { - stdout = [[ - { - "name": "bash", - "dependencies": { - "bash-language-server": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/bash-language-server/-/bash-language-server-1.17.0.tgz" - } - } - } - ]], - } - end) - stub(api, "get") - api.get.on_call_with("/api/npm/bash-language-server/versions/latest").returns(Result.success { - name = "bash-language-server", - version = "1.17.0", - }) - - local result = npm.check_outdated_primary_package( - mock.new { - primary_source = mock.new { - type = "npm", - package = "bash-language-server", - }, - }, - path.package_prefix "dummy" - ) - - assert.is_true(result:is_failure()) - assert.equals("Primary package is not outdated.", result:err_or_nil()) - end) - ) -end) diff --git a/tests/mason-core/managers/opam_spec.lua b/tests/mason-core/managers/opam_spec.lua deleted file mode 100644 index 297f9d8b..00000000 --- a/tests/mason-core/managers/opam_spec.lua +++ /dev/null @@ -1,57 +0,0 @@ -local installer = require "mason-core.installer" -local match = require "luassert.match" -local opam = require "mason-core.managers.opam" - -describe("opam manager", function() - it( - "should call opam install", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context( - ctx, - opam.packages { "main-package", "supporting-package", "supporting-package2" } - ) - assert.spy(ctx.spawn.opam).was_called(1) - assert.spy(ctx.spawn.opam).was_called_with(match.tbl_containing { - "install", - "--destdir=.", - "--yes", - "--verbose", - match.tbl_containing { - "main-package.42.13.37", - "supporting-package", - "supporting-package2", - }, - }) - end) - ) - - it( - "should provide receipt information", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context( - ctx, - opam.packages { "main-package", "supporting-package", "supporting-package2" } - ) - assert.same({ - type = "opam", - package = "main-package", - }, ctx.receipt.primary_source) - assert.same({ - { - type = "opam", - package = "supporting-package", - }, - { - type = "opam", - package = "supporting-package2", - }, - }, ctx.receipt.secondary_sources) - end) - ) -end) diff --git a/tests/mason-core/managers/pip3_spec.lua b/tests/mason-core/managers/pip3_spec.lua deleted file mode 100644 index 9ad8e1d8..00000000 --- a/tests/mason-core/managers/pip3_spec.lua +++ /dev/null @@ -1,284 +0,0 @@ -local mock = require "luassert.mock" -local path = require "mason-core.path" -local spy = require "luassert.spy" -local stub = require "luassert.stub" - -local Result = require "mason-core.result" -local _ = require "mason-core.functional" -local a = require "mason-core.async" -local api = require "mason-registry.api" -local installer = require "mason-core.installer" -local pip3 = require "mason-core.managers.pip3" -local settings = require "mason.settings" -local spawn = require "mason-core.spawn" - -describe("pip3 manager", function() - before_each(function() - settings.set(settings._DEFAULT_SETTINGS) - a.run_blocking(installer.create_prefix_dirs) - end) - - it("normalizes pip3 packages", function() - local normalize = pip3.normalize_package - assert.equals("python-lsp-server", normalize "python-lsp-server[all]") - assert.equals("python-lsp-server", normalize "python-lsp-server[]") - assert.equals("python-lsp-server", normalize "python-lsp-server[[]]") - end) - - it( - "should create venv and call pip3 install", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context( - ctx, - pip3.packages { "main-package", "supporting-package", "supporting-package2" } - ) - assert.equals(path.package_prefix "dummy", ctx.cwd:get()) -- should've promoted cwd - assert.spy(ctx.spawn.python3).was_called(1) - assert.spy(ctx.spawn.python3).was_called_with { - "-m", - "venv", - "venv", - } - assert.spy(ctx.spawn.python).was_called(1) - assert.spy(ctx.spawn.python).was_called_with { - "-m", - "pip", - "--disable-pip-version-check", - "install", - "-U", - {}, - { - "main-package==42.13.37", - "supporting-package", - "supporting-package2", - }, - with_paths = { path.concat { path.package_prefix "dummy", "venv", "bin" } }, - } - end) - ) - - it( - "should exhaust python3 executable candidates if all fail", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - ctx.spawn.python3 = spy.new(mockx.throws()) - ctx.spawn.python = spy.new(mockx.throws()) - local err = assert.has_error(function() - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, pip3.packages { "package" }) - end) - - assert.equals("Unable to create python3 venv environment.", err) - assert.spy(ctx.spawn.python3).was_called(1) - assert.spy(ctx.spawn.python).was_called(1) - end) - ) - - it( - "should use install_args from settings", - async_test(function() - settings.set { - pip = { - install_args = { "--proxy", "http://localhost:8080" }, - }, - } - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, pip3.packages { "package" }) - assert.spy(ctx.spawn.python).was_called(1) - assert.spy(ctx.spawn.python).was_called_with { - "-m", - "pip", - "--disable-pip-version-check", - "install", - "-U", - { "--proxy", "http://localhost:8080" }, - { "package" }, - with_paths = { path.concat { path.package_prefix "dummy", "venv", "bin" } }, - } - end) - ) - - it( - "should upgrade pip", - async_test(function() - settings.set { - pip = { - upgrade_pip = true, - }, - } - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context(ctx, pip3.packages { "package" }) - assert.spy(ctx.spawn.python).was_called(2) - assert.spy(ctx.spawn.python).was_called_with { - "-m", - "pip", - "--disable-pip-version-check", - "install", - "-U", - {}, - "pip", - with_paths = { path.concat { path.package_prefix "dummy", "venv", "bin" } }, - } - assert.spy(ctx.spawn.python).was_called_with { - "-m", - "pip", - "--disable-pip-version-check", - "install", - "-U", - {}, - { "package" }, - with_paths = { path.concat { path.package_prefix "dummy", "venv", "bin" } }, - } - end) - ) - - it( - "should provide receipt information", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { version = "42.13.37" }) - installer.prepare_installer(ctx):get_or_throw() - installer.exec_in_context( - ctx, - pip3.packages { "main-package", "supporting-package", "supporting-package2" } - ) - assert.same({ - type = "pip3", - package = "main-package", - }, ctx.receipt.primary_source) - assert.same({ - { - type = "pip3", - package = "supporting-package", - }, - { - type = "pip3", - package = "supporting-package2", - }, - }, ctx.receipt.secondary_sources) - end) - ) -end) - -describe("pip3 version check", function() - it( - "should return current version", - async_test(function() - stub(spawn, "python") - spawn.python.returns(Result.success { - stdout = _.dedent [[ - [ - {"name": "astroid", "version": "2.9.3"}, - {"name": "mccabe", "version": "0.6.1"}, - {"name": "python-lsp-server", "version": "1.3.0", "latest_version": "1.4.0", "latest_filetype": "wheel"}, - {"name": "wrapt", "version": "1.13.3", "latest_version": "1.14.0", "latest_filetype": "wheel"} - ] - ]], - }) - - local result = pip3.get_installed_primary_package_version( - mock.new { - primary_source = mock.new { - type = "pip3", - package = "python-lsp-server", - }, - }, - path.package_prefix "dummy" - ) - - assert.spy(spawn.python).was_called(1) - assert.spy(spawn.python).was_called_with { - "-m", - "pip", - "list", - "--format=json", - cwd = path.package_prefix "dummy", - with_paths = { path.concat { path.package_prefix "dummy", "venv", "bin" } }, - } - assert.is_true(result:is_success()) - assert.equals("1.3.0", result:get_or_nil()) - end) - ) - - it( - "should return outdated primary package", - async_test(function() - stub(api, "get") - api.get.on_call_with("/api/pypi/python-lsp-server/versions/latest").returns(Result.success { - name = "python-lsp-server", - version = "1.4.0", - }) - stub(spawn, "python") - spawn.python.returns(Result.success { - stdout = [[ - [ - {"name": "astroid", "version": "2.9.3"}, - {"name": "mccabe", "version": "0.6.1"}, - {"name": "python-lsp-server", "version": "1.3.0", "latest_version": "1.4.0", "latest_filetype": "wheel"}, - {"name": "wrapt", "version": "1.13.3", "latest_version": "1.14.0", "latest_filetype": "wheel"} - ] - ]], - }) - - local result = pip3.check_outdated_primary_package( - mock.new { - primary_source = mock.new { - type = "pip3", - package = "python-lsp-server", - }, - }, - path.package_prefix "dummy" - ) - - assert.is_true(result:is_success()) - assert.same({ - name = "python-lsp-server", - current_version = "1.3.0", - latest_version = "1.4.0", - }, result:get_or_nil()) - end) - ) - - it( - "should return failure if primary package is not outdated", - async_test(function() - stub(spawn, "python") - spawn.python.returns(Result.success { - stdout = [[ - [ - {"name": "astroid", "version": "2.9.3"}, - {"name": "mccabe", "version": "0.6.1"}, - {"name": "python-lsp-server", "version": "1.3.0", "latest_version": "1.4.0", "latest_filetype": "wheel"}, - {"name": "wrapt", "version": "1.13.3", "latest_version": "1.14.0", "latest_filetype": "wheel"} - ] - ]], - }) - stub(api, "get") - api.get.on_call_with("/api/pypi/python-lsp-server/versions/latest").returns(Result.success { - name = "python-lsp-server", - version = "1.3.0", - }) - - local result = pip3.check_outdated_primary_package( - mock.new { - primary_source = mock.new { - type = "pip3", - package = "python-lsp-server", - }, - }, - "/tmp/install/dir" - ) - - assert.is_true(result:is_failure()) - assert.equals("Primary package is not outdated.", result:err_or_nil()) - end) - ) -end) |
