test: fix flaky tests

This commit is contained in:
Steven Arcangeli 2023-11-19 19:40:20 -08:00
parent af04969c43
commit 4df43ad5f5
5 changed files with 31 additions and 21 deletions

View file

@ -12,14 +12,10 @@ local FIELD_META = constants.FIELD_META
local M = {}
local function touch_dir(path)
uv.fs_mkdir(path, 448) -- 0700
end
local function ensure_trash_dir(path)
touch_dir(path)
touch_dir(fs.join(path, "info"))
touch_dir(fs.join(path, "files"))
local mode = 448 -- 0700
fs.mkdirp(fs.join(path, "info"), mode)
fs.mkdirp(fs.join(path, "files"), mode)
end
---Gets the location of the home trash dir, creating it if necessary

View file

@ -143,7 +143,10 @@ M.shorten_path = function(path, relative_to)
return relpath or path
end
M.mkdirp = function(dir)
---@param dir string
---@param mode? integer
M.mkdirp = function(dir, mode)
mode = mode or 493
local mod = ""
local path = dir
while vim.fn.isdirectory(path) == 0 do
@ -153,7 +156,7 @@ M.mkdirp = function(dir)
while mod ~= "" do
mod = mod:sub(3)
path = vim.fn.fnamemodify(dir, mod)
uv.fs_mkdir(path, 493)
uv.fs_mkdir(path, mode)
end
end

View file

@ -536,7 +536,9 @@ M.try_write_changes = function(confirm, cb)
view.unlock_buffers()
if err then
err = string.format("[oil] Error applying actions: %s", err)
view.rerender_all_oil_buffers()
view.rerender_all_oil_buffers(nil, function()
cb(err)
end)
else
local current_entry = oil.get_cursor_entry()
if current_entry then
@ -546,11 +548,15 @@ M.try_write_changes = function(confirm, cb)
vim.split(current_entry.parsed_name or current_entry.name, "/")[1]
)
end
view.rerender_all_oil_buffers()
vim.api.nvim_exec_autocmds("User", { pattern = "OilMutationComplete", modeline = false })
view.rerender_all_oil_buffers(nil, function(render_err)
vim.api.nvim_exec_autocmds(
"User",
{ pattern = "OilMutationComplete", modeline = false }
)
cb(render_err)
end)
end
mutation_in_progress = false
cb(err)
end)
)
end)

View file

@ -145,9 +145,10 @@ M.unlock_buffers = function()
end
---@param opts? table
---@param callback? fun(err: nil|string)
---@note
--- This DISCARDS ALL MODIFICATIONS a user has made to oil buffers
M.rerender_all_oil_buffers = function(opts)
M.rerender_all_oil_buffers = function(opts, callback)
opts = opts or {}
local buffers = M.get_all_buffers()
local hidden_buffers = {}
@ -159,13 +160,15 @@ M.rerender_all_oil_buffers = function(opts)
hidden_buffers[vim.api.nvim_win_get_buf(winid)] = nil
end
end
local cb = util.cb_collect(#buffers, callback or function() end)
for _, bufnr in ipairs(buffers) do
if hidden_buffers[bufnr] then
vim.b[bufnr].oil_dirty = opts
-- We also need to mark this as nomodified so it doesn't interfere with quitting vim
vim.bo[bufnr].modified = false
vim.schedule(cb)
else
M.render_buffer_async(bufnr, opts)
M.render_buffer_async(bufnr, opts, cb)
end
end
end