rcarriga / vim-ultest

The ultimate testing plugin for (Neo)Vim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rust tests with mod names other that default 'mod tests' filtered out and not run.

russ-dm opened this issue · comments

Hi there, thanks for this super plugin.

I have encountered an issue with using the plugin to test Rust projects.

It appears that the code is trying to perform an --exact flagged cargo test with the incorrect mod name, ie:

cargo test tests::my_test_function -- --exact`

This causes the test case to be filtered out, instead of being run, which shows up as a always passing test.

I don't use a default 'tests' mod, but one named after the area I am testing, eg

mod widget_tests

Image

This means that the correct command should be:

cargo test my_specific_tests::my_test_function -- --exact

Multiple of these named modules can and do exist in the file being tested, as shown together with correct and current incorrect calls in the terminal alongside(after doing a Nearest Test) :
Image

An example of the correct terminal command running shown here:

image

One with the current incorrect invocation, using the hardcoded module tests and the result getting filtered out, over here:

image

I have uploaded the minimal test case repo here:
Link

Hope this explains the issue clearly enough, let me know if I can give any more details, thanks.

If I run the command:

cargo test -- -Z unstable-options --format json

I get the results:



{
  "type": "suite",
  "event": "started",
  "test_count": 3
}
{
  "type": "test",
  "event": "started",
  "name": "my_other_specific_tests::it_works"
}
{
  "type": "test",
  "event": "started",
  "name": "my_second_specific_tests::it_works"
}
{
  "type": "test",
  "event": "started",
  "name": "my_specific_tests::it_works"
}
{
  "type": "test",
  "name": "my_second_specific_tests::it_works",
  "event": "ok"
}
{
  "type": "test",
  "name": "my_other_specific_tests::it_works",
  "event": "failed",
  "stdout": "thread 'my_other_specific_tests::it_works' panicked at 'assertion failed: `(left == right)`\n  left: `2`,\n right: `4`', src/lib.rs:25:9\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n"
}
{
  "type": "test",
  "name": "my_specific_tests::it_works",
  "event": "failed",
  "stdout": "thread 'my_specific_tests::it_works' panicked at 'assertion failed: `(left == right)`\n  left: `2`,\n right: `4`', src/lib.rs:6:9\n"
}
{
  "type": "suite",
  "event": "failed",
  "passed": 1,
  "failed": 2,
  "ignored": 0,
  "measured": 0,
  "filtered_out": 0,
  "exec_time": 0.000321702
}

I put this here wondering if you think it's simpler making another test runner based on this command?

I believe this is a vim-test issue. You just need to update the regex used to match the namespace in the cargo file here https://github.com/vim-test/vim-test/blob/master/autoload/test/rust/cargotest.vim#L8. They'll be happy to take a PR, just make sure to add a test to handle the new case 😄