Skip to content

Commit

Permalink
Rewrite select_package to only use workspace members
Browse files Browse the repository at this point in the history
  • Loading branch information
maackle committed Jun 10, 2024
1 parent 0907452 commit 3466c5f
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,9 @@ impl Project {
metadata: &'a cargo_metadata::Metadata,
package_name: &str,
) -> Option<&'a cargo_metadata::Package> {
let package = metadata.packages.iter().find(|package| package.name == package_name)?;

// We need to make sure the package we found is actually a project of the workspace.
match metadata.workspace_members.contains(&package.id) {
false => None,
true => Some(package),
}
metadata.packages.iter().find(|package| {
package.name == package_name && metadata.workspace_members.contains(&package.id)
})
}

pub fn from_current_dir_workspace_project(project_name: &str) -> Result<Project, ProjectError> {
Expand Down
6 changes: 6 additions & 0 deletions tests/option_cmd_workspace_dependency_collision/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]

members = [
"cargo-rdme",
"dependent",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- cargo-rdme start -->

# Fake cargo-rdme

This is a fake cargo-rdme crate, designed to conflict with the one published on crates.io.

<!-- cargo-rdme end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- cargo-rdme -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "cargo-rdme"
version = "9000.0.0"
edition = "2021"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! # Fake cargo-rdme
//!
//! This is a fake cargo-rdme crate, designed to conflict with the one published on crates.io.
fn foo() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "dependent"
version = "0.0.1"
edition = "2021"


[dependencies]
# Depends on a published version of a crate with a lower version than the one
# of the same name in this workspace
cargo-rdme = "1.4.3"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn foo() {}
12 changes: 12 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,18 @@ fn integration_test_option_cmd_workspace() {
run_test_with_options(test_name, &option);
}

#[test]
fn integration_test_option_cmd_workspace_dependency_collision() {
let test_name = "option_cmd_workspace_dependency_collision";

let option = TestOptions {
args: &["--workspace-project", "cargo-rdme", "--readme-path", "README.md"],
..TestOptions::default()
};

run_test_with_options(test_name, &option);
}

#[test]
fn integration_test_option_conf_file_intralinks_docs_rs_base_url() {
run_test("option_conf_file_intralinks_docs_rs_base_url");
Expand Down

0 comments on commit 3466c5f

Please sign in to comment.