Skip to content

Commit

Permalink
Fix duplicate src/main.rs discovery (#51)
Browse files Browse the repository at this point in the history
If a `[[bin]]` for `src/main.rs` is explicitly declared with a different name than the crate the code would previously add two entries to the `bin` field of the `Manifest`. This commit fixes the discovery by only comparing the paths, but not the names of the discovered targets.
  • Loading branch information
Turbo87 authored Aug 21, 2024
1 parent 00bef13 commit 37530d0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,10 @@ fn process_discovered_targets(

if add_discovered_targets {
for discovered_target in discovered_targets {
if targets.iter().any(|b| {
b.name.as_deref() == Some(&discovered_target.name)
&& b.path.as_deref() == Some(&discovered_target.path)
}) {
if targets
.iter()
.any(|b| b.path.as_deref() == Some(&discovered_target.path))
{
continue;
}

Expand Down
33 changes: 33 additions & 0 deletions tests/autotarget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,36 @@ fn test_bin_module_example() {
insta::assert_snapshot!(format_products(&m.test), @"");
insta::assert_snapshot!(format_products(&m.bench), @"");
}

/// see <https://github.com/rust-lang/crates.io/issues/9222>
#[test]
fn test_data_encoding_bin() {
let manifest = r#"
[package]
name = "data-encoding-bin"
version = "0.3.4"
license = "MIT"
edition = "2021"
keywords = ["base-conversion", "encoding", "base64", "base32", "hex"]
categories = ["command-line-utilities", "encoding"]
readme = "README.md"
repository = "https://github.com/ia0/data-encoding"
description = "Swiss Army knife for data-encoding"
include = ["Cargo.toml", "LICENSE", "README.md", "src/main.rs"]
[[bin]]
name = "data-encoding"
path = "src/main.rs"
[dependencies]
data-encoding = { version = "2.6.0", path = "../lib" }
getopts = "0.2"
"#;
let tempdir = utils::prepare(manifest, vec!["src/main.rs"]);
let m = Manifest::from_path(tempdir.path().join("Cargo.toml")).unwrap();
assert!(m.lib.is_none());
insta::assert_snapshot!(format_products(&m.bin), @"data-encoding → src/main.rs");
insta::assert_snapshot!(format_products(&m.example), @"");
insta::assert_snapshot!(format_products(&m.test), @"");
insta::assert_snapshot!(format_products(&m.bench), @"");
}

0 comments on commit 37530d0

Please sign in to comment.