Giter Club home page Giter Club logo

neotest-rust's Introduction

neotest-rust

Neotest adapter for Rust, using cargo-nextest.

Requires nvim-treesitter and the parser for Rust.

require("neotest").setup({
  adapters = {
    require("neotest-rust")
  }
})

If you wish to give additional arguments to the cargo nextest, you can specify the args when initializing the adapter.

require("neotest").setup({
  adapters = {
    require("neotest-rust") {
        args = { "--no-capture" },
    }
  }
})

Supports standard library tests, rstest, Tokio's [#tokio::test], and more. Does not support rstest's parametrized tests.

Debugging Tests

Codelldb is the default adapter used for debugging. Alternatives can be specified via the dap_adapter property during initialization.

require("neotest").setup({
  adapters = {
    require("neotest-rust") {
        args = { "--no-capture" },
        dap_adapter = "lldb",
    }
  }
})

See nvim-dap, and rust-tools#debugging if you are using rust-tools.nvim, for more information.

Limitations

The following limitations apply to both running and debugging tests.

  • Assumes unit tests in main.rs, mod.rs, and lib.rs are in a tests module.
  • Does not support rstest's #[case] macro.
  • When running tests for a main.rs in an integration test subdirectory (e.g. tests/testsuite/main.rs), all tests in that subdirectory will be run (e.g. all tests in tests/testsuite/). This is because Cargo lacks the capability to specify a test file.

Additionally, when debugging tests, no output from failed tests will be captured in the results provided to Neotest.

neotest-rust's People

Contributors

andy-bell101 avatar bram209 avatar danielvoogsgerd avatar dependabot[bot] avatar erezamihud avatar frederick888 avatar igorlfs avatar jesse-bakker avatar jsiefer avatar morgsmccauley avatar mrcjkb avatar muniftanjim avatar pre-commit-ci[bot] avatar rareitems avatar rouge8 avatar tkmpypy avatar tylersouthwick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

neotest-rust's Issues

"No tests found"

I'm getting a "No tests found" error. Tests run fine using vim-test, cargo test and cargo nextest run. See below for the example lib.rs that fails to run:

use std::env;
use std::error::Error;
use std::fs;

pub struct Config {
    pub filename: String,
    pub query: String,
    pub ignore_case: bool,
}
impl Config {
    pub fn new(args: &[String]) -> Result<Config, &'static str> {
        if args.len() < 3 {
            return Err("Not enough arguments");
        }
        let query = args[1].clone();
        let filename = args[2].clone();
        let ignore_case = env::var("IGNORE_CASE").is_ok();
        Ok(Config {
            filename,
            query,
            ignore_case,
        })
    }
}

pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
    let contents = fs::read_to_string(config.filename)?;
    for line in search(&config.query, &contents, config.ignore_case) {
        println!("{}", line);
    }
    Ok(())
}

pub fn search<'a>(query: &str, contents: &'a str, case_insensitive: bool) -> Vec<&'a str> {
    let query = if case_insensitive {
        query.to_lowercase()
    } else {
        query.to_string()
    };
    let mut results = vec![];
    if case_insensitive {
        for line in contents.lines() {
            if line.to_lowercase().contains(&query) {
                results.push(line);
            }
        }
    } else {
        for line in contents.lines() {
            if line.contains(&query) {
                results.push(line);
            }
        }
    }
    results
}

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

    #[test]
    fn case_sensitive_test() {
        let query = "duct";
        let contents = "\
Rust:
safe, fast, productive.
Duct tape.
Pick three.";
        assert_eq!(
            vec!["safe, fast, productive.",],
            search(query, contents, false)
        );
    }
    #[test]
    fn case_insensitive_test() {
        let query = "dUCt";
        let contents = "\
Rust:
safe, fast, productive.
Duct tape.
Pick three.";
        assert_eq!(
            vec!["safe, fast, productive.", "Duct tape."],
            search(query, contents, true)
        );
    }
}

Debug fails because `file_path` is nil

When trying to run a test with:

require("neotest").run.run_last({ strategy = "dap" })

I get:

neotest-rust: ...vis/.neovim/bundle/neotest/lua/neotest/lib/file/init.lua:22: attempt to concatenate local
 'file_path' (a nil value)

I know this is not much, I do not have rust-tools installed, maybe there is an undocumented dependency.

If it is needed:

dap.adapters.codelldb = {
    type = 'server',
    port = '${port}',
    executable = {
        -- CHANGE THIS to your path!
        command = '/home/notme/.local/share/nvim/mason/packages/codelldb/codelldb',
        args = { '--port', '${port}' },
    },
}

Any pointers where to look?

#.junit.xml: No such file or directory

I can't seem to get this working. When I run a test, I get an error saying that a file 3.junit.xml doesn't exist.

I searched for the issue and saw that someone reported an issue with it but they didn't have cargo-nextest installed. I do, v0.9.48.

Did I misconfigure something?

Running a single test fails

Hello, I have the following file:

use std::num::ParseIntError;
fn number_sum(data:&str) -> Result<u32, ParseIntError>{ 
    let mut ot = Vec::new();
    for line in data.split("\n"){
        ot.push(line.parse::<u32>()?);
    }
    Ok(ot.iter().sum())
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_number_list_sum_ok(){
        assert_eq!(number_sum("323\n392").unwrap(), 323+392);
    }
    #[test]
    fn test_number_list_sum_error(){
        assert!(number_sum("hi\n392").is_err());
    }
}

When trying to run only the test_number_list_sum_error test (via the neotest sidebar) I get the following error:

error: expected expression
   ╭────
 1 │ 'test(/tests::test_number_list_sum_error$/)'
   · ──────────────────────┬─────────────────────
   ·                       ╰── missing expression
   ╰────

  error: expected end of expression
   ╭────
 1 │ 'test(/tests::test_number_list_sum_error$/)'
   · ──────────────────────┬─────────────────────
   ·                       ╰── unparsed input
   ╰────

error: failed to parse filter expression

Or in a photo:

image

NOTE that when running the entire tests module everything works.

Running a single test breaks on fish

This is similar to #50 and also might have a similar fix to nvim-neotest/neotest-go#9.

I am having this error while using fish shell and running :lua require("neotest").run.run():

fish: $/ is not a valid variable in fish.
cargo nextest run --workspace --no-fail-fast --config-file /var/folders/j5/fyvk84zx4r7fpgfpzs7my4m40000gn/T/nvim.storopoli/B0RHTL/9.nextest.toml --profile neotest --test wallet -E "package(bdk) & test(/^test_bump_fee_reduce_change$/)"

We need to scape the $ sign with \$:

cargo nextest run --workspace --no-fail-fast --config-file /var/folders/j5/fyvk84zx4r7fpgfpzs7my4m40000gn/T/nvim.storopoli/B0RHTL/9.nextest.toml --profile neotest --test wallet -E "package(bdk) & test(/^test_bump_fee_reduce_change\$/)"
warning: some crates are on edition 2021 which defaults to `resolver = "2"`, but virtual workspaces default to `resolver = "1"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
warning: some crates are on edition 2021 which defaults to `resolver = "2"`, but virtual workspaces default to `resolver = "1"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
    Finished test [unoptimized + debuginfo] target(s) in 0.15s
    Starting 1 test across 1 binary (121 skipped)
        FAIL [   0.022s] bdk::wallet test_bump_fee_reduce_change

--- STDOUT:              bdk::wallet test_bump_fee_reduce_change ---

running 1 test
test test_bump_fee_reduce_change ... FAILED

failures:

failures:
    test_bump_fee_reduce_change

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 121 filtered out; finished in 0.02s


--- STDERR:              bdk::wallet test_bump_fee_reduce_change ---
thread 'test_bump_fee_reduce_change' panicked at 'called `Result::unwrap()` on an `Err` value: FeeRateTooLow { required: FeeRate(2.9230769) }', crates/bdk/tests/wallet.rs:1445:33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

------------
     Summary [   0.023s] 1 test run: 0 passed, 1 failed, 121 skipped
        FAIL [   0.022s] bdk::wallet test_bump_fee_reduce_change
error: test run failed

Running/listing tests in a workspace with a root package fails

Issue

It looks like cargo nextest list isn't listing tests in the workspace members when a root package is present: https://doc.rust-lang.org/cargo/reference/workspaces.html#root-package, e.g. https://github.com/rouge8/test-ws-rust

Original report

I ran into the issue today. I create a simple repo to help reproducing the problem at https://github.com/tuanbass/test-ws-rust

open foo/src/lib.rs and try to run the test.

But the fix, while necessary, still does not resolve the root cause. No more crash, but the test was not run.
The root cause seem is occurred when determined the cwd to run cargo nextest command for rust project with workspace enable.
When open such project, the cwd is set to root project's path not the member's one. Hence cargo nextest cannot found any test/test suite.

Originally posted by @tuanbass in #33 (comment)

Support for doctests?

It looks like neotest-rust doesn't detect doctests, would it be possible to support those as well?

Package name should be read from `Cargo.toml`

First of all, thank you for making this!

In my project, I have a workspace with a few crates. These crates have a different (shorter) folder name than their corresponding package names: https://github.com/bram209/leptosfmt/blob/main/formatter/Cargo.toml

Running a test in the formatter crate will result in the following filter expression:
package(formatter) & test(/^source_file::tests::multiple$/)

but it should be:
package(leptosfmt-formatter) & test(/^source_file::tests::multiple$/)

Error attempt to get length of field 'testsuite' (a nil value)

I have cargo workspace setup:

project/Cargo.toml
project/mylib/Cargo.toml
project/mylib/src/foo.rs

My test looks something like

// foo.rs
#[cfg(test)]
mod tests {
    use super::*;
  

    #[test]
    fn test_it_returns_something() {
        assert_eq!(true, true);
    }
}

I tried the following commands:

lua require('neotest').run.run()
lua require("neotest").run.run({vim.fn.expand("%")}) 

And I'm getting this error

Error executing vim.schedule lua callback: ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...l/share/nvim/lazy/neotest-rust/lua/neotest-rust/init.lua:253: attempt to get length of field 'testsuite' (a nil value)

When I try this:

lua require("neotest").run.run(vim.fn.getcwd())

Nothing happened.

I run this command from the project/mylib/

cargo nextest run test_it_returns_something

It works as expected.

I'm new to Rust/Cargo. Not sure if I can help you more.

Crash on running tests: attempt to index upvalue 'xml_etree'

I have a dead-simple Rust project with a single test file in tests/poker.rs. cargo nextest runs the tests just fine. When I run :lua require("neotest").run.run(vim.fn.expand("%")), I get:

Error executing vim.schedule lua callback: ...ck/packer/start/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...pack/packer/start/neotest-rust/lua/neotest-rust/init.lua:182: attempt to index upvalue 'xml_tree' (a function value)
stack traceback:
        [C]: in function 'error'
        ...ck/packer/start/plenary.nvim/lua/plenary/async/async.lua:18: in function 'callback_or_next'
        ...ck/packer/start/plenary.nvim/lua/plenary/async/async.lua:45: in function <...ck/packer/start/plenary.nvim/lua/plenary/async/async.lua:44>

Test cases from /target folder are extracted unnecessarily

It appears that neotest-rust might mistakenly be extracting test cases from .rs files within the rust-target folder.

Based on the information provided in https://github.com/nvim-neotest/neotest/blob/master/lua/neotest/adapters/interface.lua, the API offers a "filter_dir" method that allows an adapter to exclude specific folders from test cases. Neotest-python, for example, filters out the virtualenv directory "venv," as shown here: nvim-neotest/neotest-python@288e58b.

Perhaps neotest-rust should also filter the "target" folder or provide the filter configuration to the user, potentially in a format similar to how neotest-python exposes the "is_test_file" method (see https://github.com/nvim-neotest/neotest-python)

Tested with https://github.com/blaind/webp-animation/ :
image

Low performance in a large codebase and multi-crate workspace

Thank you for the excellent library.

I'm encountering an issue when running individual crate tests in a large codebase, and it's causing significant initial slowness. For instance, when working with the Bevy engine repository (https://github.com/bevyengine/bevy/), running tests only in the crates/bevy_app crate necessitates building all the examples, resulting in a target directory size of over 150GB and a substantial time investment. I've managed to improve the situation to some extent by adding an args = { "--lib" } flag, but the build process remains quite slow due to the workspace flag.

The root cause appears to be related to issue #27 and commit c8894d8.

Here are some statistics below, each run starting with a clean target folder.

Current neotest-rust flags (--workspace): very very slow

crates/bevy_app$ cargo nextest run --workspace app::
time taken: [very long time]
target folder size: > 100GB

Without workspace, with --lib: very fast

crates/bevy_app$ cargo nextest run --lib app:
Finished test [unoptimized + debuginfo] target(s) in 17.72s
target folder size: 496MB

No arguments

crates/bevy_app$ cargo nextest run
Finished test [unoptimized + debuginfo] target(s) in 17.14s
target folder size: 519MB

With --lib and --workspace: somewhat reasonable, but still slow

crates/bevy_app$ cargo nextest run --lib --workspace app::
Finished test [unoptimized + debuginfo] target(s) in 1m 36s
target folder size: 8.3GB

Treesitter query: invalid node type

Getting "No tests found", looking at neotest.log:

ERROR | 2022-11-08T08:06:37Z-0800 | ...te/pack/packer/start/neotest/lua/neotest/client/init.lua:274 | Couldn't find positions in path /Users/aiden/src/test-neotest/src/lib.rs /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 33 for language rust

I opened up the :TSPlaygroundToggle and looked at what treesitter was showing for a simple test (cargo new --lib ...):
Screen Shot 2022-11-08 at 8 03 40 AM

I got a working treesitter query to capture tests using the following:

Untitled

Is perhaps the treesitter query in this repo out of date with the latest grammar? Happy to submit a PR.

:version
NVIM v0.8.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /Library/Developer/CommandLineTools/usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -O2 -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prot
otypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DI
NCLUDE_GENERATED_DECLARATIONS -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/Users/aiden/src/neovim/build/cmake.config -I/Users/aiden/src/neovim/src -I/Users/aiden/src/neovim/.deps/usr/include -I
/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include -I/usr/local/opt/gettext/include -I/Users/aiden/src/neovim/build/src/nvim/auto -I/Users/aiden/src/neovim/build/include
Compiled by [email protected]

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

  nvim-treesitter: require("nvim-treesitter.health").check()
  ========================================================================
  ## Installation
    - OK: `tree-sitter` found 0.20.6 (parser generator, only needed for :TSInstallFromGrammar)
    - OK: `node` found v19.0.1 (only needed for :TSInstallFromGrammar)
    - OK: `git` executable found.
    - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
      Version: Apple clang version 14.0.0 (clang-1400.0.29.102)
    - OK: Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.
  vim.treesitter: require("vim.treesitter.health").check()
  ========================================================================
    - INFO: Runtime ABI version : 14
    - OK: Loaded parser for bash: ABI version 14
    - OK: Loaded parser for c: ABI version 13
    - OK: Loaded parser for clojure: ABI version 13                                                                                                                                                                               - OK: Loaded parser for css: ABI version 13
    - OK: Loaded parser for dockerfile: ABI version 13
    - OK: Loaded parser for elixir: ABI version 14
    - OK: Loaded parser for erlang: ABI version 13
    - OK: Loaded parser for go: ABI version 14
    - OK: Loaded parser for graphql: ABI version 13
    - OK: Loaded parser for hcl: ABI version 13
    - OK: Loaded parser for heex: ABI version 14
    - OK: Loaded parser for help: ABI version 14
    - OK: Loaded parser for html: ABI version 13
    - OK: Loaded parser for javascript: ABI version 13
    - OK: Loaded parser for json: ABI version 13
    - OK: Loaded parser for lua: ABI version 13
    - OK: Loaded parser for python: ABI version 14
    - OK: Loaded parser for query: ABI version 14
    - OK: Loaded parser for ruby: ABI version 13
    - OK: Loaded parser for rust: ABI version 13
    - OK: Loaded parser for svelte: ABI version 13
    - OK: Loaded parser for toml: ABI version 13
    - OK: Loaded parser for tsx: ABI version 13
    - OK: Loaded parser for typescript: ABI version 14
    - OK: Loaded parser for vim: ABI version 14
    - OK: Loaded parser for yaml: ABI version 13
    - OK: Loaded parser for c: ABI version 13
    - OK: Loaded parser for help: ABI version 14
    - OK: Loaded parser for lua: ABI version 13
    - OK: Loaded parser for vim: ABI version 14

Confirmed that if I edit init.lua and replace the treesitter query with the following, it works:

(
  (attribute_item
    (meta_item
      (identifier) @macro_name
    )
  )+
  .
  (function_item
    name: (identifier) @test.name
  ) @test.definition
  (#contains? @macro_name "test" "rstest" "case")
)
(mod_item name: (identifier) @namespace.name)? @namespace.definition

Tests don't run; 2.junit.xml: No such file or directory

I'm just giving neotest a whirl for the first time, trying it out with some Rust unit tests. I'm on nvim 0.7.2 on macOS 12.5.1.

I have these mappings:

        vim.keymap.set("n", "<leader>tn", neotest.run.run)
        vim.keymap.set("n", "<leader>tf", "neotest.run.run(vim.fn.expand('%'))")
        vim.keymap.set("n", "<leader>td", "neotest.run.run({strategy = 'dap'})")

When I try to run the nearest test, I get: E486: Pattern not found: float. Not sure what that means, but seems like it could something with my config. The problem that seems a bit more straightforward is when I try to run tests for the file, I get:

neotest-rust: ...acker/start/plenary.nvim/lua/plenary/context_manager.lua:47: /var/folders/k9/xm7wlry90z3fjwl909bs1bb80000gp/T/nvimF2oxR3/2.junit.xml: No such file or directory

I see a reference to junit here; seems a bit odd to require anything junit for testing rust, no?

Tests with `#[should_panic]` macro are ignored

Adding the #[should_panic] macro, below the #[test] macro, to an existing test causes it to be ignored. Replacing the order, i.e. #[should_panic] followed by #[test] on the next line, seems to work.

This seems to be related to the treesitter query which looks for the #[test] macro on a function. Perhaps it just picks up the first macro defined?

Unable to parse the test

Hi,

I have this simple test:
image

And I am getting this error:
image

When I run all the tests for the file it says there are no tests. It seems like it is unable to parse/find my tests.

Also, when I run "cargo nextest r" it passes.

My config:

image

Can you tell me what am I doing wrong?

Thanks!

No Tests found

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

Not works run tests

When I try to run the test, I get an error message:

Error executing vim.schedule lua callback: ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...e/nvim/lazy/plenary.nvim/lua/plenary/context_manager.lua:47: /var/folders/z5/sp9btnks26sbh__fhy
tbhshc0000gn/T/nvim.ivan/B62x0s/19.junit.xml: No such file or directory
stack traceback:
        [C]: in function 'error'
        ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: in function 'callback_or_next'
        ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:45: in function <...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:44>

My test code:

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
    }
}

But this error I have only in Rust, in Go works good.

Here is my Neovim config.

Failed to run test after recent upgrade.

neotest-rust: ...uzhiping/.local/share/nvim/lazy/neotest/lua/nio/init.lua:105: The coroutine failed with this message:
...share/nvim/lazy/neotest-rust/lua/neotest-rust/errors.lua:7: attempt to index local 'output' (a nil value)
stack traceback:
        ...share/nvim/lazy/neotest-rust/lua/neotest-rust/errors.lua: in function 'parse_errors'
        ...l/share/nvim/lazy/neotest-rust/lua/neotest-rust/init.lua:380: in function 'results'
        ...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:131: in function '_run_spec'
        ...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:89: in function <...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:88>
Press ENTER or type command to continue

running the whole test suite

I thought I'd give it a shot to implement running the whole test suite, but I don't find a good entry point. I was wondering if you could give me a hint if you already know where the problem is?

For clarification, I am talking about require("neotest").run.run(vim.fn.getcwd()) returning No tests found.

Issues with workspaces

I have issues with workspaces which might be related to this plugin. More specifically, if I open neovim inside my workspace folder, everything works as expected. However, when I open neovim in a subfolder of that workspace and try to run tests or open the test tree with neotest, neovim crashes. Is this a known issue? I have had trouble to trace this to a single function, I tried reading the crash dumps of neovim, but it does not contain any useful information. I think the best behaviour, if that is possible, would also be to only run the tests of that subpackage in the workspace, if I open neovim in that subfolder.

OS: Ubuntu 22.04
neovim version: v0.9.4

neotest-rust: ...plenary/context_manager.lua:47: /tmp/nvimXXXXXX/2: No such file or directory

Hi! This project looks super cool and it looks like it's brand new! Super excited to try it out. I've run into an issue when running it, so I thought I'd post here :)

❯ rustc --version
rustc 1.62.0
❯ cargo --version
cargo 1.62.0
❯ cargo nextest --version
cargo-nextest 0.9.14
❯ cargo nextest run
   Compiling rust v0.1.0 (/home/tanner/projects/tmp)
    Finished test [unoptimized + debuginfo] target(s) in 0.24s
  Executable unittests src/lib.rs (target/debug/deps/rust-7e43bc118666ed88)
    Starting 1 tests across 1 binaries
        PASS [   0.001s] rust tests::test_thing
     Summary [   0.002s] 1 tests run: 1 passed, 0 skipped
❯ nvim --version
NVIM v0.7.0

lib.rs

#[cfg(test)]
mod tests {
    #[test]
    fn test_thing() {
        assert!(true)
    }
}

Neotest-run command output in neovim:

neotest-rust: ...nager/start/plenary-nvim/lua/plenary/context_manager.lua:47: /tmp/nvimU923sF/2: No such file or directory   

Running with latest source (as of time of this post) of all:

  1. neotest rev = "2f5e9f634fd66351f323bd3c97eaa82f3dfbcb61"
  2. neotest-rust rev = "ae9539b4d4a213c08106d830db66795a42337092"
  3. plenary-nvim rev = "986ad71ae930c7d96e812734540511b4ca838aa2"

Running file doesn't work

Hi! First of all, thanks for making this plugin!

The tests seem to get skipped when I try and run all tests in the file with the recommended command:

lua require("neotest").run.run(vim.fn.expand("%"))

This is the output of neotest.output.open after running the command above, the test seems to have been skipped:

    Finished test [unoptimized + debuginfo] target(s) in 0.01s
    Starting 0 tests across 1 binary (1 skipped)
------------
     Summary [   0.000s] 0 tests run: 0 passed, 1 skipped

But when I run cargo nextest run the test gets run and passes:

    Finished test [unoptimized + debuginfo] target(s) in 0.01s
    Starting 1 test across 1 binary
        PASS [   0.005s] rust::bin/rust my_test
------------
     Summary [   0.005s] 1 test run: 1 passed, 0 skipped

To test I just ran cargo init and set main.rs to this:

fn main() {
    println!("Hello, world!");
}

#[test]
fn my_test() {
    assert_eq!(42, 42);
}

Here's my minimal config:

Click to expand
local function bootstrap_lazy()
  local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
  if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
      "git",
      "clone",
      "--filter=blob:none",
      "https://github.com/folke/lazy.nvim.git",
      "--branch=stable",
      lazypath,
    })
  end
  vim.opt.rtp:prepend(lazypath)
end
bootstrap_lazy()

require('lazy').setup({
  {
    'nvim-neotest/neotest',
    dependencies = { 'haydenmeade/neotest-jest', 'rouge8/neotest-rust', 'nvim-lua/plenary.nvim' },
    config = function()
      require('neotest').setup({
        adapters = {
          require("neotest-rust"),
        },
      })
    end,
  },
  {
    'nvim-treesitter/nvim-treesitter',
    build = ':TSUpdate',
    config = function()
      require 'nvim-treesitter.configs'.setup({
        ensure_installed = { 'rust' },
      })
    end,
  },
})

vim.keymap.set('n', '<C-q>', '<cmd>:qa!<CR>')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.