lawrence-laz / neotest-zig

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

No tests found when using neotest.run.run() #1

Closed freakmangd closed 1 year ago

freakmangd commented 1 year ago

Describe the bug Running lua require("neotest").run.run() gives the output No tests found. Running lua require("neotest").run.run(vim.fn.expand("%")) results in a forever pending result (see screenshot)

Expected behavior

A report of how many tests passed/failed

Screenshots

image

Environment

Additional context

The file was called main.zig and it was the only file in the folder

Installation using packer.nvim:

    use {
        "nvim-neotest/neotest",
        requires = {
            "lawrence-laz/neotest-zig",
            "nvim-lua/plenary.nvim",
            "nvim-treesitter/nvim-treesitter",
            "antoinemadec/FixCursorHold.nvim"
        },
        config = function()
            require("neotest").setup({
                adapters = {
                    require("neotest-zig"), -- Registration
                }
            })
        end
    }

The config option actually didnt seem to work so i made a file called /after/plugin/neotest.lua and put this in it:

local nt = require("neotest")

nt.setup({
    adapters = {
        require("neotest-zig"), -- Registration
    }
})

which actually runs

My :TSConfigInfo command gives this under ensure_installed: { "c", "lua", "vim", "query", "javascript", "rust", "zig", "cpp" }

lawrence-laz commented 1 year ago

Thanks for the report! I'll try to reproduce this on a clean windows machine soon

lawrence-laz commented 1 year ago

I was able to reproduce this and some more issues on windows with a bare config. All fixes are available in v1.0.4 and the tests seem to be running fine now: neotest-zig-win

Let me know if your issue is resolved

freakmangd commented 1 year ago

even with a bare config and reinstalling to v1.0.4 i still cant seem to get it to work 😅

im getting this log message when i try doing run.run() and then just "No tests found" every time afterward:

WARN | 2023-10-04T19:49:18Z-0400 | ...pack\packer\start\neotest/lua/neotest/lib/subprocess.lua:162 | CHILD | Error in remote call ...rrent\share\nvim\runtime/lua/vim/treesitter/language.lua:88: '' is not a valid language name
stack traceback:
    [C]: in function 'error'
    ...rrent\share\nvim\runtime/lua/vim/treesitter/language.lua:88: in function 'add'
    ...t\share\nvim\runtime/lua/vim/treesitter/languagetree.lua:98: in function 'get_string_parser'
    ...packer\start\neotest/lua/neotest/lib/treesitter/init.lua:119: in function 'get_parse_root'
    ...packer\start\neotest/lua/neotest/lib/treesitter/init.lua:160: in function 'parse_positions_from_string'
    ...packer\start\neotest/lua/neotest/lib/treesitter/init.lua:207: in function 'func'
    ...pack\packer\start\neotest/lua/neotest/lib/subprocess.lua:154: in function <...pack\packer\start\neotest/lua/neotest/lib/subprocess.lua:153>
    [C]: in function 'xpcall'
    ...pack\packer\start\neotest/lua/neotest/lib/subprocess.lua:153: in function <...pack\packer\start\neotest/lua/neotest/lib/subprocess.lua:152>

using it with my normal config seems to lag my neovim quite a bit and can occasionally freeze it

lawrence-laz commented 1 year ago

Huh, that's one of the issues I was solving in this commit. It was related to the library neotest uses not being able to recognize zig filetype. So I registered it manually on setup function.

Thinking about this again, setup function is probably not the best place, since your config probably doesn't call .setup() on neotest-zig instance.

Could you try calling the setup function to enable debug logs like so:

require("neotest").setup({
    adapters = {
        require("neotest-zig").setup({
            debug_log = true
        })
    }
})

If tests will get found then I just need to move that logic to a better location.

If the issue is still not resolved, could you then please attach the log that will get created after debug_log is set to true? The path of the log can be retrieved using :lua =(vim.fn.stdpath("data") .. "/neotest-zig.log")


EDIT: I just reproduced the issue when require'neotest-zig'.setup() is not called. I moved out the filetype registration logic to top level and now it seems to work without a call to .setup(). Could you try v1.0.5?

freakmangd commented 1 year ago

Ah yeah I wasnt calling setup, makes sense now. Good news is that v1.0.5 works with the single test file, so nice work! Although i dont see a way to use this for projects that have tests that depend on modules.