Closed Drewfyre closed 2 years ago
Unfortunately I haven't actually tested on Windows, and you're the first person to report using it so there may some small issues :sweat_smile: The command window popping up should be fixed in latest commit.
For the issue of tests not appearing, can you provide a log from stdpath("log") .. "/neotest.log"
and also a sample test file?
Ok, regarding popup window will check if the release pipeline of the commit succeeds.
For the log:
I had to update to nvim nightly v0.8.0+ because the :echo stdpath("log")
didnt work below that version.
Also the neotest.log file was empty before trying to run the test with the nvim nightly version.
After updating nvim to nightly and tryn to run a test the log looks like this:
INFO | 2022-07-06T11:03:42Z+0200 | ...ny46864\.vim\plugged\neotest/lua/neotest/client/init.lua:305 | Initialising client
DEBUG | 2022-07-06T11:03:43Z+0200 | ...46864\.vim\plugged\neotest/lua/neotest/lib/file/find.lua:46 | Searching for files using command { "rg", "--files", "C:\\Users\\ny46864\\dev\\testtest" }
DEBUG | 2022-07-06T11:03:43Z+0200 | ...46864\.vim\plugged\neotest/lua/neotest/lib/file/find.lua:73 | Searching for files finished
DEBUG | 2022-07-06T11:03:43Z+0200 | ...4\.vim\plugged\neotest/lua/neotest/client/state/init.lua:54 | New positions at ID C:\Users\ny46864\dev\testtest
INFO | 2022-07-06T11:03:43Z+0200 | ...\.vim\plugged\neotest/lua/neotest/client/events/init.lua:46 | Emitting discover_positions event
DEBUG | 2022-07-06T11:03:43Z+0200 | ...\.vim\plugged\neotest/lua/neotest/client/events/init.lua:48 | Calling listener status for event discover_positions
DEBUG | 2022-07-06T11:03:43Z+0200 | ...\.vim\plugged\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event discover_positions
DEBUG | 2022-07-06T11:03:43Z+0200 | ...\.vim\plugged\neotest/lua/neotest/client/events/init.lua:48 | Calling listener diagnostic for event discover_positions
INFO | 2022-07-06T11:03:43Z+0200 | ...ny46864\.vim\plugged\neotest/lua/neotest/client/init.lua:372 | Initialisation finished in 1 seconds
INFO | 2022-07-06T11:03:43Z+0200 | ...\.vim\plugged\neotest/lua/neotest/client/events/init.lua:46 | Emitting test_file_focused event
DEBUG | 2022-07-06T11:03:43Z+0200 | ...\.vim\plugged\neotest/lua/neotest/client/events/init.lua:48 | Calling listener status for event test_file_focused
ERROR | 2022-07-06T11:03:43Z+0200 | ...\.vim\plugged\neotest/lua/neotest/client/events/init.lua:51 | Error during listener status for event: ...64\.vim\plugged\neotest/lua/neotest/consumers/status.lua:29: attempt to index local 'tree' (a nil value)
DEBUG | 2022-07-06T11:03:43Z+0200 | ...\.vim\plugged\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event test_file_focused
DEBUG | 2022-07-06T11:03:43Z+0200 | ...\.vim\plugged\neotest/lua/neotest/client/events/init.lua:48 | Calling listener diagnostic for event test_file_focused
I created a small repo with a single test as a sample. https://github.com/Drewfyre/Neotest-test-csharp
Looks like the path is being constructed incorrectly
DEBUG | 2022-07-06T11:03:43Z+0200 | ...4.vim\plugged\neotest/lua/neotest/client/state/init.lua:54 | New positions at ID C:\Users\ny46864\dev\testtest
I'll try find out where this could be happening
In case you want to try find it yourself, these lines https://github.com/nvim-neotest/neotest/blob/master/lua/neotest/client/init.lua#L226-L227 are the ones of interest I believe. When calling lib.files.find({ path })
the path is correct
DEBUG | 2022-07-06T11:03:43Z+0200 | ...46864.vim\plugged\neotest/lua/neotest/lib/file/find.lua:46 | Searching for files using command { "rg", "--files", "C:\Users\ny46864\dev\testtest" }
and then it's wrong in parsed result on the next line.
Sadly, I haven't taken a look into vim extension development or lua for that matter. So it would take me quite some time I guess. If you happen to find the time to fix this I would be really glad.
Any updates?
@Drewfyre - Try https://github.com/Issafalcon/neotest-dotnet . I've not tested it on Windows yet, but hopefully this will become the adapter for dotnet testing. If it doesn't work, then it maybe more likely an issue with the core neotest code, rather than the adapter, but I'll try to help where possible.
Sweet! Currently on vacation but will give it a try once im Home.
So I tried my adapter on Windows and discovering tests seems to just hang Neovim. Not had time to investigate, but I also tried the run commands of neotest directly and the outcome of 'No tests found' in the messages came up. So I imagine it's an issue with the core neotest code.
I can confirm that this isn't just a C# tests thing. It occurs with the plenary adapter, the jest adapter and the python adapter, when neotest is used on Windows. So as @rcarriga mentioned, it's probably the file paths being malformed. I tried to pinpoint it myself, but couldn't narrow it down. I'm not completely sure the format it expects when searching for test positions on Windows.
Thanks for investigating!
If you can print out the tree parsed then that should hopefully give some useful info. Just here https://github.com/nvim-neotest/neotest/blob/master/lua/neotest/client/init.lua#L258-L260 You can add a print like this, and just paste here. This will be very large if in a large repo, so a small repo would be best :sweat_smile:
if positions:data().type == "dir" then
print(vim.inspect(positions:to_list()))
self:_parse_dir_files(path, adapter_id)
end
@rcarriga - So I think I have narrowed it down to a problem in lib/file.find.lua with the find
function. The command (run using fd
) and it's args all look OK, and when I run the same command directly from powershell or cmd it returns all the expected outputs. However, when the command runs in that vim.loop.spawn command, the stdout is always nil. I've pretty much hit my limit of understanding there, when it comes to how vim.loop works and why it seems to function differently on Window than Linux in this case.
To further prove the point, I forced the find
function to return a list with a single hard coded file path of the test file I was currently in, and this produced a list of all the tests in the summary window. However, I then went on to run the tests, which produced the following in the log:
DEBUG | 2022-09-10T17:27:37Z+0100 | ...k\packer\start\neotest/lua/neotest/client/state/init.lua:87 | Setting positions to running C:\Users\adam.figgins\AppData\Local\nvim-data\site\pack\packer\start\neotest/tests\unit\consumers\jump_spec.lua::"jump consumer"
INFO | 2022-09-10T17:27:37Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:46 | Emitting run event
DEBUG | 2022-09-10T17:27:37Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener diagnostic for event run
DEBUG | 2022-09-10T17:27:37Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener status for event run
DEBUG | 2022-09-10T17:27:37Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event run
INFO | 2022-09-10T17:27:37Z+0100 | ...ker\start\neotest/lua/neotest/client/strategies/init.lua:32 | Starting process neotest-plenary:C:\Users\adam.figgins\AppData\Local\nvim-data\site\pack\packer\start\neotest-C:\Users\adam.figgins\AppData\Local\nvim-data\site\pack\packer\start\neotest/tests\unit\consumers\jump_spec.lua::"jump consumer" with strategy integrated
DEBUG | 2022-09-10T17:27:37Z+0100 | ...ker\start\neotest/lua/neotest/client/strategies/init.lua:33 | Strategy spec {
command = { "C:\\tools\\neovim\\nvim-win64\\bin\\nvim.exe", "--headless", "-u", "tests\\init.vim", "-c", "source C:\\Users\\adam.figgins\\AppData\\Local\\nvim-data\\site\\pack\\packer\\run_tests.lua", "--noplugin", "-c", "lua _run_tests({results = 'C:\\Users\\ADAM~1.FIG\\AppData\\Local\\Temp\\nvim3bvuhe\\3', file = 'C:\\Users\\adam.figgins\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\neotest/tests\\unit\\consumers\\jump_spec.lua', filter = { { 7, 136 } }})" },
context = {
file = "C:\\Users\\adam.figgins\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\neotest/tests\\unit\\consumers\\jump_spec.lua",
results_path = "C:\\Users\\ADAM~1.FIG\\AppData\\Local\\Temp\\nvim3bvuhe\\3"
},
strategy = {
height = 40,
width = 120
}
}
Then the runner just hangs (not blocking the neovom UI though). So I noticed that the neotest/tests
portion of the file name there uses the linux file separator. I'm guessing this is the cause of the tests not running properly, or at least the results not showing up correctly (I couldn't find the specified file in the results_path
either). Still not sure about why the find commands don't work as expected. Maybe something to do with how the fd
or rg
commands work with pipes? Could be related to https://github.com/neovim/neovim/issues/13736 maybe?
OK that's great progress!
Interesting on the fd
issue. It's been a while since I looked at it but I believe it's using the same command/arguments as telescope so not sure why it wouldn't work :thinking:
when it comes to how vim.loop works and why it seems to function differently on Window than Linux in this case.
It's supposed to function the same unless stated otherwise in docs so I'd say it's probably fd
related instead but that's also just a guess.
For the separator issue, I've never actually verified the separator detection, I'm not even sure where it came from :sweat_smile: I've switched to how plenary figures it out so that might fix it, please try with the latest commit.
Nice one! That's done the trick to fix the test discovery issue. Looks like the correct tests are being returned in the summary pane (takes a couple of attempts - i.e. Opening it displays 'No Tests Found' but saving the test file again in neovim seems to trigger an update to the positions and then they are displayed correctly).
However, running tests fails (I tried both plenary adapter and the dotnet one). I think there is an issue with the windows filepath again for these adapters (and probably others). Here is the output results file from the plenary adapter running the neotest tests:
[2J[m[HE]0;C:\tools\neovim\nvim-win64\bin\nvim.exe[?25h[25l[HError detected while processing C:\Users\adam.figgins\AppData\Local\nvim-data\site\pack\packer\start\neotest\tests\init.
vim:[K
line 6:[K
E484: Cannot open file tests/minimal_init.lua[K[?25hError detected while processing co
E484: Cannot open file tests/minimal_init.luaError detected while processing command line:
E484: Cannot open file C:\Users\adam.figgins\AppData\Local\nvi[28X
E484: Cannot open file C:\Users\adam.figgins\AppData\Local\nvim-data\site\pack\packer\run_tests.lua
E5107: Error loading lua [string ":lua"]:1: invalid escape sequence near ''C:'[21X
I get something similar in the .trx file from the dotnet adapter, in that the filter for the test name tried to include the C
drive, which is not correct.
Might need some tweaking in the adapters themselves?
In addition, running the neotest commands directly (neotest.run.run()) both on the nearest test and all tests in the file, doesn't seem to work. I still get the message 'No tests found' but nothing in the neotest logs.
OK I've rewritten the file discovery to not rely on external tools so please let me know if there are any issues with it now. I've also added more logging (though changed default level to warnings) to help debug any further issues.
Yep those issues are in the adapters. I've updated neotest-plenary if you could try again, I think it should work, though there's some globbing that I'm not 100% confident on.
I'm not sure about the dotnet one if it's an adapter issue or something in the neotest libs, hopefully you can figure that one out :sweat_smile:
In addition, running the neotest commands directly (neotest.run.run()) both on the nearest test and all tests in the file, doesn't seem to work. I still get the message 'No tests found' but nothing in the neotest logs.
This sounds like it's not finding the project root. If you're still seeing it after latest changes, can you provide a debug log? You can change level with log_level
option in setup
Thanks again for the quick updates! I gave it another go. The new file discovery seems to work a lot better with Windows, in that it now picks up all the test files and displays them in the summary window. However, the issues with running those tests via the summary window still stands. Here's the debug log of me trying to run a test through the summary window (where the command appears), and then the log afterwards:
INFO | 2022-09-11T15:52:41Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:46 | Emitting test_focused event
DEBUG | 2022-09-11T15:52:41Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event test_focused
INFO | 2022-09-11T15:52:42Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:46 | Emitting test_focused event
DEBUG | 2022-09-11T15:52:42Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event test_focused
INFO | 2022-09-11T15:52:53Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:46 | Emitting test_file_focused event
DEBUG | 2022-09-11T15:52:53Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener status for event test_file_focused
DEBUG | 2022-09-11T15:52:53Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener diagnostic for event test_file_focused
DEBUG | 2022-09-11T15:52:53Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event test_file_focused
INFO | 2022-09-11T15:52:53Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:46 | Emitting test_focused event
DEBUG | 2022-09-11T15:52:53Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event test_focused
INFO | 2022-09-11T15:52:54Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:46 | Emitting test_focused event
DEBUG | 2022-09-11T15:52:54Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event test_focused
INFO | 2022-09-11T15:52:55Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:46 | Emitting test_focused event
DEBUG | 2022-09-11T15:52:55Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event test_focused
INFO | 2022-09-11T15:52:55Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:46 | Emitting test_focused event
DEBUG | 2022-09-11T15:52:55Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event test_focused
DEBUG | 2022-09-11T15:53:03Z+0100 | ...k\packer\start\neotest/lua/neotest/client/state/init.lua:85 | Setting positions to running C:\Users\adam.figgins\AppData\Local\nvim-data\site\pack\packer\start\neotest\tests\unit\consumers\jump_spec.lua::"jump consumer"::"next goes to first test"
INFO | 2022-09-11T15:53:03Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:46 | Emitting run event
DEBUG | 2022-09-11T15:53:03Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener status for event run
DEBUG | 2022-09-11T15:53:03Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener diagnostic for event run
DEBUG | 2022-09-11T15:53:03Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event run
INFO | 2022-09-11T15:53:03Z+0100 | ...ker\start\neotest/lua/neotest/client/strategies/init.lua:32 | Starting process neotest-plenary:C:\Users\adam.figgins\AppData\Local\nvim-data\site\pack\packer\start\neotest-C:\Users\adam.figgins\AppData\Local\nvim-data\site\pack\packer\start\neotest\tests\unit\consumers\jump_spec.lua::"jump consumer"::"next goes to first test" with strategy integrated
DEBUG | 2022-09-11T15:53:03Z+0100 | ...ker\start\neotest/lua/neotest/client/strategies/init.lua:33 | Strategy spec {
command = { "C:\\tools\\neovim\\nvim-win64\\bin\\nvim.exe", "--headless", "-u", "tests\\minimal_init.lua", "-c", "source C:\\Users\\adam.figgins\\AppData\\Local\\nvim-data\\site\\pack\\run_tests.lua", "--noplugin", "-c", "lua _run_tests({results = 'C:\\Users\\ADAM~1.FIG\\AppData\\Local\\Temp\\nvimz75y4Q\\1', file = 'C:\\Users\\adam.figgins\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\neotest\\tests\\unit\\consumers\\jump_spec.lua', filter = { { 7, 136 }, { 67, 72 } }})" },
context = {
file = "C:\\Users\\adam.figgins\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\neotest\\tests\\unit\\consumers\\jump_spec.lua",
results_path = "C:\\Users\\ADAM~1.FIG\\AppData\\Local\\Temp\\nvimz75y4Q\\1"
},
strategy = {
height = 40,
width = 120
}
}
INFO | 2022-09-11T15:55:01Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:46 | Emitting test_file_focused event
DEBUG | 2022-09-11T15:55:01Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener status for event test_file_focused
DEBUG | 2022-09-11T15:55:01Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener diagnostic for event test_file_focused
DEBUG | 2022-09-11T15:55:01Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event test_file_focused
INFO | 2022-09-11T15:55:01Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:46 | Emitting test_focused event
DEBUG | 2022-09-11T15:55:01Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event test_focused
INFO | 2022-09-11T15:55:01Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:46 | Emitting test_focused event
DEBUG | 2022-09-11T15:55:01Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event test_focused
INFO | 2022-09-11T15:55:01Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:46 | Emitting test_focused event
DEBUG | 2022-09-11T15:55:01Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event test_focused
INFO | 2022-09-11T15:55:02Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:46 | Emitting test_focused event
DEBUG | 2022-09-11T15:55:02Z+0100 | ...\packer\start\neotest/lua/neotest/client/events/init.lua:48 | Calling listener summary for event test_focused
The test then appears to be running and never completes, with the output in a temp file (with ID 1 higher than the specified ID in the results_path
property of the logs) that looks like:
[2J[m[HE]0;C:\tools\neovim\nvim-win64\bin\nvim.exe[?25h[25l[HError detected while processing command line:[47X
E484: Cannot open file C:\Users\adam.figgins\AppData\Local\nvim-data\site\pack\run_tests.lua
E5107: Error loading lua [string ":lua"]:1: invalid escape sequence near ''C:'[14X[?25h
Then I tried to run the nearest test using require("neotest").run.run()
but I still only get the output of No tests found
in messages, with nothing else in the log file.
When I get more time I'll investigate how to fix it in the neotest-adapter, and maybe it might shed more light on how to fix it in other adapters.
OK. So with a combination of your latest changes to neotest core @rcarriga , and a minor update to neotest-dotnet (see https://github.com/Issafalcon/neotest-dotnet/commit/8b4b5e452b1702ab94d5abca7023d13231694781), everything looks like it's working well on Windows with C# tests!
Whatever you've done for file discovery has made a big improvement for test discovery in general! The summary window is a lot more "complete" now. (The 1400+ tests in my dotnet project at work all show up in the summary window providing they are searched after the omnisharp-lsp is attached). It seems to be that way for other test frameworks too (I'll need to switch back to my home machine with WSL installed to test it out there as well).
Only minor thing I noticed since the updates were that there are now a huge number of ERROR lines in the log now that match:
ERROR | 2022-09-11T17:01:36Z+0100 | ...ker\start\neotest/lua/neotest/consumers/summary/init.lua:106 | Couldn't render buffer Window not found
This occurs for all the adapters on Windows it seems. The only windows I have open are the initial individual test file and the neotest summary window, when this error log keeps appearing.
For running tests using other adapters on Windows, there may be some issues like there still is with the Plenary one. I'm not sure of the number of people who actually use Neovim on Windows (I do for work, only because there are some silly .bat scripts that are run as part of the build, so can't really use WSL like I would otherwise), but it seems to me that the problems in the neotest core code have been fixed for this issue.
@Drewfyre - If you could also try out the neotest-dotnet adapter to confirm everything is fixed for you too?
Today is my last vacation day. So I will definitely try it out tomorrow. I followed the convo here and am hopeful that it works for me too.
Seems to be working for me as well! I tried it with the neotest-dotnet adapter and running test, as well as the summary seem to be working. Haven't encountered any issues so far.
Ah that's great to hear! As long as neotest core works then we're good. I'll try figure out the neotest-plenary issue but as you said there's probably not many people using Windows for plugin development :sweat_smile:
ERROR | 2022-09-11T17:01:36Z+0100 | ...ker\start\neotest/lua/neotest/consumers/summary/init.lua:106 | Couldn't render buffer Window not found
Don't worry about this, it's just a red herring that I need to prevent causing noise
One thing to note is that the new file finding now no longer respects gitignore. I'm not sure how dotnet dependencies work, but if they are installed in a directory within a project that is not hidden (i.e. starts with .
) then neotest-dotnet should define a filter_dir
function to prevent them being searched.
Thanks @rcarriga ! Great work on this! 😃
I'll add an issue to the dotnet adapter to make sure it doesn't search unnecessary files. Just to clarify, when you say they are 'searched', which point in the process do you mean? Is it at the start when neotest is determining which files are test files, or will it be during discover positions?
Yep on startup when just searching for files to be checked with adapter.is_test_file
. For examples the JS adapters will filter out node_modules
because nothing in that should be searched. You can see recent changes in neotest-jest, neotest-vitest and neotest-python but it's just a simple name filter. If you don't filter, non-test files will still be filtered by is_test_file
, it's purely for performance :smile:
Closing this as it seems like only issues are now adapter specific
Opening it displays 'No Tests Found' but saving the test file again in neovim seems to trigger an update to the positions and then they are displayed correctly).
I'm still having this issue. I'm on linux and using neotest-python. When opening a file, neotest mostly works, but sometimes (I haven't found a way to reproduce, it seems to be random) I get the "No Tests Found" with the following log:
ERROR | 2022-10-06T11:51:02Z-0300 | .../neotest/lua/neotest/client/init.lua:274 | Couldn't find positions in path /home/user/python/proj .../neotest/lua/neotest/lib/file/find.lua:27: bad argument #1 to 'fs_scandir_next' (uv_req expected, got nil)
This is a completely unrelated problem. Please open another issue
Hi, I have used ul-test for a while but wanted to switch to NeoTest. However I am facing issues with it not detecting my tests.
Config is the following:
I didn't add the ignore_file_types or allow_file_types options as I only use it for C#.
When I run
require("neotest").run.run()
orrequire("neotest").run.run(vim.fn.expand("%"))
I get a cmd popup running through a lot of files (can't really tell as it's going to fast) and then an output inside vim stating "No tests found".I can run the tests from vim-test however. I.e. I can call :TestNearest or :TestFile from vim-test and it works. I have also run
TSInstall c_sharp
so that cant be it either.Edit: I am running Win10 and Nvim inside PowerShell.