Skip to content

Commit 92a5d5e

Browse files
committed
test(run): Move run-focused test with rest
1 parent 21f4080 commit 92a5d5e

File tree

2 files changed

+149
-149
lines changed

2 files changed

+149
-149
lines changed

tests/testsuite/run.rs

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,155 @@ Available example targets:
783783
.run();
784784
}
785785

786+
// See rust-lang/cargo#14544
787+
#[cargo_test]
788+
fn print_available_targets_within_virtual_workspace() {
789+
let p = project()
790+
.file(
791+
"Cargo.toml",
792+
r#"
793+
[workspace]
794+
resolver = "3"
795+
members = ["crate1", "crate2", "pattern1", "pattern2"]
796+
797+
default-members = ["crate1"]
798+
"#,
799+
)
800+
.file("crate1/src/main.rs", "fn main(){}")
801+
.file(
802+
"crate1/Cargo.toml",
803+
r#"
804+
[package]
805+
name = "crate1"
806+
version = "0.1.0"
807+
edition = "2024"
808+
"#,
809+
)
810+
.file("crate2/src/main.rs", "fn main(){}")
811+
.file(
812+
"crate2/Cargo.toml",
813+
r#"
814+
[package]
815+
name = "crate2"
816+
version = "0.1.0"
817+
edition = "2024"
818+
"#,
819+
)
820+
.file("pattern1/src/main.rs", "fn main(){}")
821+
.file(
822+
"pattern1/Cargo.toml",
823+
r#"
824+
[package]
825+
name = "pattern1"
826+
version = "0.1.0"
827+
edition = "2024"
828+
"#,
829+
)
830+
.file("pattern2/src/main.rs", "fn main(){}")
831+
.file(
832+
"pattern2/Cargo.toml",
833+
r#"
834+
[package]
835+
name = "pattern2"
836+
version = "0.1.0"
837+
edition = "2024"
838+
"#,
839+
)
840+
.file("another/src/main.rs", "fn main(){}")
841+
.file(
842+
"another/Cargo.toml",
843+
r#"
844+
[package]
845+
name = "another"
846+
version = "0.1.0"
847+
edition = "2024"
848+
"#,
849+
);
850+
851+
let p = p.build();
852+
p.cargo("run --bin")
853+
.with_status(101)
854+
.with_stderr_data(str![[r#"
855+
[ERROR] "--bin" takes one argument.
856+
Available binaries:
857+
crate1
858+
859+
860+
"#]])
861+
.run();
862+
863+
p.cargo("run -p crate1 --bin crate2")
864+
.with_status(101)
865+
.with_stderr_data(str![[r#"
866+
[ERROR] no bin target named `crate2` in `crate1` package
867+
868+
[HELP] a target with a similar name exists: `crate1`
869+
[HELP] Available bin in `crate2` package:
870+
crate2
871+
872+
"#]])
873+
.run();
874+
875+
p.cargo("check -p crate1 -p pattern1 -p pattern2 --bin crate2")
876+
.with_status(101)
877+
.with_stderr_data(str![[r#"
878+
[ERROR] no bin target named `crate2` in `crate1`, ... packages
879+
880+
[HELP] a target with a similar name exists: `crate1`
881+
[HELP] Available bin in `crate2` package:
882+
crate2
883+
884+
"#]])
885+
.run();
886+
887+
p.cargo("run --bin crate2")
888+
.with_status(101)
889+
.with_stderr_data(str![[r#"
890+
[ERROR] no bin target named `crate2` in default-run packages
891+
892+
[HELP] a target with a similar name exists: `crate1`
893+
[HELP] Available bin in `crate2` package:
894+
crate2
895+
896+
"#]])
897+
.run();
898+
899+
p.cargo("check --bin pattern*")
900+
.with_status(101)
901+
.with_stderr_data(str![[r#"
902+
[ERROR] no bin target matches pattern `pattern*` in default-run packages.
903+
[HELP] Available bin in `pattern1` package:
904+
pattern1
905+
[HELP] Available bin in `pattern2` package:
906+
pattern2
907+
908+
"#]])
909+
.run();
910+
911+
// This another branch that none of similar name exists, and print available targets in the
912+
// default-members.
913+
p.change_file(
914+
"Cargo.toml",
915+
r#"
916+
[workspace]
917+
resolver = "3"
918+
members = ["crate1", "crate2", "another"]
919+
920+
default-members = ["another"]
921+
"#,
922+
);
923+
924+
p.cargo("run --bin crate2")
925+
.with_status(101)
926+
.with_stderr_data(str![[r#"
927+
[ERROR] no bin target named `crate2` in default-run packages.
928+
[HELP] Available bin in `crate2` package:
929+
crate2
930+
931+
"#]])
932+
.run();
933+
}
934+
786935
#[cargo_test]
787936
fn either_name_or_example() {
788937
let p = project()

tests/testsuite/workspaces.rs

Lines changed: 0 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,152 +2716,3 @@ 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` in `crate1` package
2801-
2802-
[HELP] a target with a similar name exists: `crate1`
2803-
[HELP] Available bin in `crate2` package:
2804-
crate2
2805-
2806-
"#]])
2807-
.run();
2808-
2809-
p.cargo("check -p crate1 -p pattern1 -p pattern2 --bin crate2")
2810-
.with_status(101)
2811-
.with_stderr_data(str![[r#"
2812-
[ERROR] no bin target named `crate2` in `crate1`, ... packages
2813-
2814-
[HELP] a target with a similar name exists: `crate1`
2815-
[HELP] Available bin in `crate2` package:
2816-
crate2
2817-
2818-
"#]])
2819-
.run();
2820-
2821-
p.cargo("run --bin crate2")
2822-
.with_status(101)
2823-
.with_stderr_data(str![[r#"
2824-
[ERROR] no bin target named `crate2` in default-run packages
2825-
2826-
[HELP] a target with a similar name exists: `crate1`
2827-
[HELP] Available bin in `crate2` package:
2828-
crate2
2829-
2830-
"#]])
2831-
.run();
2832-
2833-
p.cargo("check --bin pattern*")
2834-
.with_status(101)
2835-
.with_stderr_data(str![[r#"
2836-
[ERROR] no bin target matches pattern `pattern*` in default-run packages.
2837-
[HELP] Available bin in `pattern1` package:
2838-
pattern1
2839-
[HELP] Available bin in `pattern2` package:
2840-
pattern2
2841-
2842-
"#]])
2843-
.run();
2844-
2845-
// This another branch that none of similar name exists, and print available targets in the
2846-
// default-members.
2847-
p.change_file(
2848-
"Cargo.toml",
2849-
r#"
2850-
[workspace]
2851-
resolver = "3"
2852-
members = ["crate1", "crate2", "another"]
2853-
2854-
default-members = ["another"]
2855-
"#,
2856-
);
2857-
2858-
p.cargo("run --bin crate2")
2859-
.with_status(101)
2860-
.with_stderr_data(str![[r#"
2861-
[ERROR] no bin target named `crate2` in default-run packages.
2862-
[HELP] Available bin in `crate2` package:
2863-
crate2
2864-
2865-
"#]])
2866-
.run();
2867-
}

0 commit comments

Comments
 (0)