test: fix flaky tests
This commit is contained in:
parent
af04969c43
commit
4df43ad5f5
5 changed files with 31 additions and 21 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -20,17 +20,23 @@ end
|
|||
|
||||
a.describe("freedesktop", function()
|
||||
local tmpdir
|
||||
local tmphome
|
||||
local home = vim.env.XDG_DATA_HOME
|
||||
a.before_each(function()
|
||||
require("oil.config").delete_to_trash = true
|
||||
tmpdir = TmpDir.new()
|
||||
tmphome = TmpDir.new()
|
||||
package.loaded["oil.adapters.trash"] = require("oil.adapters.trash.freedesktop")
|
||||
local trash_dir = string.format(".Trash-%d", uv.getuid())
|
||||
tmpdir:create({ fs.join(trash_dir, "__dummy__") })
|
||||
vim.env.XDG_DATA_HOME = tmphome.path
|
||||
end)
|
||||
a.after_each(function()
|
||||
vim.env.XDG_DATA_HOME = home
|
||||
if tmpdir then
|
||||
tmpdir:dispose()
|
||||
end
|
||||
if tmphome then
|
||||
tmphome:dispose()
|
||||
end
|
||||
test_util.reset_editor()
|
||||
package.loaded["oil.adapters.trash"] = nil
|
||||
end)
|
||||
|
|
@ -140,12 +146,8 @@ a.describe("freedesktop", function()
|
|||
test_util.actions.save()
|
||||
test_util.actions.reload()
|
||||
assert.are.same({ "a.txt" }, parse_entries(0))
|
||||
local uid = uv.getuid()
|
||||
tmpdir:assert_fs({
|
||||
["a.txt"] = "a.txt",
|
||||
[".Trash-" .. uid .. "/__dummy__"] = ".Trash-" .. uid .. "/__dummy__",
|
||||
[".Trash-" .. uid .. "/files/"] = true,
|
||||
[".Trash-" .. uid .. "/info/"] = true,
|
||||
})
|
||||
end)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue