alfaix / neotest-gtest

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

Other test adapters fail to work when using gtest adapter #6

Closed ErezAmihud closed 1 year ago

ErezAmihud commented 1 year ago

Hi, When I use the gtest adapter, other adapters that I have just stop working (i.e. python adapter)

I suspect it is related to neotest version. What version do you use? thanks

ErezAmihud commented 1 year ago

Nevermind, it was a problem with order of calls to setup.

I use lazy.nvim, and apparently I should have called setup in the config part of neotest

meicale commented 1 month ago

Nevermind, it was a problem with order of calls to setup.

I use lazy.nvim, and apparently I should have called setup in the config part of neotest

Hi, I encounter the same problem and would you mind sharing your answer dealing with this problem? I am using lazyvim and using neotest-python as well. I tried several order in the apdapters. How to setup that? Thank you so much!

alfaix commented 1 month ago

Hey @meicale I can try to help, but I need to see your configuration of neotest, neotest-gtest, neotest-python, as well as the exact behavior you observe. Could you please share that, your neovim --version, and make sure that all of the plugins are on current master (:Lazy update)?

meicale commented 1 month ago

Thank you so much for you reply. I update all the plugin and my neovim version is:

❯ nvim --version
NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1693350652

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "
/nix/store/j3dbrk5h42k1b4mrmcl5nba9qndqkqji-neovim-unwrapped-0.9.4/share/nvim
"

Run :checkhealth for more info

Since I use different lua files for different languages, the related parts are these: for python

{
    "nvim-neotest/neotest",
    optional = true,
    dependencies = {
      "nvim-neotest/nvim-nio",
      "nvim-lua/plenary.nvim",
      "antoinemadec/FixCursorHold.nvim",
      "nvim-neotest/neotest-python",
    },
    opts = {
      adapters = {
        ["neotest-python"] = {
          dap = { justMyCode = false },
        },
      },
    },
  }

for cpp

{
    "nvim-neotest/neotest",
    dependencies = {
      "alfaix/neotest-gtest",
    },
    opts = {
      adapters = {
        ["neotest-gtest"] = {
          setup = {},
        },
      },
    },
  }

I also import the extra.test in lazyvim following this. This link may help. for lazy:

    { import = "lazyvim.plugins.extras.test.core" },
    { import = "custom.python" },
    -- FIXME: comment out next line if you want use neotest-pyhton
    { import = "custom.cpp" },

Either neotest-python or neotest-gtest works fine alone. But if I put them together like this, the neotest-python just can not find any tests and neotest-gtest still works. But neotest-python can work together with neotest-plenary. Thank you so much.

alfaix commented 1 month ago

I see. I might be missing something but the configuration seems incorrect. From neotest documentation, adapters needs to be a list:

require("neotest").setup({
  adapters = {
    require("neotest-python")({
      dap = { justMyCode = false },
    }),
    require("neotest-plenary"),
    require("neotest-vim-test")({
      ignore_file_types = { "python", "vim", "lua" },
    }),
  },
})

While upon merging your configuration, lazy will produce something like:

adapters = {
  ["neotest-gtest"] = {setup = {}},
  ["neotest-python"] = {dap = {justMyCode = false}},
}

You can change it to be a list by setting adapters = {require("adapter-for-this-language").setup({opts})}, though I'm also not sure if lazy will merge lists correctly and not just overwrite by key (which in both cases would be 1).

If this helps, I organize my config like so:

-- in cpp.lua
{
  "alfaix/neotest-gtest",
  opts = {...} -- your config
}
-- in test.lua
{
  `neotest/neotest`,
  config = function()
    require"neotest".setup({
      adapters = {require"neotest-gtest", require"neotest-python"}, -- ...
    })
  end,
}

Then lazy will take care of doing .setup(opts) for adapters upon require.

meicale commented 1 month ago

I tried to use the similar method using config = function() method. BUT, I still cannot use the neotest-python, and neotest-gtest works fine. IMO, the link(https://www.lazyvim.org/extras/test/core) explain how to merge opts and there may something goes wrong. Thank you all the same. the related code in lazyvim:


if opts.adapters then
    local adapters = {}
    for name, config in pairs(opts.adapters or {}) do
      if type(name) == "number" then
        if type(config) == "string" then
          config = require(config)
        end
        adapters[#adapters + 1] = config
      elseif config ~= false then
        local adapter = require(name)
        if type(config) == "table" and not vim.tbl_isempty(config) then
          local meta = getmetatable(adapter)
          if adapter.setup then
            adapter.setup(config)
          elseif adapter.adapter then
            adapter.adapter(config)
            adapter = adapter.adapter
          elseif meta and meta.__call then
            adapter(config)
          else
            error("Adapter " .. name .. " does not support setup")
          end
        end
        adapters[#adapters + 1] = adapter
      end
    end
    opts.adapters = adapters
  end