diff --git a/src/lib.rs b/src/lib.rs index 4b08745..e56ce8d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { diff --git a/tests/option_cmd_workspace_dependency_collision/Cargo.toml b/tests/option_cmd_workspace_dependency_collision/Cargo.toml new file mode 100644 index 0000000..c1d1968 --- /dev/null +++ b/tests/option_cmd_workspace_dependency_collision/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] + +members = [ + "cargo-rdme", + "dependent", +] diff --git a/tests/option_cmd_workspace_dependency_collision/README-expected.md b/tests/option_cmd_workspace_dependency_collision/README-expected.md new file mode 100644 index 0000000..bf59b45 --- /dev/null +++ b/tests/option_cmd_workspace_dependency_collision/README-expected.md @@ -0,0 +1,7 @@ + + +# Fake cargo-rdme + +This is a fake cargo-rdme crate, designed to conflict with the one published on crates.io. + + diff --git a/tests/option_cmd_workspace_dependency_collision/README-template.md b/tests/option_cmd_workspace_dependency_collision/README-template.md new file mode 100644 index 0000000..3c52daa --- /dev/null +++ b/tests/option_cmd_workspace_dependency_collision/README-template.md @@ -0,0 +1 @@ + diff --git a/tests/option_cmd_workspace_dependency_collision/cargo-rdme/Cargo.toml b/tests/option_cmd_workspace_dependency_collision/cargo-rdme/Cargo.toml new file mode 100644 index 0000000..199cb34 --- /dev/null +++ b/tests/option_cmd_workspace_dependency_collision/cargo-rdme/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "cargo-rdme" +version = "9000.0.0" +edition = "2021" diff --git a/tests/option_cmd_workspace_dependency_collision/cargo-rdme/src/lib.rs b/tests/option_cmd_workspace_dependency_collision/cargo-rdme/src/lib.rs new file mode 100644 index 0000000..7467033 --- /dev/null +++ b/tests/option_cmd_workspace_dependency_collision/cargo-rdme/src/lib.rs @@ -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() {} diff --git a/tests/option_cmd_workspace_dependency_collision/dependent/Cargo.toml b/tests/option_cmd_workspace_dependency_collision/dependent/Cargo.toml new file mode 100644 index 0000000..6032113 --- /dev/null +++ b/tests/option_cmd_workspace_dependency_collision/dependent/Cargo.toml @@ -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" diff --git a/tests/option_cmd_workspace_dependency_collision/dependent/src/lib.rs b/tests/option_cmd_workspace_dependency_collision/dependent/src/lib.rs new file mode 100644 index 0000000..8f3b7ef --- /dev/null +++ b/tests/option_cmd_workspace_dependency_collision/dependent/src/lib.rs @@ -0,0 +1 @@ +fn foo() {} diff --git a/tests/tests.rs b/tests/tests.rs index a263e72..d7c5193 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -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");