Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gen_rust_project: support unit tests #2909

Open
TheLortex opened this issue Oct 1, 2024 · 0 comments
Open

gen_rust_project: support unit tests #2909

TheLortex opened this issue Oct 1, 2024 · 0 comments

Comments

@TheLortex
Copy link

Currently, rules_rust's rust-project.json generation code does not provide enough information for rust-analyzer to know how to launch a unit test. It looks like this and tries to run cargo when clicking on Debug:
image

When it works, it should look like this and properly run the selected test:
image

Some investigation made me understand that the additional content is needed:

  • in the root object, provide a runnables list:
{
  "sysroot": "...",
  "sysroot_src": "...",
  "runnables": [
    {
      "program": "bazel",
      "args": [
        "test",
        "--test_output=streamed",
        "{label}",
        "--test_arg={test_id}",
        "--test_arg=--nocapture",
        "--test_arg=--color=always",
        "--test_arg=--exact"
      ],
      "cwd": "/Users/lucas/projets/issue-rust-analyzer-tests-bazel/",
      "kind": "testOne"
    }
  ],
  ...
  • for each crate, provide a build record:
   {  
      "display_name": "engine",
      "build": {
        "label": "//rs/engine:tests",
        "build_file": "/Users/lucas/projets/issue-rust-analyzer-tests-bazel/rs/engine/BUILD.bazel",
        "target_kind": "test"
      },
      ...

Is it already planned to add support for tests in cargoless setups ? Are there unexpected roadblocks ?

Here is the demo repository I have used to experiment with rust-project.json configuration. It's not usable as is, you need to run ./gen_rust_project.sh to obtain a version that works on your machine, then manually edit it to add the fields I describe above in the issue. https://github.com/TheLortex/issue-rust-analyzer-tests-bazel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant