test: Add a test for issue #14227

This commit is contained in:
Lin Yihai 2024-09-05 14:44:52 +08:00
parent 2fcc3755a3
commit f8df39b133

View File

@ -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();
}
}