lawrence-laz / neotest-zig

Test runner for Zig in Neovim using Neotest backend.
MIT License
27 stars 7 forks source link

Neotest-zig adapter is used for non-zig repos, resulting in unexpected 'No tests found' #8

Closed asfaltboy closed 5 months ago

asfaltboy commented 7 months ago

Describe the bug

When neotest-zig adapter is enabled, alongside another plugin, such as neotest-go, it's can get selected incorrectly if it's the earlier adapter that is being tested first.

I believe the adapter selection may happen due to the root definition at

Neotest returns the root if any of the matches are found (source). And, since .git is a directory that will exist in any git repo, it always matches, which is incorrect.

As far as I understand, neotest should run for .zig files even if they aren't detected in a project. So if the root dir does not have any .zig files, then the root dir will not be detected as a zig project, but zig tests can still run in individual files (see docs)

Steps To Reproduce

  1. Enable two adapters, one of which is zig.
  2. Start vim and run neotest
  3. Receive "No tests found"

Current behavior

Using the zig adapter alongside another neotest adapter takes away the ability to use the other adapter.

Expected behavior

One should be able to use neotest-zig alongside any neotest-* adapter without this unexpected side effect.

Logs

No neotest-zig logs should actually be emitted for this issue, so I didn't bother enabling logging and running those. But, here's the relevant neotest.log excerpt from when neotest ran in a Go test module:

Details

``` INFO | 2024-04-02T16:00:14Z+0100 | ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:380 | Initialising client INFO | 2024-04-02T16:00:14Z+0100 | ...are/nvim/lazy/neotest/lua/neotest/client/events/init.lua:48 | Emitting starting event DEBUG | 2024-04-02T16:00:14Z+0100 | ...are/nvim/lazy/neotest/lua/neotest/client/events/init.lua:50 | Calling listener summary for event starting INFO | 2024-04-02T16:00:14Z+0100 | ...al/share/nvim/lazy/neotest/lua/neotest/adapters/init.lua:18 | Found 1 adapters for directory /home/asfaltboy/Code/learning/gophercises/ex-01-quiz DEBUG | 2024-04-02T16:00:14Z+0100 | ...al/share/nvim/lazy/neotest/lua/neotest/adapters/init.lua:19 | Adapters: { { adapter = { _debug_log_path = "/home/asfaltboy/.local/share/nvim/neotest-zig.log", _does_file_contain_tests = , _enable_debug_log = , _is_debug_log_enabled = false, _test_treesitter_query = "\t;;query\n\t(TestDecl\n\t\t[(IDENTIFIER) (STRINGLITERALSINGLE)] @test.name\n\t) @test.definition\n", build_spec = , discover_positions = , get_strategy_config = , get_test_node_by_runspec = , is_test_file = , name = "neotest-zig", results = , root = , setup = , version = "v1.0.5", = { __call = } }, root = "/home/asfaltboy/Code/learning/gophercises/ex-01-quiz" } } ```

Environment

lawrence-laz commented 7 months ago

Hi, thanks for reporting the issue.

I'm currently in the process of rewriting the test runner so it would support latest zig version and would work with both: individual *.zig files and modules with external dependencies via build.zig among other improvements, like exact test filtering, using single run for all tests, etc.

There's been some issues regarding finding the root already, so I'll need to check that no regressions are introduced and that all works fine with the new test runner.

So the plan is to finish up the rework on test runner first, and then I will try to address this keeping all other things in mind.

asfaltboy commented 7 months ago

That sounds great, I appreciate your ongoing dedication to the adapter.

I'm still new to neovim/Lua, so I'd be happy to learn more by reviewing and testing any new changes.

lawrence-laz commented 7 months ago

@asfaltboy, I have pushed a branch v1.2.0, could you test it?

asfaltboy commented 6 months ago

It took a while, but looks like arch got zig 0.12 now. But I cannot find the branch you linked to above. Would you be able to push some version that I could test?

EDIT: I see you've pushed the changes fixing the root dir to main, let me give that a go

EDIT 2: I'm getting the error described in #10 , sadly this happens in both go and zig files, so I'm going to disable it for now

lawrence-laz commented 6 months ago

Hopefully #10 is now resolved, the author raised a PR. I am on nvim v0.10.0 so only tested on that version.

I also set up go with neotest-go to test the adapters together. neotest-zig doesn't seem to show up as an adapter in go repo anymore, and go tests seem to execute ok:

image
lawrence-laz commented 5 months ago

Closing this, the fix is in main. Let me know if something still doesn't work.