aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-11-02 18:42:11 +0100
committerGitHub <noreply@github.com>2022-11-02 18:42:11 +0100
commit1ec0dd2fff4b14efb808049822a7cfedba3145c9 (patch)
tree5735873acfc5697e35ee442fbba8a91551d0f8f8
parentfix(provider): use correct name for github (#620) (diff)
downloadmason-1ec0dd2fff4b14efb808049822a7cfedba3145c9.tar
mason-1ec0dd2fff4b14efb808049822a7cfedba3145c9.tar.gz
mason-1ec0dd2fff4b14efb808049822a7cfedba3145c9.tar.bz2
mason-1ec0dd2fff4b14efb808049822a7cfedba3145c9.tar.lz
mason-1ec0dd2fff4b14efb808049822a7cfedba3145c9.tar.xz
mason-1ec0dd2fff4b14efb808049822a7cfedba3145c9.tar.zst
mason-1ec0dd2fff4b14efb808049822a7cfedba3145c9.zip
test: use stubs and dedent (#621)
-rw-r--r--tests/mason-core/managers/cargo_spec.lua99
-rw-r--r--tests/mason-core/managers/composer_spec.lua71
-rw-r--r--tests/mason-core/managers/gem_spec.lua66
-rw-r--r--tests/mason-core/managers/git_spec.lua43
-rw-r--r--tests/mason-core/managers/go_spec.lua9
-rw-r--r--tests/mason-core/managers/pip3_spec.lua60
6 files changed, 166 insertions, 182 deletions
diff --git a/tests/mason-core/managers/cargo_spec.lua b/tests/mason-core/managers/cargo_spec.lua
index 27de7253..9b62fccd 100644
--- a/tests/mason-core/managers/cargo_spec.lua
+++ b/tests/mason-core/managers/cargo_spec.lua
@@ -10,6 +10,7 @@ local github_client = require "mason-core.managers.github.client"
local Result = require "mason-core.result"
local spawn = require "mason-core.spawn"
local path = require "mason-core.path"
+local _ = require "mason-core.functional"
describe("cargo manager", function()
it(
@@ -157,36 +158,37 @@ describe("cargo version check", function()
["stylua"] = { name = "stylua", version = "0.11.2" },
["zoxide"] = { name = "zoxide", version = "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
-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
-]]
+ 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()
- spawn.cargo = spy.new(function()
- return Result.success {
- stdout = [[flux-lsp v0.8.8 (https://github.com/influxdata/flux-lsp#4e452f07):
- flux-lsp
-]],
- }
- end)
+ 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 {
@@ -208,21 +210,19 @@ zoxide v0.5.0:
})
assert.is_true(result:is_success())
assert.equals("4e452f07", result:get_or_nil())
-
- spawn.cargo = nil
end)
)
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)
+ 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 = {
@@ -257,21 +257,19 @@ zoxide v0.5.0:
latest_version = "0.4.2",
name = "lelwel",
}(result:get_or_nil()))
-
- spawn.cargo = nil
end)
)
it(
"should recognize up-to-date crates",
async_test(function()
- spawn.cargo = spy.new(function()
- return Result.success {
- stdout = [[lelwel v0.4.0:
- lelwel-ls
-]],
- }
- end)
+ 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 = {
@@ -294,20 +292,19 @@ zoxide v0.5.0:
assert.is_true(result:is_failure())
assert.equals("Primary package is not outdated.", result:err_or_nil())
- spawn.cargo = nil
end)
)
it(
"should return outdated primary package from git source",
async_test(function()
- spawn.cargo = spy.new(function()
- return Result.success {
- stdout = [[move-analyzer v1.0.0 (https://github.com/move-language/move#3cef7fa8):
- move-analyzer
-]],
- }
- end)
+ 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
@@ -342,8 +339,6 @@ zoxide v0.5.0:
latest_version = "b243f1fb",
name = "move-analyzer",
}(result:get_or_nil()))
-
- spawn.cargo = nil
end)
)
end)
diff --git a/tests/mason-core/managers/composer_spec.lua b/tests/mason-core/managers/composer_spec.lua
index d4d07934..fe961a4f 100644
--- a/tests/mason-core/managers/composer_spec.lua
+++ b/tests/mason-core/managers/composer_spec.lua
@@ -1,4 +1,5 @@
local spy = require "luassert.spy"
+local stub = require "luassert.stub"
local mock = require "luassert.mock"
local installer = require "mason-core.installer"
local composer = require "mason-core.managers.composer"
@@ -65,18 +66,17 @@ 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)
+ 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 {
@@ -97,31 +97,28 @@ describe("composer version check", function()
}
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)
+ 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 {
@@ -146,19 +143,16 @@ describe("composer version check", function()
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)
+ stub(spawn, "composer")
+ spawn.composer.returns(Result.success {
+ stdout = [[{"installed": []}]],
+ })
local result = composer.check_outdated_primary_package(
mock.new {
@@ -172,7 +166,6 @@ describe("composer version check", function()
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/mason-core/managers/gem_spec.lua b/tests/mason-core/managers/gem_spec.lua
index f99666e6..5f74c62d 100644
--- a/tests/mason-core/managers/gem_spec.lua
+++ b/tests/mason-core/managers/gem_spec.lua
@@ -7,6 +7,7 @@ local gem = require "mason-core.managers.gem"
local Result = require "mason-core.result"
local spawn = require "mason-core.spawn"
local api = require "mason-registry.api"
+local _ = require "mason-core.functional"
describe("gem manager", function()
it(
@@ -59,16 +60,16 @@ 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)
+ 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 {
@@ -92,24 +93,22 @@ strscan (default: 3.0.1)
})
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 = [[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)
+ 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",
@@ -132,24 +131,22 @@ strscan (default: 3.0.1)
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 = [[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)
+ 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",
@@ -168,7 +165,6 @@ strscan (default: 3.0.1)
assert.is_true(result:is_failure())
assert.equals("Primary package is not outdated.", result:err_or_nil())
- spawn.gem = nil
end)
)
diff --git a/tests/mason-core/managers/git_spec.lua b/tests/mason-core/managers/git_spec.lua
index bf3bee30..6ea72eee 100644
--- a/tests/mason-core/managers/git_spec.lua
+++ b/tests/mason-core/managers/git_spec.lua
@@ -1,8 +1,9 @@
-local spy = require "luassert.spy"
+local stub = require "luassert.stub"
local mock = require "luassert.mock"
local spawn = require "mason-core.spawn"
local Result = require "mason-core.result"
local installer = require "mason-core.installer"
+local _ = require "mason-core.functional"
local git = require "mason-core.managers.git"
@@ -91,11 +92,10 @@ describe("git version check", function()
it(
"should return current version",
async_test(function()
- spawn.git = spy.new(function()
- return Result.success {
- stdout = [[19c668c]],
- }
- end)
+ stub(spawn, "git")
+ spawn.git.returns(Result.success {
+ stdout = [[19c668c]],
+ })
local result = git.get_installed_revision({ type = "git" }, "/tmp/install/dir")
@@ -103,20 +103,19 @@ describe("git version check", function()
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)
+ stub(spawn, "git")
+ spawn.git.returns(Result.success {
+ stdout = _.dedent [[
+ 728307a74cd5f2dec7ca2ca164785c25673d6328
+ 19c668cd10695b243b09452f0dfd53570c1a2e7d
+ ]],
+ })
local result = git.check_outdated_git_clone(
mock.new {
@@ -147,20 +146,19 @@ describe("git version check", function()
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)
+ stub(spawn, "git")
+ spawn.git.returns(Result.success {
+ stdout = _.dedent [[
+ 19c668cd10695b243b09452f0dfd53570c1a2e7d
+ 19c668cd10695b243b09452f0dfd53570c1a2e7d
+ ]],
+ })
local result = git.check_outdated_git_clone(
mock.new {
@@ -174,7 +172,6 @@ describe("git version check", function()
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/mason-core/managers/go_spec.lua b/tests/mason-core/managers/go_spec.lua
index e841c1f3..79cd3014 100644
--- a/tests/mason-core/managers/go_spec.lua
+++ b/tests/mason-core/managers/go_spec.lua
@@ -84,9 +84,8 @@ gopls: go1.18
it(
"should return current version",
async_test(function()
- spawn.go = spy.new(function()
- return Result.success { stdout = go_version_output }
- end)
+ stub(spawn, "go")
+ spawn.go.returns(Result.success { stdout = go_version_output })
local result = go.get_installed_primary_package_version(
mock.new {
@@ -107,8 +106,6 @@ gopls: go1.18
}
assert.is_true(result:is_success())
assert.equals("v0.8.1", result:get_or_nil())
-
- spawn.go = nil
end)
)
@@ -159,8 +156,6 @@ gopls: go1.18
current_version = "v0.8.1",
latest_version = "v2.0.0",
}, result:get_or_nil())
-
- spawn.go = nil
end)
)
diff --git a/tests/mason-core/managers/pip3_spec.lua b/tests/mason-core/managers/pip3_spec.lua
index 1ec2dc28..ffba9b04 100644
--- a/tests/mason-core/managers/pip3_spec.lua
+++ b/tests/mason-core/managers/pip3_spec.lua
@@ -3,6 +3,7 @@ local spy = require "luassert.spy"
local stub = require "luassert.stub"
local path = require "mason-core.path"
+local _ = require "mason-core.functional"
local a = require "mason-core.async"
local pip3 = require "mason-core.managers.pip3"
local installer = require "mason-core.installer"
@@ -157,13 +158,17 @@ 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)
+ 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 {
@@ -186,8 +191,6 @@ describe("pip3 version check", function()
}
assert.is_true(result:is_success())
assert.equals("1.3.0", result:get_or_nil())
-
- spawn.python = nil
end)
)
@@ -199,13 +202,17 @@ describe("pip3 version check", function()
name = "python-lsp-server",
version = "1.4.0",
})
- 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)
+ 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 {
@@ -223,21 +230,23 @@ describe("pip3 version check", function()
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 = [[
- [{"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)
+ 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",
@@ -256,7 +265,6 @@ describe("pip3 version check", function()
assert.is_true(result:is_failure())
assert.equals("Primary package is not outdated.", result:err_or_nil())
- spawn.python = nil
end)
)
end)