mrcjkb / rustaceanvim

🦀 Supercharge your Rust experience in Neovim! A heavily modified fork of rust-tools.nvim
GNU General Public License v2.0
1.79k stars 69 forks source link

[neotest+rstest] Misleading parametrized tests UI #530

Closed alfaix closed 2 months ago

alfaix commented 2 months ago

Have you read the docs and searched existing issues?

Neovim version (nvim -v)

v0.11.0-dev-7b7c95dac

Operating system/version

Ubuntu 22.04

Output of :checkhealth rustaceanvim

==============================================================================
rustaceanvim: require("rustaceanvim.health").check()

Checking for Lua dependencies ~
- OK [mfussenegger/nvim-dap](https://github.com/mfussenegger/nvim-dap) installed.

Checking external dependencies ~
- OK rust-analyzer: found rust-analyzer 1.81.0 (eeb90cd 2024-09-04)
- OK Cargo: found cargo 1.81.0 (2dbb1af80 2024-08-20)
- OK rustc: found rustc 1.81.0 (eeb90cda1 2024-09-04)
- OK debug adapter: found codelldb 

Checking config ~
- OK No errors found in config.

Checking for conflicting plugins ~
- OK No conflicting plugins detected.

Checking for tree-sitter parser ~
- OK tree-sitter parser for Rust detected.

How to reproduce the issue

cargo new repro
cd repro
cargo add rstest
cat <<EOF > src/main.rs
#[cfg(test)]
mod test {
    use rstest::*;
    #[rstest]
    #[case(1)]
    #[case(2)]
    #[case(3)]
    #[case(4)]
    fn test_stuff(#[case] a: i32) {
        assert_eq!(a, 4);
    }
}

fn main() {
    println!("Hello, world!");
}
EOF
vim -u ../minconfig.lua src/main.rs
:Neotest summary
# navigate to the summary window, run test (`r`)
:Neotest run
# try running this command on each case line - only last case will be executed

Expected behaviour

Test cases should be treated as if they are separate tests:

  1. Running nearest should run nearest case, not the last one
  2. Running multiple cases should display status against each case separately

I think this comes from the overlapping (or empty) text range for test cases.

Actual behaviour

The cases are treated as if it's just one test by the main-editor UI. Examples: running all tests (shows checkmark next to the test, should be a cross) running nearest test when cursor is at a case line runs the last test image

I understand this is a minor issue, but I usually don't use the summary window (just run file-run nearest), and I just spent ~15 minutes trying to understand why a test was failing assuming another test I ran before was successful, but turns out that test never ran at all. I think in neotest this should be doable if the range for a test supplied is limited to one line (the #[case] line), or just the #[case] statement in case they are on the same line.

The minimal config used to reproduce this issue.

vim.env.lazy_stdpath = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    {
      "mrcjkb/rustaceanvim",
      version = "^5",
      init = function()
        -- configure rustaceanvim here
        vim.g.rustaceanvim = {}
      end,
      lazy = false,
    },
    {
      "nvim-neotest/neotest",
      dependencies = {
        "nvim-neotest/nvim-nio",
        "nvim-lua/plenary.nvim",
        "antoinemadec/fixcursorhold.nvim",
        "nvim-treesitter/nvim-treesitter",
      },
      opts = function()
        return { adapters = {
          require("rustaceanvim.neotest"),
        } }
      end,
      lazy = false,
    },
  },
})
mrcjkb commented 2 months ago

Hey :wave:

rustaceanvim gets the test positions from rust-analyzer and isn't aware of different test frameworks. So I'm afraid this can only be solved upstream, in rust-analyzer.

Regarding more reliable parsing of the test results: That will be solved when #462 has been implemented. I don't know when I'll have time for that, but it is on my radar.