lazy.nvim/tests/manage/runner_spec.lua

84 lines
2.4 KiB
Lua
Raw Normal View History

2022-11-28 18:04:44 +08:00
local Runner = require("lazy.manage.runner")
describe("runner", function()
local plugins = { { name = "plugin1", _ = {} }, { name = "plugin2", _ = {} } }
2022-11-28 18:04:44 +08: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 18:04:44 +08: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 18:04:44 +08: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 18:04:44 +08:00
error("error" .. i)
end,
}
package.loaded["lazy.manage.task.test"]["async" .. i] = {
---@param task LazyTask
run = function(task)
task:schedule(function()
table.insert(runs, { plugin = task.plugin.name, task = task.name })
end)
end,
}
2022-11-28 18:04:44 +08: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 18:04:44 +08: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()
assert.equal(4, #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 18:04:44 +08: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 18:04:44 +08:00
assert.equal(4, #runs)
end)
end)