Skip to content

Commit 5a3f6f3

Browse files
committed
fix: ensure elixir-tool.nvim cache dir exists
1 parent 896686e commit 5a3f6f3

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

lua/elixir/utils.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ function M.latest_release(owner, repo, opts)
4444
)
4545
local invocation = vim.fn.system(curl)
4646

47+
vim.fn.mkdir(vim.fn.expand(cache_dir), "p")
48+
4749
local latest_version_file = Path:new(vim.fn.expand(cache_dir .. owner .. "-" .. repo .. ".txt")):absolute()
4850

4951
if vim.v.shell_error == 0 then

tests/utils_spec.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ describe("utils", function()
3838
end)
3939

4040
describe("latest_release", function()
41+
before_each(function()
42+
vim.fn.delete("./tmp/version-cache", "rf")
43+
end)
44+
4145
it("returns the latest release for the repo", function()
42-
local result = utils.latest_release("elixir-tools", "next-ls", { cache_dir = "./tmp/" })
46+
local result = utils.latest_release("elixir-tools", "next-ls", { cache_dir = "./tmp/version-cache/" })
4347

4448
assert(type(result) == "string")
4549
assert.is.Truthy(string.match(result, "%d+%.%d+%.%d+"))
@@ -50,18 +54,19 @@ describe("utils", function()
5054
local result = utils.latest_release(
5155
"elixir-tools",
5256
"next-ls",
53-
{ github_host = "localhost:9999", cache_dir = "./tmp/" }
57+
{ github_host = "localhost:9999", cache_dir = "./tmp/version-cache/" }
5458
)
5559

5660
assert.is.Nil(result)
5761
end)
5862

5963
it("returns nil if the command has a non zero exit code and no file in cache", function()
60-
vim.fn.writefile({ "0.2.2" }, "./tmp/elixir-tools-next-ls.txt")
64+
vim.fn.mkdir("./tmp/version-cache", "p")
65+
vim.fn.writefile({ "0.2.2" }, "./tmp/version-cache/elixir-tools-next-ls.txt")
6166
local result = utils.latest_release(
6267
"elixir-tools",
6368
"next-ls",
64-
{ github_host = "localhost:9999", cache_dir = "./tmp/" }
69+
{ github_host = "localhost:9999", cache_dir = "./tmp/version-cache/" }
6570
)
6671

6772
assert.are.same(result, "0.2.2")

0 commit comments

Comments
 (0)