-
-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] in neotest.lib.treesitter.parse_positions caused by neotest.lib.files.read #349
Comments
I think I start to understand my mistake thank's to this issue |
How did you solve the problem? I am going through the same trouble writing a an adapter and I wanted to write tests for my it('Discovers nothing in an empty file', function()
vim.fn.writefile({''}, tempfile, 's')
local tree = adapter.discover_positions(tempfile)
assert.is_empty(tree) -- Or something along those lines
end) However, this won't work. Apparently it('Discovers nothing in an empty file', function()
vim.fn.writefile({''}, tempfile, 's')
local task = nio.run(
function()
return adapter.discover_positions(tempfile)
end,
function(success, tree)
assert.is_true(success)
assert.is_true(false)
end
)
task.wait()
end) Well, this won't work either, I get a segfault and the test passes enough though the second assertions should definitely fail. It looks reasonable, but I am probably missing something here. |
You can use the busted wrapper functions to run async tests. Example: neotest/tests/unit/lib/files/init_spec.lua Lines 133 to 138 in f6048f3
|
@rcarriga I get the error that
I have both Neotest and Plenary installed. Do I need some initial configuration first? I use the actual Busted to run tests, not Plenary's re-implementation, and all tests run in an environment separate from my own configuration and plugins. EDIT: The test file is: local nio = require 'nio'
local adapter = require 'neotest-busted'
describe('Discovery of test positions', function()
local tempfile
before_each(function()
-- Create temporary file
tempfile = vim.fn.tempname()
end)
after_each(function()
-- Delete temporary file
if vim.fn.filereadable(tempfile) ~= 0 then
vim.fn.delete(tempfile)
end
end)
nio.tests.it('Discovers nothing in an empty file', function()
vim.fn.writefile({''}, tempfile, 's')
local result = adapter.discover_positions(tempfile)
print(vim.inspect(result))
end)
end) |
Oh interesting, is the |
There is no busted adapter yet, that's what I'm trying to write. For now I am running busted manually. I want to use tests to test the adapter implementation every step along the way, and I wrote a blog post about how to use busted to test Neovim plugins.
Yeah, looks like some runtime magic. Within the test
Tried that already: it('Does something async', function()
local success, err
local task = nio.tasks.run(function()
assert.is_true(true)
assert.equal('x', 'y')
return 'Yay!'
end,
function(success_, err_)
success = success_
if not success_ then
err = err_
end
end)
vim.wait(2000, function()
return success ~= nil
end, 20, false)
if success == nil then
error(string.format("Test task timed out\n%s", task.trace()))
elseif not success then
error(string.format("Test task failed with message:\n%s", err))
end
end) This gives me a different error which is triggered by the failed assertion:
If instead of a failing assertion I raise an error (e.g.
Should we open a new issue instead of spamming this one? |
NeoVim Version
Describe the bug
I tried to make my own adapter so I looked over other adapter code and I ran into a problem using
parse_position uses neotest.lib.files.read which itself uses nio.uv.fs_open : (as U can see I added a vim.print to log)
The problem here is that open_err and file_fd are mixed up
when file_path is a valid file_path with valid perm, etc... then open_err is just the fd and
the fd is nil because there is no error. When I intentionnaly feed it a wrong file_path, then
open_err is nil because there is no fd because the file_path is wrong and then file_fd
contains the error, causing the rest of the function to crash.
To Reproduce
cd /tmp touch valid_file.txt chmod 777 ./valid_file.txt
nvim --clean -u minimal.lua
(It's the default one):lua require("neotest.lib").treesitter.parse_positions("/tmp/valid_file.txt", [[]], {})
The assert should fail with the fd as an error.
:lua require("neotest.lib").treesitter.parse_positions("/tmp/invalid_file_pathjldsqjldkfqklsjdfkljqklsdjfkljqklsdjfk", [[]], {})
Here no assert should fail as the fd is nil (open_err in the implementation of neotest.lib.files.read) and then the function should
crash because file_fd in the implementation now contains the error (a string I guess ? or at least it's printable).
Expected behavior
Don't really know what more to say here, to not mixup open_err and file_fd ?
Logs
As it's just a function that I'm trying to use to make an adapter and that fails I don't think there is any log to put here, instead I will reproduce every steps of the To Reproduce with the added vim.print and show you what I got.
valid file path :
invalid file path :
PS :
to add the vim.print at line 24 between fs_open and assert
The text was updated successfully, but these errors were encountered: