alfaix / neotest-gtest

Google Test adapter for nvim-neotest
MIT License
45 stars 14 forks source link

root dir not being found #5

Closed igorlfs closed 10 months ago

igorlfs commented 1 year ago

Hello,

I've been meaning to try this plugin. Today I gave it a shot, but I got the following error:

E5108: Error executing lua: ...re/nvim/site/pack/packer/start/neotest/lua/nio/tasks.lua:95: Async task failed without callback: The coroutine failed with this message: 
.../pack/packer/start/neotest/lua/neotest/adapters/init.lua:13: attempt to call field 'root' (a nil value)
stack traceback:
    .../pack/packer/start/neotest/lua/neotest/adapters/init.lua: in function 'adapters_with_root_dir'
    ...te/pack/packer/start/neotest/lua/neotest/client/init.lua:504: in function '_update_adapters'
    ...te/pack/packer/start/neotest/lua/neotest/client/init.lua:478: in function '_start'
    ...te/pack/packer/start/neotest/lua/neotest/client/init.lua:188: in function '_ensure_started'
    ...te/pack/packer/start/neotest/lua/neotest/client/init.lua:200: in function 'get_position'
    ...te/pack/packer/start/neotest/lua/neotest/client/init.lua:152: in function <...te/pack/packer/start/neotest/lua/neotest/client/init.lua:151>
    .../pack/packer/start/neotest/lua/neotest/consumers/run.lua:34: in function 'get_tree_from_args'
    .../pack/packer/start/neotest/lua/neotest/consumers/run.lua:67: in function 'func'
    ...re/nvim/site/pack/packer/start/neotest/lua/nio/tasks.lua:166: in function <...re/nvim/site/pack/packer/start/neotest/lua/nio/tasks.lua:165>
stack traceback:
    [C]: in function 'error'
    ...re/nvim/site/pack/packer/start/neotest/lua/nio/tasks.lua:95: in function 'close_task'
    ...re/nvim/site/pack/packer/start/neotest/lua/nio/tasks.lua:117: in function 'step'
    ...re/nvim/site/pack/packer/start/neotest/lua/nio/tasks.lua:143: in function 'run'
    /home/user/.config/nvim/lua/plugins/test.lua:36: in function </home/user/.config/nvim/lua/plugins/test.lua:35>

While it looks like an error with neotest itself, other adapters work fine. So I'm guessing neotest-gtest isn't picking up my root dir properly (which is set by a compile_commands.json). There might have been a breaking change upstream? Actually, to make other adapters work, I need to uninstall gtest's. Any ideas?

alfaix commented 1 year ago

Hi, this is a bug since the code should work without it, but as a temporary workaround could you please call require"(neotest-gtest").setup({}) in your init.lua. (see README.md - I just updated it). Please let me know if this works!

The documentation is a bit stale, but lately I did not have a lot of time on my hands, sorry :)

igorlfs commented 1 year ago

Indeed, adding require"(neotest-gtest").setup({}) fixes this issue, but now my tests aren't being found. Is there any structure my project should have, to ease test discovery?

alfaix commented 1 year ago

I don't think so, you can check https://github.com/alfaix/neotest-gtest/tree/main/tests/integration/cpp for a working setup. Your test files need to be named test_stuff.* or stuff_test.*

You can also supply your own is_test_file(path) function in config. The default one is here

You can also supply a custom root detection function, the default one is here

igorlfs commented 1 year ago

Okay, I tried to use the integration tests you provided, but I get ...lua/neotest-gtest/init.lua:122: Did not run tests: no tests selected to run. I'm also getting the same error after I renamed my own test files to fit the default function, so I think we're getting there. Any ideas?

alfaix commented 1 year ago

If you're running more than one file, you're probably running into this

Sorry, it's WIP :)

igorlfs commented 1 year ago

Sorry, it's WIP :)

No problem 😅

alfaix commented 10 months ago

Hey, been a while, should be fixed now. See README.md for usage.