canola.nvim/tests/files_spec.lua
Barrett Ruth 86f553cd0a
build: replace luacheck with selene, add nix devshell and pre-commit (#20)
* build: replace luacheck with selene

Problem: luacheck is unmaintained (last release 2018) and required
suppressing four warning classes to avoid false positives. It also
lacks first-class vim/neovim awareness.

Solution: switch to selene with std='vim' for vim-aware linting.
Replace the luacheck CI job with selene, update the Makefile lint
target, and delete .luacheckrc.

* build: add nix devshell and pre-commit hooks

Problem: oil.nvim had no reproducible dev environment. The .envrc
set up a Python venv for the now-removed docgen pipeline, and there
were no pre-commit hooks for local formatting checks.

Solution: add flake.nix with stylua, selene, and prettier in the
devshell. Replace the stale Python .envrc with 'use flake'. Add
.pre-commit-config.yaml with stylua and prettier hooks matching
other plugins in the repo collection.

* fix: format with stylua

* build(selene): configure lints and add inline suppressions

Problem: selene fails on 5 errors and 3 warnings from upstream code
patterns that are intentional (mixed tables in config API, unused
callback parameters, identical if branches for readability).

Solution: globally allow mixed_table and unused_variable (high volume,
inherent to the codebase design). Add inline selene:allow directives
for the 8 remaining issues: if_same_then_else (4), mismatched_arg_count
(1), empty_if (2), global_usage (1). Remove .envrc from tracking.

* build: switch typecheck action to mrcjkb/lua-typecheck-action

Problem: oil.nvim used stevearc/nvim-typecheck-action, which required
cloning the action repo locally for the Makefile lint target. All
other plugins in the collection use mrcjkb/lua-typecheck-action.

Solution: swap to mrcjkb/lua-typecheck-action@v0 for consistency.
Remove the nvim-typecheck-action git clone from the Makefile and
.gitignore. Drop LuaLS from the local lint target since it requires
a full language server install — CI handles it.
2026-02-21 23:52:27 -05:00

173 lines
5.1 KiB
Lua

require('plenary.async').tests.add_to_env()
local TmpDir = require('tests.tmpdir')
local files = require('oil.adapters.files')
local test_util = require('tests.test_util')
a.describe('files adapter', function()
local tmpdir
a.before_each(function()
tmpdir = TmpDir.new()
end)
a.after_each(function()
if tmpdir then
tmpdir:dispose()
end
test_util.reset_editor()
end)
a.it('tmpdir creates files and asserts they exist', function()
tmpdir:create({ 'a.txt', 'foo/b.txt', 'foo/c.txt', 'bar/' })
tmpdir:assert_fs({
['a.txt'] = 'a.txt',
['foo/b.txt'] = 'foo/b.txt',
['foo/c.txt'] = 'foo/c.txt',
['bar/'] = true,
})
end)
a.it('Creates files', function()
local err = a.wrap(files.perform_action, 2)({
url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a.txt',
entry_type = 'file',
type = 'create',
})
assert.is_nil(err)
tmpdir:assert_fs({
['a.txt'] = '',
})
end)
a.it('Creates directories', function()
local err = a.wrap(files.perform_action, 2)({
url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a',
entry_type = 'directory',
type = 'create',
})
assert.is_nil(err)
tmpdir:assert_fs({
['a/'] = true,
})
end)
a.it('Deletes files', function()
tmpdir:create({ 'a.txt' })
a.util.scheduler()
local url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a.txt'
local err = a.wrap(files.perform_action, 2)({
url = url,
entry_type = 'file',
type = 'delete',
})
assert.is_nil(err)
tmpdir:assert_fs({})
end)
a.it('Deletes directories', function()
tmpdir:create({ 'a/' })
local url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a'
local err = a.wrap(files.perform_action, 2)({
url = url,
entry_type = 'directory',
type = 'delete',
})
assert.is_nil(err)
tmpdir:assert_fs({})
end)
a.it('Moves files', function()
tmpdir:create({ 'a.txt' })
a.util.scheduler()
local src_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a.txt'
local dest_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'b.txt'
local err = a.wrap(files.perform_action, 2)({
src_url = src_url,
dest_url = dest_url,
entry_type = 'file',
type = 'move',
})
assert.is_nil(err)
tmpdir:assert_fs({
['b.txt'] = 'a.txt',
})
end)
a.it('Moves directories', function()
tmpdir:create({ 'a/a.txt' })
a.util.scheduler()
local src_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a'
local dest_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'b'
local err = a.wrap(files.perform_action, 2)({
src_url = src_url,
dest_url = dest_url,
entry_type = 'directory',
type = 'move',
})
assert.is_nil(err)
tmpdir:assert_fs({
['b/a.txt'] = 'a/a.txt',
['b/'] = true,
})
end)
a.it('Copies files', function()
tmpdir:create({ 'a.txt' })
a.util.scheduler()
local src_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a.txt'
local dest_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'b.txt'
local err = a.wrap(files.perform_action, 2)({
src_url = src_url,
dest_url = dest_url,
entry_type = 'file',
type = 'copy',
})
assert.is_nil(err)
tmpdir:assert_fs({
['a.txt'] = 'a.txt',
['b.txt'] = 'a.txt',
})
end)
a.it('Recursively copies directories', function()
tmpdir:create({ 'a/a.txt' })
a.util.scheduler()
local src_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a'
local dest_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'b'
local err = a.wrap(files.perform_action, 2)({
src_url = src_url,
dest_url = dest_url,
entry_type = 'directory',
type = 'copy',
})
assert.is_nil(err)
tmpdir:assert_fs({
['b/a.txt'] = 'a/a.txt',
['b/'] = true,
['a/a.txt'] = 'a/a.txt',
['a/'] = true,
})
end)
a.it('Editing a new oil://path/ creates an oil buffer', function()
local tmpdir_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. '/'
vim.cmd.edit({ args = { tmpdir_url } })
test_util.wait_oil_ready()
local new_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'newdir'
vim.cmd.edit({ args = { new_url } })
test_util.wait_oil_ready()
assert.equals('oil', vim.bo.filetype)
-- The normalization will add a '/'
assert.equals(new_url .. '/', vim.api.nvim_buf_get_name(0))
end)
a.it('Editing a new oil://file.rb creates a normal buffer', function()
local tmpdir_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. '/'
vim.cmd.edit({ args = { tmpdir_url } })
test_util.wait_for_autocmd('BufReadPost')
local new_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'file.rb'
vim.cmd.edit({ args = { new_url } })
test_util.wait_for_autocmd('BufReadPost')
assert.equals('ruby', vim.bo.filetype)
assert.equals(vim.fn.fnamemodify(tmpdir.path, ':p') .. 'file.rb', vim.api.nvim_buf_get_name(0))
assert.equals(tmpdir.path .. '/file.rb', vim.fn.bufname())
end)
end)