-
Notifications
You must be signed in to change notification settings - Fork 43
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
Test Output in JSON, making it difficult to read #52
Comments
I had a similar issue, and it was due to clang compiler warnings being printed due to cgo. Once I disabled the warnings, the test output was correctly parsed. |
Neotest-go does not properly parse the test output when using Go provided via pkgx: If e.g. using Go provided through Homebrew, the test output works fine and this specific test in the screenshot passes. |
@pehowell Can you help to explain how to do this? |
EDIT: hm, strange ... I no longer see these JSON lines mixed in with the non-JSON lines in the test output window. Original postI am working in a project right now where I get both nicely printed output along with a huge amount of JSON printed in the test output panel. When I run "nearest test" and debug print some values (see git diff at the bottom of post), I can see that neotest-go writes 4 files to tmp:
When I compare the output I see in Neovim with the contents of these files, the Test Output panel prints file I wouldn't want file It's also possible I get these four files because of how my test is structured: func Test_Something(t *testing.T) {
t.Parallel()
t.Run("Create something", func(t *testing.T) {
t.Parallel()
t.Run("Create something with minimal data", func(t *testing.T) {
... Here's a diff showing how I obtained these filepaths and was able to inspect their contents: diff --git a/lua/neotest-go/init.lua b/lua/neotest-go/init.lua
index 8c97dc4..048fdc1 100644
--- a/lua/neotest-go/init.lua
+++ b/lua/neotest-go/init.lua
@@ -198,11 +198,16 @@ function adapter.results(spec, result, tree)
end
local success, lines = pcall(lib.files.read_lines, result.output)
+ print("file containing all output", vim.inspect(result.output))
if not success then
logger.error("neotest-go: could not read output: " .. lines)
return {}
end
- return adapter.prepare_results(tree, lines, go_root, go_module)
+ local r = adapter.prepare_results(tree, lines, go_root, go_module)
+
+ print("FINAL")
+ print(vim.inspect(r))
+ return r
end
---@param tree neotest.Tree
@@ -239,6 +244,7 @@ function adapter.prepare_results(tree, lines, go_root, go_module)
-- file level node
if test_result then
local fname = async.fn.tempname()
+ print("nicely parsed results", fname, vim.inspect(test_result.output))
fn.writefile(test_result.output, fname)
results[value.id] = {
status = test_result.status,
@@ -247,14 +253,15 @@ function adapter.prepare_results(tree, lines, go_root, go_module) Here's another diff which removes the diff --git a/lua/neotest-go/init.lua b/lua/neotest-go/init.lua
index 8c97dc4..98117d7 100644
--- a/lua/neotest-go/init.lua
+++ b/lua/neotest-go/init.lua
@@ -202,7 +202,10 @@ function adapter.results(spec, result, tree)
logger.error("neotest-go: could not read output: " .. lines)
return {}
end
- return adapter.prepare_results(tree, lines, go_root, go_module)
+
+ local r = adapter.prepare_results(tree, lines, go_root, go_module)
+ vim.fn.delete(result.output)
+ return r
end
---@param tree neotest.Tree This gives me a readable result in the test output, but yields an error, since neotest is attempting to read this (now non-existing) file:
This means the @sergii4 is it possible that the contents of file |
Hi @fredrikaverpil, wasn't it fixed by #54? |
@sergii4 yes, I must have been on some weird, locally modified, version of neotest-go... Sorry for the noise. |
@sergii4 I once again got json output in the "Neotest Output" pane. I don't quite understand what's triggering this behavior. Sometimes I only see JSON output, sometimes I see a mix of nicely formatted non-JSON output. It's when I have to manually read through all the JSON output that this becomes really tedious. Weird... I wonder if this might have anything to do with testcontainers, which is being used in this project... |
@sergii4 can confirm that this is still happening as I don't locally modify any neotest-go files. However, the output is only showing raw JSON when I open the individual test and the test output panel.
This behavior seems to differ from files to files. Sometime it shows the correct output, sometimes not, depending on the file. (I was getting all raw JSON output on file using testify suite) |
I'm also working on and off with nested tests which could explain why I see this irregularly. There's a showstopper here, unfortunately, which makes certain failing tests so hard to manually read (the JSON output) that I have to keep vscode open on the side and re-run the test there, only so I can see why the test was failing. |
Thank @Vjchi, @fredrikaverpil for brining this up and @Syakhisk for an excellent illustration. I have reproduced the bug. Taking a look 👁️ |
Hey @sergii4, thanks a lot for taking the time to fix this. I'm using Go 1.21.6 if that helps |
Hi @Syakhisk, sorry for false hope. Could you please pull and try again? |
Yupp, it works on the tests in your PR. But I've found yet another bug. if the 2nd level test has space in it, the output still messed up If i remove the space, it works. neotest-go/lua/neotest-go/init.lua Lines 237 to 239 in e12fe00
e.g.
I think we should also substitute spaces with underscore beside removing the quotes. |
But upon checking on my real projects, it still shows the JSON. I think for now let's keep the issue open, wdyt? @sergii4 |
@Syakhisk of course |
Thanks for your efforts on looking into this. I've added a minimal example here: |
Hey @fredrikaverpil, could you please try #82 on your playground? It seems working to me |
@sergii4 this one actually still causes JSON output for me 😢 |
@fredrikaverpil what I can say 🤷♂️ it's pity. But to be honest I really doubt somebody will write such non-liner test |
@fredrikaverpil seems that we get malformed data from neotest/tree-sitter. Fix requires extensive debugging. |
We actually have this kind of test at work. In our case we are doing a big refactoring effort where we port integration tests over onto a new gRPC service. The skipping is because we are porting code on a per-test basis. So even if it looks exotic, it's actually in use where I work. |
Oh, really, sorry didn't expect that 😄 |
Hi Looks like the cause in this example is invalid test name matching by position_id and test_name from output generator.
I think it's possible to add suite name to neotest tree node and then use it to build position_id (and also to run single test suite method) with little treesitter query modification like this:
I tried to implement it, but got stuck on implementation and running tests. |
Yep, having the same issue with running individual tests of a Test Suite. Funny is that it still recognizes the test tables I have. It just apparently has issues parsing the results and showing as a successful run. |
I did some investigating since I didn't know how neotest adapters worked. The modified treesitter query wouldn't work unless there was an upstream change since Neotest only passes on I can see we might have three options:
@sergii4 Do you see any other paths into fixing this? I'm happy to contribute with a PR if you point me the best way forward. |
Hi @rnesytov, @theoribeiro I need to take a grip on it. I have it on my todo list for the weekend. My last understanding after debugging was that problem comes from neotest/tree-sitter. I am not sure it's connected to the suite test. I assume it's a separate problem |
While developing my own Neotest adapter for Go ( |
Folks, I am not sure I have enough time to constantly contribute and keep up with upcoming issues since it requires long hours of laser-focused debugging. I will continue to support project but we definitely need more capacity I assume we need more contributors. @fredrikaverpil is it something you are interested in? |
It's completely understandable that priorities and availability change with time. Thanks for all the fine work you've done so far @sergii4 ❤️ I'm not interested in taking over this project as I developed my own Neotest adapter for Go (here) some time back and I rather focus my efforts there and on my specific needs. |
@fredrikaverpil thanks you! That's cool! Wish all the best with your shot! |
## What is this PR for? This PR switches [nvim-neotest/neotest-go](https://github.com/nvim-neotest/neotest-go) for [fredrikaverpil/neotest-golang](https://github.com/fredrikaverpil/neotest-golang). ## Does this PR fix an existing issue? Neotest-go comes with some problems which are mitigated in neotest-golang. A full description/background is available in the project README, but here are some highlights: ### Neotest-go issues mitigated in neotest-golang - Test Output in JSON, making it difficult to read: [neotest-go#52](nvim-neotest/neotest-go#52) - "Run nearest" runs all tests: [neotest-go#83](nvim-neotest/neotest-go#83) - Running test suite doesn't work: [neotest-go#89](nvim-neotest/neotest-go#89) - Diagnostics for table tests on the line of failure: [neotest-go#75](nvim-neotest/neotest-go#75) - Support for Nested Subtests: [neotest-go#74](nvim-neotest/neotest-go#74) - DAP support: [neotest-go#12](nvim-neotest/neotest-go#12) ### Features - Supports all [Neotest usage](https://github.com/nvim-neotest/neotest#usage). - Integrates with [nvim-dap-go](https://github.com/leoluz/nvim-dap-go) for debugging of tests using delve. - Inline diagnostics. - Works great with [andythigpen/nvim-coverage](https://github.com/andythigpen/nvim-coverage) for displaying coverage in the sign column (per-Go package, or per-test basis). - Monorepo support (detect, run and debug tests in sub-projects). - Supports table tests (relies on treesitter AST detection). - Supports nested test functions. ## Notes - I'm the author of [fredrikaverpil/neotest-golang](https://github.com/fredrikaverpil/neotest-golang). ## Checklist - [x] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines.
Good afternoon all,
I’m currently transitioning from VS Code to NeoVim, and decided to get started with LazyVim (a pre-configuration using the package manager Lazy.nvim. Apologies in advance if I have missed something obvious;
Neotest seems to complete the testing as expected (closest test, test file, test all files, etc…), I am experiencing two issues:
See example output below:
For the setup, I followed the recommendations from the lazyVim website, and simply added the plugins in the relevant folder:
neotest.lua
[the file preconfigured by LazyVim]
neotest.lua
neotest-go.lua
[the file I use to declare and load neotest-go]
I don’t know what I’m missing at this point, I’ve restarted the installation of LazyVim from scratch twice, and the only thing I can think of is the adapter not interpreting or parsing the output of the test, for whatever reason,
Any help would be greatly appreciated :)
The text was updated successfully, but these errors were encountered: