Skip to content

Commit 8b9dc21

Browse files
linyihaiYihai Lin
authored andcommitted
test(workspace): Add test about workspace
1 parent 19d3071 commit 8b9dc21

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed

tests/testsuite/workspaces.rs

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,3 +2716,146 @@ fn nonexistence_package_together_with_workspace() {
27162716
"#]])
27172717
.run();
27182718
}
2719+
2720+
// See rust-lang/cargo#14544
2721+
#[cargo_test]
2722+
fn print_available_targets_within_virtual_workspace() {
2723+
let p = project()
2724+
.file(
2725+
"Cargo.toml",
2726+
r#"
2727+
[workspace]
2728+
resolver = "3"
2729+
members = ["crate1", "crate2", "pattern1", "pattern2"]
2730+
2731+
default-members = ["crate1"]
2732+
"#,
2733+
)
2734+
.file("crate1/src/main.rs", "fn main(){}")
2735+
.file(
2736+
"crate1/Cargo.toml",
2737+
r#"
2738+
[package]
2739+
name = "crate1"
2740+
version = "0.1.0"
2741+
edition = "2024"
2742+
"#,
2743+
)
2744+
.file("crate2/src/main.rs", "fn main(){}")
2745+
.file(
2746+
"crate2/Cargo.toml",
2747+
r#"
2748+
[package]
2749+
name = "crate2"
2750+
version = "0.1.0"
2751+
edition = "2024"
2752+
"#,
2753+
)
2754+
.file("pattern1/src/main.rs", "fn main(){}")
2755+
.file(
2756+
"pattern1/Cargo.toml",
2757+
r#"
2758+
[package]
2759+
name = "pattern1"
2760+
version = "0.1.0"
2761+
edition = "2024"
2762+
"#,
2763+
)
2764+
.file("pattern2/src/main.rs", "fn main(){}")
2765+
.file(
2766+
"pattern2/Cargo.toml",
2767+
r#"
2768+
[package]
2769+
name = "pattern2"
2770+
version = "0.1.0"
2771+
edition = "2024"
2772+
"#,
2773+
)
2774+
.file("another/src/main.rs", "fn main(){}")
2775+
.file(
2776+
"another/Cargo.toml",
2777+
r#"
2778+
[package]
2779+
name = "another"
2780+
version = "0.1.0"
2781+
edition = "2024"
2782+
"#,
2783+
);
2784+
2785+
let p = p.build();
2786+
p.cargo("run --bin")
2787+
.with_status(101)
2788+
.with_stderr_data(str![[r#"
2789+
[ERROR] "--bin" takes one argument.
2790+
Available binaries:
2791+
crate1
2792+
2793+
2794+
"#]])
2795+
.run();
2796+
2797+
p.cargo("run -p crate1 --bin crate2")
2798+
.with_status(101)
2799+
.with_stderr_data(str![[r#"
2800+
[ERROR] no bin target named `crate2`
2801+
2802+
[HELP] a target with a similar name exists: `crate1`
2803+
2804+
"#]])
2805+
.run();
2806+
2807+
p.cargo("check -p crate1 -p pattern1 -p pattern2 --bin crate2")
2808+
.with_status(101)
2809+
.with_stderr_data(str![[r#"
2810+
[ERROR] no bin target named `crate2`
2811+
2812+
[HELP] a target with a similar name exists: `crate1`
2813+
2814+
"#]])
2815+
.run();
2816+
2817+
p.cargo("run --bin crate2")
2818+
.with_status(101)
2819+
.with_stderr_data(str![[r#"
2820+
[ERROR] no bin target named `crate2`
2821+
2822+
[HELP] a target with a similar name exists: `crate1`
2823+
2824+
"#]])
2825+
.run();
2826+
2827+
p.cargo("check --bin pattern*")
2828+
.with_status(101)
2829+
.with_stderr_data(str![[r#"
2830+
[ERROR] no bin target matches pattern `pattern*`.
2831+
Available bin targets:
2832+
crate1
2833+
2834+
2835+
"#]])
2836+
.run();
2837+
2838+
// This another branch that none of similar name exists, and print available targets in the
2839+
// default-members.
2840+
p.change_file(
2841+
"Cargo.toml",
2842+
r#"
2843+
[workspace]
2844+
resolver = "3"
2845+
members = ["crate1", "crate2", "another"]
2846+
2847+
default-members = ["another"]
2848+
"#,
2849+
);
2850+
2851+
p.cargo("run --bin crate2")
2852+
.with_status(101)
2853+
.with_stderr_data(str![[r#"
2854+
[ERROR] no bin target named `crate2`.
2855+
Available bin targets:
2856+
another
2857+
2858+
2859+
"#]])
2860+
.run();
2861+
}

0 commit comments

Comments
 (0)