Repository navigation
Expand file tree
/
Copy pathloader_resolution_spec.lua
More file actions
102 lines (86 loc) · 3.35 KB
/
Copy pathloader_resolution_spec.lua
File metadata and controls
102 lines (86 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
local state = require("pack.state")
local loader = require("pack.loader")
local persist = require("pack.persist")
-- Create a real, packadd-able plugin under a fresh packpath entry so
-- loader.load() -> packadd actually sources something. The sourced file bumps
-- _G.PACK_TEST_LOADED[name] so a test can assert whether (and how often) the
-- plugin was loaded.
local function fake_plugin(name)
local root = vim.fn.tempname()
local pdir = root .. "/pack/pht/opt/" .. name
vim.fn.mkdir(pdir .. "/plugin", "p")
vim.fn.writefile({
"_G.PACK_TEST_LOADED = _G.PACK_TEST_LOADED or {}",
('_G.PACK_TEST_LOADED[%q] = (_G.PACK_TEST_LOADED[%q] or 0) + 1'):format(name, name),
}, pdir .. "/plugin/init.lua")
vim.opt.packpath:prepend(root)
return pdir
end
local function config_with(plugins)
return { plugins = plugins }
end
describe("pack.loader load-path hardening", function()
local tmp_path
before_each(function()
tmp_path = vim.fn.tempname() .. "-pack-extra.json"
persist._set_path_for_testing(tmp_path)
_G.PACK_TEST_LOADED = {}
end)
after_each(function()
if vim.fn.filereadable(tmp_path) == 1 then
vim.fn.delete(tmp_path)
end
persist._set_path_for_testing(nil)
_G.PACK_TEST_LOADED = nil
end)
it("terminates (no stack overflow) on a circular dependency and loads both", function()
fake_plugin("a")
fake_plugin("b")
-- Nest the deps so the back-edge (b -> a) actually registers; two flat
-- top-level specs would dedup and drop the cycle.
state.init(config_with({
{ "u/a", dependencies = { { "u/b", dependencies = { "u/a" } } } },
}))
local ok = pcall(loader.load, "a")
assert.is_true(ok, "circular dependency must not recurse forever")
assert.equals(1, _G.PACK_TEST_LOADED["a"])
assert.equals(1, _G.PACK_TEST_LOADED["b"])
end)
it("loads a native-style dependency keyed by name (not URL basename)", function()
fake_plugin("customdep")
state.init(config_with({
{
"u/parent",
dependencies = { { src = "https://github.com/u/realrepo", name = "customdep" } },
},
}))
fake_plugin("parent")
loader.load("parent")
assert.equals(1, _G.PACK_TEST_LOADED["customdep"], "dependency resolved by name must load")
end)
it("does not load a disabled plugin via M.load", function()
fake_plugin("disabledone")
state.init(config_with({ "u/disabledone" }))
state.get_plugins()["disabledone"].disabled = true
loader.load("disabledone")
assert.is_nil(_G.PACK_TEST_LOADED["disabledone"])
assert.are_not.equal("loaded", state.get_plugins()["disabledone"].status)
end)
end)
describe("pack.state.derive_name", function()
it("derives from a bare owner/repo string", function()
assert.equals("repo.nvim", state.derive_name("owner/repo.nvim"))
end)
it("strips a trailing .git", function()
assert.equals("repo", state.derive_name("owner/repo.git"))
end)
it("honors an explicit name on a native-style spec", function()
assert.equals("custom", state.derive_name({ src = "https://x/y", name = "custom" }))
end)
it("honors an explicit name on a shorthand spec", function()
assert.equals("custom", state.derive_name({ "owner/repo", name = "custom" }))
end)
it("prefers `as` over name and basename", function()
assert.equals("aliased", state.derive_name({ "owner/repo", name = "custom", as = "aliased" }))
end)
end)