aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-10-13 21:14:29 +0200
committerWilliam Boman <william@redwill.se>2025-02-19 09:23:19 +0100
commitae208dc380808ff1aef39929a0e897e881571d43 (patch)
treeb9044cec7223062db69998189c76f8163ac9d58b /tests
parentfix(location): use correct registry path (diff)
downloadmason-ae208dc380808ff1aef39929a0e897e881571d43.tar
mason-ae208dc380808ff1aef39929a0e897e881571d43.tar.gz
mason-ae208dc380808ff1aef39929a0e897e881571d43.tar.bz2
mason-ae208dc380808ff1aef39929a0e897e881571d43.tar.lz
mason-ae208dc380808ff1aef39929a0e897e881571d43.tar.xz
mason-ae208dc380808ff1aef39929a0e897e881571d43.tar.zst
mason-ae208dc380808ff1aef39929a0e897e881571d43.zip
refactor: standardize constructors and improve inheritance construction
Diffstat (limited to 'tests')
-rw-r--r--tests/helpers/lua/dummy-registry/dummy2_package.lua2
-rw-r--r--tests/helpers/lua/dummy-registry/dummy_package.lua2
-rw-r--r--tests/helpers/lua/dummy-registry/registry_package.lua2
-rw-r--r--tests/mason-core/async/async_spec.lua18
-rw-r--r--tests/mason-core/installer/handle_spec.lua10
-rw-r--r--tests/mason-core/installer/runner_spec.lua56
-rw-r--r--tests/mason-core/package/package_spec.lua12
-rw-r--r--tests/mason-core/receipt_spec.lua12
-rw-r--r--tests/mason-registry/sources/lua_spec.lua10
9 files changed, 62 insertions, 62 deletions
diff --git a/tests/helpers/lua/dummy-registry/dummy2_package.lua b/tests/helpers/lua/dummy-registry/dummy2_package.lua
index 793404ea..008d27b2 100644
--- a/tests/helpers/lua/dummy-registry/dummy2_package.lua
+++ b/tests/helpers/lua/dummy-registry/dummy2_package.lua
@@ -1,6 +1,6 @@
local Pkg = require "mason-core.package"
-return Pkg.new {
+return Pkg:new {
schema = "registry+v1",
name = "dummy2",
description = [[This is a dummy2 package.]],
diff --git a/tests/helpers/lua/dummy-registry/dummy_package.lua b/tests/helpers/lua/dummy-registry/dummy_package.lua
index 52a709ad..4fbaf44d 100644
--- a/tests/helpers/lua/dummy-registry/dummy_package.lua
+++ b/tests/helpers/lua/dummy-registry/dummy_package.lua
@@ -1,6 +1,6 @@
local Pkg = require "mason-core.package"
-return Pkg.new {
+return Pkg:new {
schema = "registry+v1",
name = "dummy",
description = [[This is a dummy package.]],
diff --git a/tests/helpers/lua/dummy-registry/registry_package.lua b/tests/helpers/lua/dummy-registry/registry_package.lua
index e72284a8..7e5d9fbd 100644
--- a/tests/helpers/lua/dummy-registry/registry_package.lua
+++ b/tests/helpers/lua/dummy-registry/registry_package.lua
@@ -1,6 +1,6 @@
local Pkg = require "mason-core.package"
-return Pkg.new {
+return Pkg:new {
schema = "registry+v1",
name = "registry",
description = [[This is a dummy package.]],
diff --git a/tests/mason-core/async/async_spec.lua b/tests/mason-core/async/async_spec.lua
index a4197b85..79f74462 100644
--- a/tests/mason-core/async/async_spec.lua
+++ b/tests/mason-core/async/async_spec.lua
@@ -188,7 +188,7 @@ describe("async :: Condvar", function()
local Condvar = control.Condvar
it("should block execution until condvar is notified", function()
- local condvar = Condvar.new()
+ local condvar = Condvar:new()
local function wait()
local start = timestamp()
@@ -222,7 +222,7 @@ describe("async :: Semaphore", function()
local Semaphore = control.Semaphore
it("should limit the amount of permits", function()
- local sem = Semaphore.new(5)
+ local sem = Semaphore:new(5)
---@type Permit[]
local permits = {}
@@ -237,7 +237,7 @@ describe("async :: Semaphore", function()
end)
it("should lease new permits", function()
- local sem = Semaphore.new(2)
+ local sem = Semaphore:new(2)
---@type Permit[]
local permits = {}
@@ -259,7 +259,7 @@ describe("async :: OneShotChannel", function()
local OneShotChannel = control.OneShotChannel
it("should only allow sending once", function()
- local channel = OneShotChannel.new()
+ local channel = OneShotChannel:new()
assert.is_false(channel:is_closed())
channel:send "value"
assert.is_true(channel:is_closed())
@@ -270,7 +270,7 @@ describe("async :: OneShotChannel", function()
end)
it("should wait until it can receive", function()
- local channel = OneShotChannel.new()
+ local channel = OneShotChannel:new()
local start = timestamp()
local value = a.run_blocking(function()
@@ -286,7 +286,7 @@ describe("async :: OneShotChannel", function()
end)
it("should receive immediately if value is already sent", function()
- local channel = OneShotChannel.new()
+ local channel = OneShotChannel:new()
channel:send(42)
assert.equals(42, channel:receive())
end)
@@ -296,7 +296,7 @@ describe("async :: Channel", function()
local Channel = control.Channel
it("should suspend send until buffer is received", function()
- local channel = Channel.new()
+ local channel = Channel:new()
spy.on(channel, "send")
local guard = spy.new()
@@ -312,7 +312,7 @@ describe("async :: Channel", function()
end)
it("should send subsequent messages after they're received", function()
- local channel = Channel.new()
+ local channel = Channel:new()
spy.on(channel, "send")
a.run(function()
@@ -329,7 +329,7 @@ describe("async :: Channel", function()
end)
it("should suspend receive until message is sent", function()
- local channel = Channel.new()
+ local channel = Channel:new()
a.run(function()
a.sleep(100)
diff --git a/tests/mason-core/installer/handle_spec.lua b/tests/mason-core/installer/handle_spec.lua
index 66a9a5c4..780b1cc7 100644
--- a/tests/mason-core/installer/handle_spec.lua
+++ b/tests/mason-core/installer/handle_spec.lua
@@ -15,7 +15,7 @@ describe("installer handle", function()
end)
it("should register spawn handle", function()
- local handle = InstallHandle.new(mock.new {})
+ local handle = InstallHandle:new(mock.new {})
local spawn_handle_change_handler = spy.new()
local luv_handle = mock.new {}
@@ -32,7 +32,7 @@ describe("installer handle", function()
end)
it("should deregister spawn handle", function()
- local handle = InstallHandle.new(mock.new {})
+ local handle = InstallHandle:new(mock.new {})
local spawn_handle_change_handler = spy.new()
local luv_handle1 = mock.new {}
local luv_handle2 = mock.new {}
@@ -53,7 +53,7 @@ describe("installer handle", function()
end)
it("should change state", function()
- local handle = InstallHandle.new(mock.new {})
+ local handle = InstallHandle:new(mock.new {})
local state_change_handler = spy.new()
handle:once("state:change", state_change_handler)
@@ -68,7 +68,7 @@ describe("installer handle", function()
local process = require "mason-core.process"
stub(process, "kill")
local uv_handle = {}
- local handle = InstallHandle.new(mock.new {})
+ local handle = InstallHandle:new(mock.new {})
local kill_handler = spy.new()
handle:once("kill", kill_handler)
@@ -87,7 +87,7 @@ describe("installer handle", function()
stub(process, "kill")
local uv_handle1 = {}
local uv_handle2 = {}
- local handle = InstallHandle.new(mock.new {})
+ local handle = InstallHandle:new(mock.new {})
local kill_handler = spy.new()
local terminate_handler = spy.new()
local closed_handler = spy.new()
diff --git a/tests/mason-core/installer/runner_spec.lua b/tests/mason-core/installer/runner_spec.lua
index 69661842..f4acdcc1 100644
--- a/tests/mason-core/installer/runner_spec.lua
+++ b/tests/mason-core/installer/runner_spec.lua
@@ -30,11 +30,11 @@ describe("install runner ::", function()
describe("locking ::", function()
it("should respect semaphore locks", function()
- local semaphore = Semaphore.new(1)
+ local semaphore = Semaphore:new(1)
local location = InstallLocation.global()
- local dummy_handle = InstallHandle.new(dummy)
- local runner_1 = InstallRunner.new(location, dummy_handle, semaphore)
- local runner_2 = InstallRunner.new(location, InstallHandle.new(dummy2), semaphore)
+ local dummy_handle = InstallHandle:new(dummy)
+ local runner_1 = InstallRunner:new(location, dummy_handle, semaphore)
+ local runner_2 = InstallRunner:new(location, InstallHandle:new(dummy2), semaphore)
stub(dummy.spec.source, "install", function()
a.sleep(10000)
@@ -57,10 +57,10 @@ describe("install runner ::", function()
end)
it("should write lockfile", function()
- local semaphore = Semaphore.new(1)
+ local semaphore = Semaphore:new(1)
local location = InstallLocation.global()
- local dummy_handle = InstallHandle.new(dummy)
- local runner = InstallRunner.new(location, dummy_handle, semaphore)
+ local dummy_handle = InstallHandle:new(dummy)
+ local runner = InstallRunner:new(location, dummy_handle, semaphore)
spy.on(fs.async, "write_file")
@@ -72,10 +72,10 @@ describe("install runner ::", function()
end)
it("should abort installation if installation lock exists", function()
- local semaphore = Semaphore.new(1)
+ local semaphore = Semaphore:new(1)
local location = InstallLocation.global()
- local dummy_handle = InstallHandle.new(dummy)
- local runner = InstallRunner.new(location, dummy_handle, semaphore)
+ local dummy_handle = InstallHandle:new(dummy)
+ local runner = InstallRunner:new(location, dummy_handle, semaphore)
stub(fs.async, "file_exists")
stub(fs.async, "read_file")
@@ -95,10 +95,10 @@ describe("install runner ::", function()
end)
it("should not abort installation if installation lock exists with force=true", function()
- local semaphore = Semaphore.new(1)
+ local semaphore = Semaphore:new(1)
local location = InstallLocation.global()
- local dummy_handle = InstallHandle.new(dummy)
- local runner = InstallRunner.new(location, dummy_handle, semaphore)
+ local dummy_handle = InstallHandle:new(dummy)
+ local runner = InstallRunner:new(location, dummy_handle, semaphore)
stub(fs.async, "file_exists")
stub(fs.async, "read_file")
@@ -115,10 +115,10 @@ describe("install runner ::", function()
end)
it("should release lock after successful installation", function()
- local semaphore = Semaphore.new(1)
+ local semaphore = Semaphore:new(1)
local location = InstallLocation.global()
- local dummy_handle = InstallHandle.new(dummy)
- local runner = InstallRunner.new(location, dummy_handle, semaphore)
+ local dummy_handle = InstallHandle:new(dummy)
+ local runner = InstallRunner:new(location, dummy_handle, semaphore)
local callback = spy.new()
runner:execute({}, callback)
@@ -135,7 +135,7 @@ describe("install runner ::", function()
it("should initialize install location", function()
local location = InstallLocation.global()
- local runner = InstallRunner.new(location, InstallHandle.new(registry.get_package "dummy"), Semaphore.new(1))
+ local runner = InstallRunner:new(location, InstallHandle:new(registry.get_package "dummy"), Semaphore:new(1))
spy.on(location, "initialize")
@@ -150,7 +150,7 @@ describe("install runner ::", function()
it("should write receipt", function()
local location = InstallLocation.global()
local runner =
- InstallRunner.new(location, InstallHandle.new(registry.get_package "dummy"), Semaphore.new(1))
+ InstallRunner:new(location, InstallHandle:new(registry.get_package "dummy"), Semaphore:new(1))
runner:execute {}
@@ -185,8 +185,8 @@ describe("install runner ::", function()
dummy:once("install:failed", package_spy)
local location = InstallLocation.global()
- local handle = InstallHandle.new(registry.get_package "dummy")
- local runner = InstallRunner.new(location, handle, Semaphore.new(1))
+ local handle = InstallHandle:new(registry.get_package "dummy")
+ local runner = InstallRunner:new(location, handle, Semaphore:new(1))
stub(dummy.spec.source, "install", function()
error("I've made a mistake.", 0)
@@ -208,8 +208,8 @@ describe("install runner ::", function()
it("should terminate installation", function()
local location = InstallLocation.global()
- local handle = InstallHandle.new(registry.get_package "dummy")
- local runner = InstallRunner.new(location, handle, Semaphore.new(1))
+ local handle = InstallHandle:new(registry.get_package "dummy")
+ local runner = InstallRunner:new(location, handle, Semaphore:new(1))
local capture = spy.new()
stub(dummy.spec.source, "install", function()
@@ -233,8 +233,8 @@ describe("install runner ::", function()
it("should write debug logs when debug=true", function()
local location = InstallLocation.global()
- local handle = InstallHandle.new(registry.get_package "dummy")
- local runner = InstallRunner.new(location, handle, Semaphore.new(1))
+ local handle = InstallHandle:new(registry.get_package "dummy")
+ local runner = InstallRunner:new(location, handle, Semaphore:new(1))
stub(dummy.spec.source, "install", function(ctx)
ctx.stdio_sink.stdout "Hello "
@@ -254,8 +254,8 @@ describe("install runner ::", function()
it("should not retain installation directory on failure", function()
local location = InstallLocation.global()
- local handle = InstallHandle.new(registry.get_package "dummy")
- local runner = InstallRunner.new(location, handle, Semaphore.new(1))
+ local handle = InstallHandle:new(registry.get_package "dummy")
+ local runner = InstallRunner:new(location, handle, Semaphore:new(1))
stub(dummy.spec.source, "install", function(ctx)
ctx.stdio_sink.stderr "Something will go terribly wrong.\n"
@@ -275,8 +275,8 @@ describe("install runner ::", function()
it("should retain installation directory on failure and debug=true", function()
local location = InstallLocation.global()
- local handle = InstallHandle.new(registry.get_package "dummy")
- local runner = InstallRunner.new(location, handle, Semaphore.new(1))
+ local handle = InstallHandle:new(registry.get_package "dummy")
+ local runner = InstallRunner:new(location, handle, Semaphore:new(1))
stub(dummy.spec.source, "install", function(ctx)
ctx.stdio_sink.stderr "Something will go terribly wrong.\n"
diff --git a/tests/mason-core/package/package_spec.lua b/tests/mason-core/package/package_spec.lua
index 622a2ee4..b9b15d04 100644
--- a/tests/mason-core/package/package_spec.lua
+++ b/tests/mason-core/package/package_spec.lua
@@ -55,35 +55,35 @@ describe("package", function()
assert.equals(
"name: expected string, got number",
assert.has_error(function()
- Pkg.new(spec { name = 23 })
+ Pkg:new(spec { name = 23 })
end)
)
assert.equals(
"description: expected string, got number",
assert.has_error(function()
- Pkg.new(spec { description = 23 })
+ Pkg:new(spec { description = 23 })
end)
)
assert.equals(
"homepage: expected string, got number",
assert.has_error(function()
- Pkg.new(spec { homepage = 23 })
+ Pkg:new(spec { homepage = 23 })
end)
)
assert.equals(
"categories: expected table, got number",
assert.has_error(function()
- Pkg.new(spec { categories = 23 })
+ Pkg:new(spec { categories = 23 })
end)
)
assert.equals(
"languages: expected table, got number",
assert.has_error(function()
- Pkg.new(spec { languages = 23 })
+ Pkg:new(spec { languages = 23 })
end)
)
end)
@@ -211,7 +211,7 @@ describe("package", function()
assert.is_true(vim.in_fast_event())
local pkg = assert.is_not.has_error(function()
- return Pkg.new(dummy.spec)
+ return Pkg:new(dummy.spec)
end)
assert.same(dummy.spec, pkg.spec)
end)
diff --git a/tests/mason-core/receipt_spec.lua b/tests/mason-core/receipt_spec.lua
index 05ce1439..e7fcd648 100644
--- a/tests/mason-core/receipt_spec.lua
+++ b/tests/mason-core/receipt_spec.lua
@@ -7,7 +7,7 @@ end
describe("receipt ::", function()
it("should parse 1.0 structures", function()
- local receipt = InstallReceipt.new(fixture "1.0.json")
+ local receipt = InstallReceipt:new(fixture "1.0.json")
assert.equals("angular-language-server", receipt:get_name())
assert.equals("1.0", receipt:get_schema_version())
@@ -21,7 +21,7 @@ describe("receipt ::", function()
end)
it("should parse 1.1 structures", function()
- local receipt = InstallReceipt.new(fixture "1.1.json")
+ local receipt = InstallReceipt:new(fixture "1.1.json")
assert.equals("angular-language-server", receipt:get_name())
assert.equals("1.1", receipt:get_schema_version())
@@ -46,7 +46,7 @@ describe("receipt ::", function()
end)
it("should parse 1.2 structures", function()
- local receipt = InstallReceipt.new(fixture "1.2.json")
+ local receipt = InstallReceipt:new(fixture "1.2.json")
assert.equals("angular-language-server", receipt:get_name())
assert.equals("1.2", receipt:get_schema_version())
@@ -66,9 +66,9 @@ describe("receipt ::", function()
describe("schema versions ::", function()
it("should check minimum compatibility", function()
- local receipt_1_0 = InstallReceipt.new { schema_version = "1.0" }
- local receipt_1_1 = InstallReceipt.new { schema_version = "1.1" }
- local receipt_1_2 = InstallReceipt.new { schema_version = "1.2" }
+ local receipt_1_0 = InstallReceipt:new { schema_version = "1.0" }
+ local receipt_1_1 = InstallReceipt:new { schema_version = "1.1" }
+ local receipt_1_2 = InstallReceipt:new { schema_version = "1.2" }
assert.is_true(receipt_1_0:is_schema_min "1.0")
assert.is_true(receipt_1_1:is_schema_min "1.0")
diff --git a/tests/mason-registry/sources/lua_spec.lua b/tests/mason-registry/sources/lua_spec.lua
index 27a351d7..c720ae10 100644
--- a/tests/mason-registry/sources/lua_spec.lua
+++ b/tests/mason-registry/sources/lua_spec.lua
@@ -6,7 +6,7 @@ describe("Lua registry source", function()
["my-pkg"] = "pkg-index.my-pkg",
}
package.loaded["pkg-index.my-pkg"] = {}
- local source = LuaRegistrySource.new {
+ local source = LuaRegistrySource:new {
mod = "pkg-index",
}
assert.is_not_nil(source:get_package "my-pkg")
@@ -19,7 +19,7 @@ describe("Lua registry source", function()
["rust-analyzer"] = "pkg-index.rust-analyzer",
["typescript-language-server"] = "pkg-index.typescript-language-server",
}
- local source = LuaRegistrySource.new {
+ local source = LuaRegistrySource:new {
mod = "pkg-index",
}
local package_names = source:get_all_package_names()
@@ -33,10 +33,10 @@ describe("Lua registry source", function()
it("should check if is installed", function()
package.loaded["pkg-index"] = {}
- local installed_source = LuaRegistrySource.new {
+ local installed_source = LuaRegistrySource:new {
mod = "pkg-index",
}
- local uninstalled_source = LuaRegistrySource.new {
+ local uninstalled_source = LuaRegistrySource:new {
mod = "non-existent",
}
@@ -45,6 +45,6 @@ describe("Lua registry source", function()
end)
it("should stringify instances", function()
- assert.equals("LuaRegistrySource(mod=pkg-index)", tostring(LuaRegistrySource.new { mod = "pkg-index" }))
+ assert.equals("LuaRegistrySource(mod=pkg-index)", tostring(LuaRegistrySource:new { mod = "pkg-index" }))
end)
end)