Skip to content

Commit da833c5

Browse files
committed
test(run): Show ambiguous package name errors
1 parent 92a5d5e commit da833c5

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

tests/testsuite/run.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,82 @@ Available example targets:
779779
780780
[HELP] a target with a similar name exists: `a`
781781
782+
"#]])
783+
.run();
784+
}
785+
786+
#[cargo_test]
787+
fn ambiguous_bin_name() {
788+
let p = project()
789+
.file(
790+
"Cargo.toml",
791+
r#"
792+
[workspace]
793+
resolver = "3"
794+
members = ["crate1", "crate2", "crate3", "crate4"]
795+
"#,
796+
)
797+
.file("crate1/src/bin/ambiguous.rs", "fn main(){}")
798+
.file(
799+
"crate1/Cargo.toml",
800+
r#"
801+
[package]
802+
name = "crate1"
803+
version = "0.1.0"
804+
edition = "2024"
805+
"#,
806+
)
807+
.file("crate2/src/bin/ambiguous.rs", "fn main(){}")
808+
.file(
809+
"crate2/Cargo.toml",
810+
r#"
811+
[package]
812+
name = "crate2"
813+
version = "0.1.0"
814+
edition = "2024"
815+
"#,
816+
)
817+
.file("crate3/src/bin/ambiguous.rs", "fn main(){}")
818+
.file(
819+
"crate3/Cargo.toml",
820+
r#"
821+
[package]
822+
name = "crate3"
823+
version = "0.1.0"
824+
edition = "2024"
825+
"#,
826+
)
827+
.file("crate4/src/bin/ambiguous.rs", "fn main(){}")
828+
.file(
829+
"crate4/Cargo.toml",
830+
r#"
831+
[package]
832+
name = "crate4"
833+
version = "0.1.0"
834+
edition = "2024"
835+
"#,
836+
);
837+
let p = p.build();
838+
839+
p.cargo("run --bin ambiguous")
840+
.with_status(101)
841+
.with_stderr_data(str![[r#"
842+
[ERROR] `cargo run` can run at most one executable, but multiple were specified
843+
844+
"#]])
845+
.run();
846+
847+
p.cargo("run --bin crate1/ambiguous")
848+
.with_status(101)
849+
.with_stderr_data(str![[r#"
850+
[ERROR] no bin target named `crate1/ambiguous` in default-run packages.
851+
Available bin targets:
852+
ambiguous
853+
ambiguous
854+
ambiguous
855+
ambiguous
856+
857+
782858
"#]])
783859
.run();
784860
}

0 commit comments

Comments
 (0)