rouge8 / neotest-rust

Neotest adapter for Rust, using cargo-nextest.
MIT License
91 stars 28 forks source link

No Tests found #36

Closed VoreckLukas closed 1 year ago

VoreckLukas commented 1 year ago

With lazy vim my config looks like this

    {
        "nvim-neotest/neotest",
        dependencies = {
            "nvim-lua/plenary.nvim",
            "nvim-treesitter/nvim-treesitter",
            "rouge8/neotest-rust"
        },
        keys = {
            { "<leader>ct", function()
                require("neotest").run.run()
            end, desc = "Closest test" },
            { "<leader>cT", function()
                require("neotest").run.run(vim.fn.expand("%"))
            end, desc = "All tests" }
        },
        opts = function()
            return {
                adapers = require("neotest-rust")
            }
        end,
        config = function ()
            require("neotest").setup {
                require("neotest-rust")
            }
        end
    }

I have tree sitte for rust installed. When I press ct in this file

pub fn add(left: usize, right: usize) -> usize {
    left + right
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);
    }
}

I get no Tests found

rouge8 commented 1 year ago

I'm not sure, I don't use lazy vim.

MunifTanjim commented 1 year ago

That config doesn't look right at all.

Just try this:

    config = function()
      require("neotest").setup({
        adapters = {
          require("neotest-rust"),
        },
      })
    end,

and get rid of opts.

VoreckLukas commented 1 year ago

That config doesn't look right at all.

Just try this:

    config = function()
      require("neotest").setup({
        adapters = {
          require("neotest-rust"),
        },
      })
    end,

and get rid of opts.

Okay so this seems to work

return {
    {
        "nvim-neotest/neotest",
        dependencies = {
            "nvim-lua/plenary.nvim",
            "nvim-treesitter/nvim-treesitter",
            "rouge8/neotest-rust"
        },
        keys = {
            { "<leader>ct", function()
                require("neotest").run.run()
            end, desc = "Closest test" },
            { "<leader>cT", function()
                require("neotest").run.run(vim.fn.expand("%"))
            end, desc = "All tests" }
        },
        config = function ()
            require("neotest").setup({
                adapters = {
                    require("neotest-rust")
                }
            })
        end
    }
}

But im curious why it doesnt work with opts

return {
    {
        "nvim-neotest/neotest",
        dependencies = {
            "nvim-lua/plenary.nvim",
            "nvim-treesitter/nvim-treesitter",
            "rouge8/neotest-rust"
        },
        keys = {
            { "<leader>ct", function()
                require("neotest").run.run()
            end, desc = "Closest test" },
            { "<leader>cT", function()
                require("neotest").run.run(vim.fn.expand("%"))
            end, desc = "All tests" }
        },
        opts = function()
            return {
                adapers = {
                    require("neotest-rust")
                }
            }
        end,
}

As far as I understand lazy vim this should call

require("neotest").setup

with the table returned by opts as a parameter

MunifTanjim commented 1 year ago

But im curious why it doesnt work with opts

That'd be a question for the https://github.com/folke/lazy.nvim repo. I don't use the opts key much, so don't know.