lazy.nvim/tests/manage/runner_spec.lua

85 lines
2.4 KiB
Lua
Raw Permalink Normal View History

2024-06-30 12:35:11 +01:00
local Async = require("lazy.async")
2022-11-28 10:04:44 +00:00
local Runner = require("lazy.manage.runner")
describe("runner", function()
local plugins = { { name = "plugin1", _ = {} }, { name = "plugin2", _ = {} } }
2022-11-28 10:04:44 +00:00
---@type {plugin:string, task:string}[]
local runs = {}
before_each(function()
runs = {}
end)
package.loaded["lazy.manage.task.test"] = {}
package.loaded["lazy.manage.task.test"]["skip"] = {
skip = function()
return true
end,
}
2022-11-28 10:04:44 +00:00
for i = 1, 10 do
package.loaded["lazy.manage.task.test"]["test" .. i] = {
---@param task LazyTask
run = function(task)
table.insert(runs, { plugin = task.plugin.name, task = task.name })
2022-11-28 10:04:44 +00:00
end,
}
package.loaded["lazy.manage.task.test"]["error" .. i] = {
---@param task LazyTask
run = function(task)
table.insert(runs, { plugin = task.plugin.name, task = task.name })
2022-11-28 10:04:44 +00:00
error("error" .. i)
end,
}
package.loaded["lazy.manage.task.test"]["async" .. i] = {
---@async
---@param task LazyTask
run = function(task)
2024-06-30 12:35:11 +01:00
Async.yield()
table.insert(runs, { plugin = task.plugin.name, task = task.name })
end,
}
2022-11-28 10:04:44 +00:00
end
it("runs the pipeline", function()
local runner = Runner.new({ plugins = plugins, pipeline = { "test.test1", "test.test2" } })
runner:start()
runner:wait()
assert.equal(4, #runs)
end)
it("waits", function()
local runner = Runner.new({ plugins = plugins, pipeline = { "test.test1", "wait", "test.test2" } })
runner:start()
runner:wait()
assert.equal(4, #runs)
end)
it("handles async", function()
local runner = Runner.new({ plugins = plugins, pipeline = { "test.async1", "wait", "test.async2" } })
runner:start()
runner:wait()
2022-11-28 10:04:44 +00:00
assert.equal(4, #runs)
end)
it("handles skips", function()
local runner = Runner.new({ plugins = plugins, pipeline = { "test.test1", "test.skip", "test.test2" } })
runner:start()
runner:wait()
2024-06-26 18:58:45 +01:00
assert.equal(4, #runs, runs)
end)
it("handles opts", function()
local runner = Runner.new({ plugins = plugins, pipeline = { "test.test1", { "test.test2", foo = "bar" } } })
runner:start()
runner:wait()
assert.equal(4, #runs)
end)
2022-11-28 10:04:44 +00:00
it("aborts on error", function()
local runner = Runner.new({ plugins = plugins, pipeline = { "test.test1", "test.error1", "test.test2" } })
runner:start()
runner:wait()
2022-11-28 10:04:44 +00:00
assert.equal(4, #runs)
end)
end)