Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion spec/std/pluginloader_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe("PluginLoader", function()
after_each(function()
eaw_env.teardown_environment()
require_utilities.reset_require()
package.loaded["spec/test-plugins/ordered-dependencies/init"] = nil
end)

local function assert_loaded_plugin_stub(plugin)
Expand Down Expand Up @@ -48,6 +49,47 @@ describe("PluginLoader", function()
end)
end)

describe("When loading plugin arrays", function()
it("should load only array entries in order", function()
local loaded = {}
plugin_loader.load_plugin = function(self, plugin_name)
table.insert(loaded, plugin_name)
end

plugin_loader:load {
"first",
"second",
metadata = "not-a-plugin"
}

assert.are.same({"first", "second"}, loaded)
end)

it("should pass only dependency array entries in order", function()
local first = {name = "first"}
local second = {name = "second"}
plugin_loader.loaded_plugins.first = first
plugin_loader.loaded_plugins.second = second
plugin_loader.loaded_plugins["not-a-dependency"] = {name = "ignored"}

package.loaded["spec/test-plugins/ordered-dependencies/init"] = {
dependencies = {
"first",
"second",
metadata = "not-a-dependency"
},
init = function(self, ctx, ...)
return {dependencies = arg}
end
}

plugin_loader:load_plugin("ordered-dependencies", {})

assert.are.same({first, second, n = 2},
plugin_loader.loaded_plugins["ordered-dependencies"].dependencies)
end)
end)

describe("When loading plugin with dependency", function()
it("should pass dependency to dependent plugin", function()
plugin_loader:load {"plugin-with-dependency"}
Expand Down Expand Up @@ -81,4 +123,4 @@ describe("PluginLoader", function()
assert.has_error(cyclic_load)
end)
end)
end)
end)
6 changes: 4 additions & 2 deletions std/PluginLoader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function PluginLoader:load(plugin_list)
end
local unresolved_plugins = {}

for _, plugin_name in pairs(plugin_list) do
-- Plugin lists are ordered, so keep the order chosen by the author.
for _, plugin_name in ipairs(plugin_list) do
self:load_plugin(plugin_name, unresolved_plugins)
end

Expand Down Expand Up @@ -67,7 +68,8 @@ function PluginLoader:load_plugin(plugin_name, unresolved_plugins)

local loaded_dependencies = {}
if plugin_def.dependencies and table.getn(plugin_def.dependencies) > 0 then
for _, dependency in pairs(plugin_def.dependencies) do
-- This order also decides which dependency fills each argument.
for _, dependency in ipairs(plugin_def.dependencies) do
if not self.loaded_plugins[dependency] then
self:load_plugin(dependency, unresolved_plugins)
end
Expand Down