aboutsummaryrefslogtreecommitdiffstats
path: root/tests/core/managers
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-07-08 18:34:38 +0200
committerGitHub <noreply@github.com>2022-07-08 18:34:38 +0200
commit976aa4fbee8a070f362cab6f6ec84e9251a90cf9 (patch)
tree5e8d9c9c59444a25c7801b8f39763c4ba6e1f76d /tests/core/managers
parentfeat: add gotests, gomodifytags, impl (#28) (diff)
downloadmason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar
mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.gz
mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.bz2
mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.lz
mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.xz
mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.zst
mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.zip
refactor: add mason-schemas and mason-core modules (#29)
* refactor: add mason-schemas and move generated filetype map to mason-lspconfig * refactor: add mason-core module
Diffstat (limited to 'tests/core/managers')
-rw-r--r--tests/core/managers/cargo_spec.lua226
-rw-r--r--tests/core/managers/composer_spec.lua179
-rw-r--r--tests/core/managers/dotnet_spec.lua35
-rw-r--r--tests/core/managers/gem_spec.lua206
-rw-r--r--tests/core/managers/git_spec.lua181
-rw-r--r--tests/core/managers/github_client_spec.lua41
-rw-r--r--tests/core/managers/go_spec.lua174
-rw-r--r--tests/core/managers/luarocks_spec.lua109
-rw-r--r--tests/core/managers/npm_spec.lua194
-rw-r--r--tests/core/managers/opam_spec.lua51
-rw-r--r--tests/core/managers/pip3_spec.lua242
11 files changed, 0 insertions, 1638 deletions
diff --git a/tests/core/managers/cargo_spec.lua b/tests/core/managers/cargo_spec.lua
deleted file mode 100644
index 59bb75da..00000000
--- a/tests/core/managers/cargo_spec.lua
+++ /dev/null
@@ -1,226 +0,0 @@
-local spy = require "luassert.spy"
-local match = require "luassert.match"
-local mock = require "luassert.mock"
-local Optional = require "mason.core.optional"
-local installer = require "mason.core.installer"
-local cargo = require "mason.core.managers.cargo"
-local Result = require "mason.core.result"
-local spawn = require "mason.core.spawn"
-local path = require "mason.core.path"
-
-describe("cargo manager", function()
- it(
- "should call cargo install",
- async_test(function()
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
- installer.run_installer(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, -- --features
- "my-crate",
- }
- end)
- )
-
- it(
- "should call cargo install with git source",
- async_test(function()
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle)
- installer.run_installer(ctx, cargo.crate("https://my-crate.git", { git = true }))
- assert.spy(ctx.spawn.cargo).was_called(1)
- assert.spy(ctx.spawn.cargo).was_called_with {
- "install",
- "--root",
- ".",
- "--locked",
- vim.NIL,
- vim.NIL, -- --features
- { "--git", "https://my-crate.git" },
- }
- 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.run_installer(ctx, cargo.crate("crate-name", { git = "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,
- vim.NIL, -- --features
- { "--git", "https://my-crate.git", "crate-name" },
- }
- end)
- )
-
- it(
- "should respect options",
- async_test(function()
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
- installer.run_installer(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" },
- { "--features", "lsp" },
- "my-crate",
- }
- end)
- )
-
- it(
- "should not allow combining version with git crate",
- async_test(function()
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
- local err = assert.has_error(function()
- installer.run_installer(
- ctx,
- cargo.crate("my-crate", {
- git = true,
- })
- )
- end)
- assert.equals("Providing a version when installing a git crate is not allowed.", err)
- assert.spy(ctx.spawn.cargo).was_called(0)
- end)
- )
-
- it(
- "should provide receipt information",
- async_test(function()
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle)
- installer.run_installer(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"] = "0.18.3",
- ["exa"] = "0.10.1",
- ["git-select-branch"] = "0.1.1",
- ["hello_world"] = "0.0.1",
- ["rust-analyzer"] = "0.0.0",
- ["stylua"] = "0.11.2",
- ["zoxide"] = "0.5.0",
- },
- cargo.parse_installed_crates [[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
-rust-analyzer v0.0.0 (/private/var/folders/ky/s6yyhm_d24d0jsrql4t8k4p40000gn/T/tmp.YlsHeA9JVL/crates/rust-analyzer):
- rust-analyzer
-stylua v0.11.2:
- stylua
-zoxide v0.5.0:
- zoxide
-]]
- )
- end)
-
- it(
- "should return current version",
- async_test(function()
- spawn.cargo = spy.new(function()
- return Result.success {
- stdout = [[flux-lsp v0.8.8 (https://github.com/influxdata/flux-lsp#4e452f07):
- flux-lsp
-]],
- }
- end)
-
- 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("0.8.8", result:get_or_nil())
-
- spawn.cargo = nil
- end)
- )
-
- -- XXX: This test will actually send http request to crates.io's API. It's not mocked.
- it(
- "should return outdated primary package",
- async_test(function()
- spawn.cargo = spy.new(function()
- return Result.success {
- stdout = [[lelwel v0.4.0:
- lelwel-ls
-]],
- }
- end)
-
- 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 = match.matches "%d.%d.%d",
- name = "lelwel",
- }(result:get_or_nil()))
-
- spawn.cargo = nil
- end)
- )
-end)
diff --git a/tests/core/managers/composer_spec.lua b/tests/core/managers/composer_spec.lua
deleted file mode 100644
index 48cb4784..00000000
--- a/tests/core/managers/composer_spec.lua
+++ /dev/null
@@ -1,179 +0,0 @@
-local spy = require "luassert.spy"
-local mock = require "luassert.mock"
-local installer = require "mason.core.installer"
-local Optional = require "mason.core.optional"
-local composer = require "mason.core.managers.composer"
-local Result = require "mason.core.result"
-local spawn = require "mason.core.spawn"
-local path = require "mason.core.path"
-
-describe("composer manager", function()
- it(
- "should call composer require",
- async_test(function()
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
- ctx.fs.file_exists = spy.new(mockx.returns(false))
- installer.run_installer(
- 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, { requested_version = "42.13.37" })
- installer.run_installer(
- 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()
- spawn.composer = spy.new(function()
- return Result.success {
- stdout = [[
-{
- "name": "vimeo/psalm",
- "versions": [
- "4.0.0"
- ]
-}
-]],
- }
- end)
-
- 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())
-
- spawn.composer = nil
- end)
- )
-
- it(
- "should return outdated primary package",
- async_test(function()
- spawn.composer = spy.new(function()
- return 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"
- }
- ]
-}
-]],
- }
- end)
-
- 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())
-
- spawn.composer = nil
- end)
- )
-
- it(
- "should return failure if primary package is not outdated",
- async_test(function()
- spawn.composer = spy.new(function()
- return Result.success {
- stdout = [[{"installed": []}]],
- }
- end)
-
- 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())
- spawn.composer = nil
- end)
- )
-end)
diff --git a/tests/core/managers/dotnet_spec.lua b/tests/core/managers/dotnet_spec.lua
deleted file mode 100644
index ff922720..00000000
--- a/tests/core/managers/dotnet_spec.lua
+++ /dev/null
@@ -1,35 +0,0 @@
-local installer = require "mason.core.installer"
-local dotnet = require "mason.core.managers.dotnet"
-
-describe("dotnet manager", function()
- it(
- "should call dotnet tool update",
- async_test(function()
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
- installer.run_installer(ctx, dotnet.package "main-package")
- assert.spy(ctx.spawn.dotnet).was_called(1)
- assert.spy(ctx.spawn.dotnet).was_called_with {
- "tool",
- "update",
- "--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, { requested_version = "42.13.37" })
- installer.run_installer(ctx, dotnet.package "main-package")
- assert.same({
- type = "dotnet",
- package = "main-package",
- }, ctx.receipt.primary_source)
- end)
- )
-end)
diff --git a/tests/core/managers/gem_spec.lua b/tests/core/managers/gem_spec.lua
deleted file mode 100644
index 5beb6c95..00000000
--- a/tests/core/managers/gem_spec.lua
+++ /dev/null
@@ -1,206 +0,0 @@
-local spy = require "luassert.spy"
-local match = require "luassert.match"
-local mock = require "luassert.mock"
-local installer = require "mason.core.installer"
-local Optional = require "mason.core.optional"
-local gem = require "mason.core.managers.gem"
-local Result = require "mason.core.result"
-local spawn = require "mason.core.spawn"
-
-describe("gem manager", function()
- it(
- "should call gem install",
- async_test(function()
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
- installer.run_installer(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",
- "--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, { requested_version = "42.13.37" })
- installer.run_installer(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()
- spawn.gem = spy.new(function()
- return Result.success {
- stdout = [[shellwords (default: 0.1.0)
-singleton (default: 0.1.1)
-solargraph (0.44.0)
-stringio (default: 3.0.1)
-strscan (default: 3.0.1)
-]],
- }
- end)
-
- 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())
-
- spawn.gem = nil
- end)
- )
-
- it(
- "should return outdated primary package",
- async_test(function()
- spawn.gem = spy.new(function()
- return Result.success {
- stdout = [[bigdecimal (3.1.1 < 3.1.2)
-cgi (0.3.1 < 0.3.2)
-logger (1.5.0 < 1.5.1)
-ostruct (0.5.2 < 0.5.3)
-reline (0.3.0 < 0.3.1)
-securerandom (0.1.1 < 0.2.0)
-solargraph (0.44.0 < 0.44.3)
-]],
- }
- end)
-
- local result = gem.check_outdated_primary_package(
- 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 {
- "outdated",
- 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.same({
- name = "solargraph",
- current_version = "0.44.0",
- latest_version = "0.44.3",
- }, result:get_or_nil())
-
- spawn.gem = nil
- end)
- )
-
- it(
- "should return failure if primary package is not outdated",
- async_test(function()
- spawn.gem = spy.new(function()
- return Result.success {
- stdout = "",
- }
- end)
-
- 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())
- spawn.gem = nil
- end)
- )
-
- it("parses outdated gem output", function()
- local normalize = gem.parse_outdated_gem
- assert.same({
- name = "solargraph",
- current_version = "0.42.2",
- latest_version = "0.44.2",
- }, normalize [[solargraph (0.42.2 < 0.44.2)]])
- assert.same({
- name = "sorbet-runtime",
- current_version = "0.5.9307",
- latest_version = "0.5.9468",
- }, normalize [[sorbet-runtime (0.5.9307 < 0.5.9468)]])
- end)
-
- it("returns nil when unable to parse outdated gem", function()
- assert.is_nil(gem.parse_outdated_gem "a whole bunch of gibberish!")
- assert.is_nil(gem.parse_outdated_gem "")
- 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/core/managers/git_spec.lua b/tests/core/managers/git_spec.lua
deleted file mode 100644
index f6a3f9d1..00000000
--- a/tests/core/managers/git_spec.lua
+++ /dev/null
@@ -1,181 +0,0 @@
-local spy = require "luassert.spy"
-local mock = require "luassert.mock"
-local spawn = require "mason.core.spawn"
-local Result = require "mason.core.result"
-local installer = require "mason.core.installer"
-
-local git = require "mason.core.managers.git"
-local Optional = require "mason.core.optional"
-
-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_errors(function()
- installer.run_installer(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.run_installer(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, { requested_version = "1337" })
- installer.run_installer(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.run_installer(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()
- spawn.git = spy.new(function()
- return Result.success {
- stdout = [[19c668c]],
- }
- end)
-
- 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())
-
- spawn.git = nil
- end)
- )
-
- it(
- "should check for outdated git clone",
- async_test(function()
- spawn.git = spy.new(function()
- return Result.success {
- stdout = [[728307a74cd5f2dec7ca2ca164785c25673d6328
-19c668cd10695b243b09452f0dfd53570c1a2e7d]],
- }
- end)
-
- 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())
-
- spawn.git = nil
- end)
- )
-
- it(
- "should return failure if clone is not outdated",
- async_test(function()
- spawn.git = spy.new(function()
- return Result.success {
- stdout = [[19c668cd10695b243b09452f0dfd53570c1a2e7d
-19c668cd10695b243b09452f0dfd53570c1a2e7d]],
- }
- end)
-
- 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())
- spawn.git = nil
- end)
- )
-end)
diff --git a/tests/core/managers/github_client_spec.lua b/tests/core/managers/github_client_spec.lua
deleted file mode 100644
index 11e8c392..00000000
--- a/tests/core/managers/github_client_spec.lua
+++ /dev/null
@@ -1,41 +0,0 @@
-local client = require "mason.core.managers.github.client"
-
-describe("github client", function()
- ---@type GitHubRelease
- local release = {
- tag_name = "v0.1.0",
- prerelease = false,
- draft = false,
- assets = {},
- }
-
- local function stub_release(mock)
- return setmetatable(mock, { __index = release })
- end
-
- it("should identify stable prerelease", function()
- local predicate = client.release_predicate {
- include_prerelease = false,
- }
-
- assert.is_false(predicate(stub_release { prerelease = true }))
- assert.is_true(predicate(stub_release { prerelease = false }))
- end)
-
- it("should identify stable release with tag name pattern", function()
- local predicate = client.release_predicate {
- tag_name_pattern = "^lsp%-server.*$",
- }
-
- assert.is_false(predicate(stub_release { tag_name = "v0.1.0" }))
- assert.is_true(predicate(stub_release { tag_name = "lsp-server-v0.1.0" }))
- end)
-
- it("should identify stable release", function()
- local predicate = client.release_predicate {}
-
- assert.is_true(predicate(stub_release { tag_name = "v0.1.0" }))
- assert.is_false(predicate(stub_release { prerelease = true }))
- assert.is_false(predicate(stub_release { draft = true }))
- end)
-end)
diff --git a/tests/core/managers/go_spec.lua b/tests/core/managers/go_spec.lua
deleted file mode 100644
index 7526120e..00000000
--- a/tests/core/managers/go_spec.lua
+++ /dev/null
@@ -1,174 +0,0 @@
-local mock = require "luassert.mock"
-local stub = require "luassert.stub"
-local spy = require "luassert.spy"
-local Result = require "mason.core.result"
-local go = require "mason.core.managers.go"
-local spawn = require "mason.core.spawn"
-local installer = require "mason.core.installer"
-local path = require "mason.core.path"
-
-describe("go manager", function()
- it(
- "should call go install",
- async_test(function()
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
- installer.run_installer(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, { requested_version = "42.13.37" })
- installer.run_installer(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()
- spawn.go = spy.new(function()
- return Result.success { stdout = go_version_output }
- end)
-
- 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",
- }
- print(result:err_or_nil())
- assert.is_true(result:is_success())
- assert.equals("v0.8.1", result:get_or_nil())
-
- spawn.go = 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())
-
- spawn.go = 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")
- end)
-end)
diff --git a/tests/core/managers/luarocks_spec.lua b/tests/core/managers/luarocks_spec.lua
deleted file mode 100644
index a7091e51..00000000
--- a/tests/core/managers/luarocks_spec.lua
+++ /dev/null
@@ -1,109 +0,0 @@
-local installer = require "mason.core.installer"
-local luarocks = require "mason.core.managers.luarocks"
-local path = require "mason.core.path"
-
-describe("luarocks manager", function()
- it(
- "should install provided package",
- async_test(function()
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle)
- installer.run_installer(ctx, luarocks.package "lua-cjson")
- assert.spy(ctx.spawn.luarocks).was_called(1)
- print(vim.inspect(ctx.spawn.luarocks))
- assert.spy(ctx.spawn.luarocks).was_called_with {
- "install",
- "--tree",
- path.package_prefix "dummy",
- vim.NIL, -- --dev flag
- "lua-cjson",
- vim.NIL, -- version
- }
- end)
- )
-
- it(
- "should install provided version",
- async_test(function()
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle, { requested_version = "1.2.3" })
- installer.run_installer(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
- "lua-cjson",
- "1.2.3",
- }
- end)
- )
-
- it(
- "should provide --dev flag",
- async_test(function()
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle)
- installer.run_installer(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",
- "lua-cjson",
- 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/core/managers/npm_spec.lua b/tests/core/managers/npm_spec.lua
deleted file mode 100644
index a2170a63..00000000
--- a/tests/core/managers/npm_spec.lua
+++ /dev/null
@@ -1,194 +0,0 @@
-local spy = require "luassert.spy"
-local match = require "luassert.match"
-local mock = require "luassert.mock"
-local installer = require "mason.core.installer"
-local npm = require "mason.core.managers.npm"
-local Result = require "mason.core.result"
-local spawn = require "mason.core.spawn"
-local path = require "mason.core.path"
-
-describe("npm manager", function()
- it(
- "should call npm install",
- async_test(function()
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
- installer.run_installer(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.run_installer(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, { requested_version = "42.13.37" })
- ctx.fs.append_file = spy.new(mockx.just_runs())
- installer.run_installer(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, { requested_version = "42.13.37" })
- installer.run_installer(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()
- spawn.npm = spy.new(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())
-
- spawn.npm = nil
- end)
- )
-
- it(
- "should return outdated primary package",
- async_test(function()
- spawn.npm = spy.new(function()
- -- npm outdated returns with exit code 1 if outdated packages are found!
- return Result.failure {
- exit_code = 1,
- stdout = [[
- {
- "bash-language-server": {
- "current": "1.17.0",
- "wanted": "1.17.0",
- "latest": "2.0.0",
- "dependent": "bash",
- "location": "/tmp/install/dir"
- }
- }
- ]],
- }
- 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.spy(spawn.npm).was_called(1)
- assert.spy(spawn.npm).was_called_with {
- "outdated",
- "--json",
- "bash-language-server",
- cwd = 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())
-
- spawn.npm = nil
- end)
- )
-
- it(
- "should return failure if primary package is not outdated",
- async_test(function()
- spawn.npm = spy.new(function()
- return Result.success {
- stdout = "{}",
- }
- 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_failure())
- assert.equals("Primary package is not outdated.", result:err_or_nil())
- spawn.npm = nil
- end)
- )
-end)
diff --git a/tests/core/managers/opam_spec.lua b/tests/core/managers/opam_spec.lua
deleted file mode 100644
index 1a279fde..00000000
--- a/tests/core/managers/opam_spec.lua
+++ /dev/null
@@ -1,51 +0,0 @@
-local match = require "luassert.match"
-local mock = require "luassert.mock"
-local Optional = require "mason.core.optional"
-local installer = require "mason.core.installer"
-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, { requested_version = "42.13.37" })
- installer.run_installer(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, { requested_version = "42.13.37" })
- installer.run_installer(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/core/managers/pip3_spec.lua b/tests/core/managers/pip3_spec.lua
deleted file mode 100644
index 17489fe9..00000000
--- a/tests/core/managers/pip3_spec.lua
+++ /dev/null
@@ -1,242 +0,0 @@
-local mock = require "luassert.mock"
-local spy = require "luassert.spy"
-local path = require "mason.core.path"
-
-local pip3 = require "mason.core.managers.pip3"
-local Optional = require "mason.core.optional"
-local installer = require "mason.core.installer"
-local Result = require "mason.core.result"
-local settings = require "mason.settings"
-local spawn = require "mason.core.spawn"
-
-describe("pip3 manager", function()
- it("normalizes pip3 packages", function()
- local normalize = pip3.normalize_package
- assert.equal("python-lsp-server", normalize "python-lsp-server[all]")
- assert.equal("python-lsp-server", normalize "python-lsp-server[]")
- assert.equal("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, { requested_version = "42.13.37" })
- installer.run_installer(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()
- vim.g.python3_host_prog = "/my/python3"
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle)
- ctx.spawn.python3 = spy.new(mockx.throws())
- ctx.spawn.python = spy.new(mockx.throws())
- ctx.spawn[vim.g.python3_host_prog] = spy.new(mockx.throws())
- local err = assert.has_error(function()
- installer.run_installer(ctx, pip3.packages { "package" })
- end)
- vim.g.python3_host_prog = nil
-
- assert.equals("Unable to create python3 venv environment.", err)
- assert.spy(ctx.spawn["/my/python3"]).was_called(1)
- assert.spy(ctx.spawn.python3).was_called(1)
- assert.spy(ctx.spawn.python).was_called(1)
- end)
- )
-
- it(
- "should not exhaust python3 executable if one succeeds",
- async_test(function()
- vim.g.python3_host_prog = "/my/python3"
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle)
- ctx.spawn.python3 = spy.new(mockx.throws())
- ctx.spawn.python = spy.new(mockx.returns {})
- ctx.spawn[vim.g.python3_host_prog] = spy.new(mockx.returns {})
-
- installer.run_installer(ctx, pip3.packages { "package" })
- vim.g.python3_host_prog = nil
- assert.spy(ctx.spawn.python3).was_called(0)
- assert.spy(ctx.spawn.python).was_called(1)
- assert.spy(ctx.spawn["/my/python3"]).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.run_installer(ctx, pip3.packages { "package" })
- 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 provide receipt information",
- async_test(function()
- local handle = InstallHandleGenerator "dummy"
- local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
- installer.run_installer(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()
- spawn.python = spy.new(function()
- return 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"}]
- ]],
- }
- end)
-
- 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())
-
- spawn.python = nil
- end)
- )
-
- it(
- "should return outdated primary package",
- async_test(function()
- spawn.python = spy.new(function()
- return Result.success {
- stdout = [[
-[{"name": "astroid", "version": "2.9.3", "latest_version": "2.11.0", "latest_filetype": "wheel"}, {"name": "mccabe", "version": "0.6.1", "latest_version": "0.7.0", "latest_filetype": "wheel"}, {"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"}]
- ]],
- }
- end)
-
- local result = pip3.check_outdated_primary_package(
- 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",
- "--outdated",
- "--format=json",
- cwd = path.package_prefix "dummy",
- with_paths = { path.concat { path.package_prefix "dummy", "venv", "bin" } },
- }
- 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())
-
- spawn.python = nil
- end)
- )
-
- it(
- "should return failure if primary package is not outdated",
- async_test(function()
- spawn.python = spy.new(function()
- return Result.success {
- stdout = "[]",
- }
- end)
-
- 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())
- spawn.python = nil
- end)
- )
-end)