-
Notifications
You must be signed in to change notification settings - Fork 22
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
Tests don't work #329
Comments
For me, ❯ make test
/bin/sh: 1: busted: not found
Tests failed. Please review the errors above to diagnose issues. That would be very nice to have that working and even run on the CI. |
For the first 5 test, I am getting this error:
Looks like this is something with cursor placement. I suspect it is related to |
I don't plan to fix the tests. I may try to add some more health checks on the weekend, though. I'll see if we can get the result of |
I have found that |
I have modifed one test to see what is going on: it("returns the correct language at cursor position", function()
-- Set the cursor position
rpcrequest(nvim, "nvim_win_set_cursor", 0, { 13, 0 })
-- Verify the cursor position
local cursor_pos = rpcrequest(nvim, "nvim_win_get_cursor", 0)
print("Cursor position:", cursor_pos[1], cursor_pos[2])
local filetype = rpcrequest(nvim, "nvim_buf_get_option", 0, "filetype")
print("Filetype:", filetype)
-- Get the content at the cursor position
local line_content = rpcrequest(nvim, "nvim_get_current_line")
print("Content at cursor position:", line_content)
-- Get the language at the cursor position
local lang = send_lua_via_rpc([[return require('r.utils').get_lang()]])
print("Language at cursor position:", lang)
-- Check if the language is "r"
local result = lang == "r"
print("Language at cursor position:", result and "r" or "not r\n")
-- Assert the result
assert.is_true(result)
end) I am getting this output
|
Maybe it will be easier to make it work within |
How this could be used to test |
I don't know yet. But I will have time to try to find a way on the weekend. |
I couldn't make it work. I put this at the end of our local lines = {
"---",
"title: Test",
"author: R.nvim",
"---",
"",
"Normal text.",
"",
"```{r}",
"x <- 1",
"```",
"",
"Normal text again."
}
local b = vim.api.nvim_create_buf(false, false)
vim.api.nvim_set_option_value("filetype", "quarto", { buf = b })
vim.api.nvim_buf_set_lines(b, 0, -1, false, lines)
local w = vim.api.nvim_open_win(b, true, { relative = "win", row = 1, col = 1, width = 80, height = 24 })
vim.api.nvim_win_set_cursor(w, { 1, 1 })
local lang = require("r.utils").get_lang()
vim.api.nvim_win_close(w, true)
if lang == "yaml" then
vim.health.ok("YAML header correctly identified.")
else
vim.health.error("YAML header not identified: " .. lang)
end The last line of the output of
|
So it always returns "markdown" wherever the cursor is? This is the same issue we have with the actual tests. Could it be that TS is not loaded or properly initialized? |
This seems to be the problem, but how could we initialize it? |
I get the correct language with this: local finish_check_lang = function()
local lang = require("r.utils").get_lang()
vim.cmd("quit!")
if lang == "r" then
vim.notify("Languge correctly detected: " .. lang)
else
vim.notify("Wrong languge detected: " .. lang)
end
end
local check_lang = function()
local lines = {
"---",
"title: Test",
"author: R.nvim",
"---",
"",
"Normal text.",
"",
"```{r}",
"x <- 1",
"y <- 2",
"z <- 3",
"```",
"",
"Normal text again."
}
local b = vim.api.nvim_create_buf(false, false)
vim.api.nvim_set_option_value("filetype", "quarto", { buf = b })
vim.api.nvim_buf_set_lines(b, 0, -1, false, lines)
vim.api.nvim_open_win(b, true, { relative = "win", row = 1, col = 1, width = 80, height = 24 })
vim.api.nvim_win_set_cursor(0, { 10, 1 })
vim.schedule(finish_check_lang)
end And then, check_lang() as the last line of |
That is great, can you explain a bit what was the issue? I see that you are using local check_lang = function()
local lines = {
"---",
"title: Test",
"author: R.nvim",
"---",
"",
"Normal text.",
"",
"```{r}",
"x <- 1",
"y <- 2",
"z <- 3",
"```",
"",
"Normal text again.",
}
local b = vim.api.nvim_create_buf(false, false)
vim.api.nvim_set_option_value("filetype", "quarto", { buf = b })
vim.api.nvim_buf_set_lines(b, 0, -1, false, lines)
vim.api.nvim_open_win(b, true, { relative = "win", row = 1, col = 1, width = 80, height = 24 })
vim.api.nvim_win_set_cursor(0, { 10, 1 })
-- Add the code here, not using vim.schedule()
local lang = require("r.utils").get_lang()
vim.cmd("quit!")
if lang == "r" then
vim.notify("Languge correctly detected: " .. lang)
else
vim.notify("Wrong languge detected: " .. lang)
end
end |
I understand the command
It seems that tree-sitter is also scheduled to be updated only when Neovim is idle, that is, in this case, after the |
It's working now: local check_lang = function()
local lines = {
"---",
"title: Test",
"---",
"",
"Normal text.",
"",
"```{r}",
"x <- 1",
"```",
"",
"Normal text again.",
}
local b = vim.api.nvim_create_buf(false, false)
vim.api.nvim_set_option_value("bufhidden", "wipe", { scope = "local" })
vim.api.nvim_set_option_value("number", false, { scope = "local" })
vim.api.nvim_set_option_value("swapfile", false, { scope = "local" })
vim.api.nvim_set_option_value("buftype", "nofile", { scope = "local" })
vim.api.nvim_set_option_value("filetype", "quarto", { buf = b })
vim.api.nvim_buf_set_lines(b, 0, -1, false, lines)
local w = vim.api.nvim_open_win(
b,
true,
{ relative = "win", row = 1, col = 1, width = 80, height = 24 }
)
vim.cmd("redraw")
local langs = {
{ "yaml", 2, 0, "" },
{ "markdown", 4, 0, "" },
{ "markdown_inline", 5, 0, "" },
{ "chunk_header", 7, 0, "" },
{ "r", 8, 0, "" },
{ "chunk_end", 9, 0, "" },
}
for k, v in pairs(langs) do
vim.api.nvim_win_set_cursor(w, { v[2], v[3] })
langs[k][4] = require("r.utils").get_lang()
end
vim.api.nvim_win_close(w, true)
vim.api.nvim_buf_delete(b, { force = true })
vim.health.start("Checking language detection in a Quarto document:")
for _, v in pairs(langs) do
if v[1] == v[4] then
vim.health.ok("Correctly detected: `" .. v[1] .. "`")
else
vim.health.error(
"Wrongly detected: `" .. v[1] .. "` vs `" .. v[4]("`")
)
end
end
end |
The command |
The code is on the branch "health". To try it: Problem: a float window appears briefly while |
I added the option "hide" and the float window no longer pops up. |
Very nice. Minor suggestions, maybe refactor as: Lines 97 to 114 in 078d6bc
local function check_language_detection(doc_type, langs)
vim.health.start("Checking language detection in a " .. doc_type .. " document:")
for _, v in pairs(langs) do
if v[1] == v[4] then
vim.health.ok("Correctly detected: `" .. v[1] .. "`")
else
vim.health.error("Wrongly detected: `" .. v[1] .. "` vs `" .. v[4] .. "`")
end
end
end
local check_lang = function()
-- Fill the buffer with a Quarto document and check language detection
local qlines = {
"---",
"title: Test",
"---",
"",
"Normal text.",
"",
"```{r}",
"x <- 1",
"```",
"",
"Normal text again.",
}
local qlangs = {
{ "yaml", 2, 0, "" },
{ "markdown", 4, 0, "" },
{ "markdown_inline", 5, 0, "" },
{ "chunk_header", 7, 0, "" },
{ "r", 8, 0, "" },
{ "chunk_end", 9, 0, "" },
}
qlangs = check_buffer("quarto", qlines, qlangs)
local nlines = {
"\\documentclass{article}",
"\\begin{document}",
"",
"Normal text.",
"",
"<<example>>=",
"x <- 1",
"@",
"",
"Normal text again.",
"",
"\\end{document}",
}
local nlangs = {
{ "latex", 4, 0, "" },
{ "chunk_header", 6, 0, "" },
{ "r", 7, 0, "" },
{ "chunk_end", 8, 0, "" },
}
nlangs = check_buffer("rnoweb", nlines, nlangs)
check_language_detection("Quarto", qlangs)
check_language_detection("Rnoweb", nlangs)
end |
If you agree, I will push it. |
Thanks! I've just made a minor change to avoid code repetition, and I think the branch is ready to be merged now. |
LGTM. |
I notice we no longer need to use Never mind, I guess this is what you meant here: #329 (comment) |
Yes, I replaced |
It would be better if there were a native Lua command to replace the VimScript command |
@she3o has written some tests about a year ago. However, if I do the command
make test
inR.nvim
directory, I get:Problems that I see:
plenary.nvim
andnvim-treesitter
already being installed.get_lang()
tests that I tried to add in July 2024 don't work.The text was updated successfully, but these errors were encountered: