alfaix / neotest-gtest

Google Test adapter for nvim-neotest
MIT License
42 stars 11 forks source link

Cannot call async function from non-async context #15

Closed bartman closed 5 months ago

bartman commented 5 months ago

When I try to :ConfigureGtest I get this error:

Error executing Lua callback: ~/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:193: Cannot call async function from non-async context
stack traceback:
        [C]: in function 'error'
        ~/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:193: in function 'wait'
        ~/.local/share/nvim/lazy/nvim-nio/lua/nio/control.lua:141: in function 'wait'
        ~/.local/share/nvim/lazy/neotest-gtest/lua/neotest-gtest/executables/init.lua:28: in function ~/.local/share/nvim/lazy/neotest-gtest/lua/neotest-gtest/executables/init.lua:27>

Versions:

At work, I have a setup similar to:

repo                       <--- top of a "monorepo"
  .git
  subdir                   <--- I work in this tree (pwd for neovim)
    CMakeLists.txt
    lib
      CMakeLists.txt       <--- library built here
      tests
        test_foo.cpp
        CMakeLists.txt     <--- tests added here
  build
    CTestTestfile.cmake    <--- top level index into tests
    lib
      tests
        test_foo           <--- test executable

Reproduce:

Select executable for marked nodes:
1: build/lib/tests/test_foo
2: Enter path...
Type number and <Enter> or click with the mouse (q or empty cancels):
neotest-gtest: ~/.local/share/nvim/lazy/nvim-nio/lua/nio/init.lua:119: The coroutine failed with this message:
vim/_editor.lua:0: E5560: nvim_echo must not be called in a lua loop callback
stack traceback:
        [C]: in function 'nvim_echo'
        vim/_editor.lua: in function 'notify'
        ~/.local/share/nvim/lazy/neotest-gtest/lua/neotest-gtest/report.lua:238: in function '_notify_if_incomplete_results'
        ~/.local/share/nvim/lazy/neotest-gtest/lua/neotest-gtest/report.lua:223: in function 'results'
        ~/.local/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:132: in function '_run_spec'
        ~/.local/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:89: in function ~/.local/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:88>
bartman commented 5 months ago

I made the following hack in neotest-gtest/report.lua, mostly to see what would happen.

-    vim.notify(message, vim.log.levels.WARN)
+    -- vim.notify(message, vim.log.levels.WARN)
+    print("[warn] " .. message)

then tried to run a simple tests case...

image

first of, good news -- this is the first time I've been able to run any tests using neotest. ~my test case passes, as expected.~ after closer inspection, it's not actually running anything.

but it seems that the test is marked with an :x: both in the code pane, and in the side pane:

image

bartman commented 5 months ago

previous post may have been due to a parameterized test case.

when I run a simple test I get:

neotest-gtest: ...nvim/lazy/nvim-nio/lua/nio/init.lua:119: The coroutine failed with this message:
...nvim/lazy/neotest-gtest/lua/neotest-gtest/utils.lua:82: attempt to index local 'path' (a nil value)
stack traceback:
        ...nvim/lazy/neotest-gtest/lua/neotest-gtest/utils.lua: in function 'normalize_path'
        ...nvim/lazy/neotest-gtest/lua/neotest-gtest/report.lua:25: in function 'position_id'
        ...nvim/lazy/neotest-gtest/lua/neotest-gtest/report.lua:18: in function 'new'
        ...nvim/lazy/neotest-gtest/lua/neotest-gtest/report.lua:219: in function 'results'
        ...nvim/lazy/neotest/lua/neotest/client/runner.lua:132: in function '_run_spec'
        ...nvim/lazy/neotest/lua/neotest/client/runner.lua:89: in function <...nvim/lazy/neotest/lua/neotest/client/runner.lua:88>

looks like the path is nil

alfaix commented 5 months ago

Heey @bartman, this seems to be the same issue as #14. I'm quite confident it is so I'll close this one - feel free to reopen if you think otherwise. The main solution there is to update your gtest library.

There is a way to implement a workaround by memorizing the path in the context when it is created. There's some legwork that would also need to be done to set up tests in CI with multiple versions of gtest. Unfortunately, these days it's very hard for me to find the time for this, and on top of that I don't really write much C++ anymore :/ I don't know when that that will change, but meanwhile if you (or anyone else) can submit a PR with the pointer above.