Skip to content

Conversation

@lluki
Copy link

@lluki lluki commented Apr 22, 2022

Execute nearest fails when using a cargo workspace where the package name does not match the directory name fails. cargotest.vim uses the directory name, but a different package name can be specified in the Cargo.toml.
This PR determines the package name using cargo read-manifest.

A minimal example that is fixed by this PR:

Directory structure:

.
├── Cargo.toml
└── pack1
    ├── Cargo.toml
    └── src
        └── main.rs

Cargo.toml

[workspace]
members = [ "pack1", ]

pack1/Cargo.toml

[package]
name = "sim2"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

pack1/src/main.rs

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

// Execute nearest test on this line
#[test]
fn my_test() {}

@lluki
Copy link
Author

lluki commented Apr 22, 2022

Hm. Is adding a dependency to cargo an option for you?

@codeinabox
Copy link
Collaborator

Hm. Is adding a dependency to cargo an option for you?

Thank you for this! May I suggest trying to install Cargo as part of the before_script inside .travis.yml. Let me know how you get on

@codeinabox
Copy link
Collaborator

I think I have a solution to testing this where we can mock the system call. Could you provide an example of what is returned by cargo read-manifest

@nitnelave
Copy link

I think I have a solution to testing this where we can mock the system call. Could you provide an example of what is returned by cargo read-manifest

read-manifest is deprecated. The modern version is something along these lines:

cargo metadata --no-deps --offline --format-version 1

And it returns something like:

{
  "packages": [
    {
      "name": "sim2",
      "version": "0.1.0",
      "id": "sim2 0.1.0 (path+file:///project-root/pack1)",
      "manifest_path": "/project-root/pack1/Cargo.toml",
      "..."
    },
    "..."
  ],
  "workspace_members": [
    "sim2 0.1.0 (path+file:///project-root/pack1)",
    "..."
  ],
  "target_directory": "/project-root/target",
  "version": 1,
  "workspace_root": "/project-root"
}

Does that help?

@codeinabox
Copy link
Collaborator

Not forgotten about this, will have a look into it soon

@codeinabox
Copy link
Collaborator

I've made a start on trying to mock cargo with an alias though getting some errors, hopefully the answer will reveal itself tomorrow

Copy link
Collaborator

@codeinabox codeinabox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your patience on this, I've finally got the mock of cargo read-manifest working so that this should work on CI. However I've discovered that even with cargo installed, this PR is lacking a Cargo.toml in the fixture directory. Could you please add one and update the manifest mock accordingly?

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

Successfully merging this pull request may close these issues.

3 participants