From f8df39b133a8b54b3bd702e4503c659052a2c753 Mon Sep 17 00:00:00 2001 From: Lin Yihai Date: Thu, 5 Sep 2024 14:44:52 +0800 Subject: [PATCH] test: Add a test for issue #14227 --- tests/testsuite/binary_name.rs | 185 +++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) diff --git a/tests/testsuite/binary_name.rs b/tests/testsuite/binary_name.rs index 8cf321b1d..a93e4abcc 100644 --- a/tests/testsuite/binary_name.rs +++ b/tests/testsuite/binary_name.rs @@ -2,6 +2,7 @@ use cargo_test_support::install::assert_has_installed_exe; use cargo_test_support::install::assert_has_not_installed_exe; +use cargo_test_support::is_nightly; use cargo_test_support::paths; use cargo_test_support::prelude::*; use cargo_test_support::project; @@ -340,3 +341,187 @@ fn check_msg_format_json() { ) .run(); } + +#[cargo_test] +fn targets_with_relative_path_in_workspace_members() { + let p = project() + .file( + "Cargo.toml", + r#" + [workspace] + members = ["relative-bar"] + resolver = "2" + "#, + ) + .file( + "relative-bar/Cargo.toml", + r#" + [package] + name = "relative-bar" + version = "0.1.0" + edition = "2021" + + build = "./build.rs" + + [[bin]] + name = "bar" + path = "./src/main.rs" + + [lib] + name = "lib" + path = "./src/lib.rs" + + [[example]] + name = "example" + path = "./example.rs" + + [[test]] + name = "test" + path = "./test.rs" + + [[bench]] + name = "bench" + path = "./bench.rs" + "#, + ) + .file("relative-bar/build.rs", "fn main() { let a = 1; }") + .file("relative-bar/src/main.rs", "fn main() { let a = 1; }") + .file("relative-bar/src/lib.rs", "fn a() {}") + .file("relative-bar/example.rs", "fn main() { let a = 1; }") + .file( + "relative-bar/test.rs", + r#" + fn main() {} + + #[test] + fn test_a() { let a = 1; } + "#, + ) + .file( + "relative-bar/bench.rs", + r#" + #![feature(test)] + #[cfg(test)] + extern crate test; + + #[bench] + fn bench_a(_b: &mut test::Bencher) { let a = 1; } + "#, + ) + .build(); + + p.cargo("check") + .with_stderr_data(str![[r#" +... + --> relative-bar/./build.rs:1:17 +... + --> relative-bar/./src/lib.rs:1:4 +... + --> relative-bar/./src/main.rs:1:17 +... +"#]]) + .run(); + + p.cargo("check --example example") + .with_stderr_data(str![[r#" +... + --> relative-bar/./example.rs:1:17 +... +"#]]) + .run(); + + p.cargo("check --test test") + .with_stderr_data(str![[r#" +... + --> relative-bar/./test.rs:5:35 +... +"#]]) + .run(); + + if is_nightly() { + p.cargo("check --bench bench") + .with_stderr_data(str![[r#" +... + --> relative-bar/./bench.rs:7:58 +... +"#]]) + .run(); + } + + // Disable Cargo target auto-discovery. + p.change_file( + "relative-bar/Cargo.toml", + r#" + [package] + name = "relative-bar" + version = "0.1.0" + edition = "2021" + + autolib = false + autobins = false + autoexamples = false + autotests = false + autobenches = false + + build = "./build.rs" + + [[bin]] + name = "bar" + path = "./src/main.rs" + + [lib] + name = "lib" + path = "./src/lib.rs" + + [[example]] + name = "example" + path = "./example.rs" + + [[test]] + name = "test" + path = "./test.rs" + + [[bench]] + name = "bench" + path = "./bench.rs" + "#, + ); + + p.cargo("check") + .with_stderr_data(str![[r#" +... + --> relative-bar/./build.rs:1:17 +... + --> relative-bar/./src/lib.rs:1:4 +... + --> relative-bar/./src/main.rs:1:17 +... +"#]]) + .run(); + + p.cargo("check --example example") + .with_stderr_data(str![[r#" +... + --> relative-bar/./example.rs:1:17 +... +"#]]) + .run(); + + p.cargo("check --test test") + .with_stderr_data(str![[r#" +... + --> relative-bar/./test.rs:5:35 +... +"#]]) + .run(); + + if is_nightly() { + p.cargo("check --bench bench") + .with_stderr_data(str![[r#" +... + --> relative-bar/./bench.rs:7:58 +... +"#]]) + .run(); + } +}