Skip to content

Commit f8df39b

Browse files
committed
test: Add a test for issue #14227
1 parent 2fcc375 commit f8df39b

File tree

1 file changed

+185
-0
lines changed

1 file changed

+185
-0
lines changed

tests/testsuite/binary_name.rs

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use cargo_test_support::install::assert_has_installed_exe;
44
use cargo_test_support::install::assert_has_not_installed_exe;
5+
use cargo_test_support::is_nightly;
56
use cargo_test_support::paths;
67
use cargo_test_support::prelude::*;
78
use cargo_test_support::project;
@@ -340,3 +341,187 @@ fn check_msg_format_json() {
340341
)
341342
.run();
342343
}
344+
345+
#[cargo_test]
346+
fn targets_with_relative_path_in_workspace_members() {
347+
let p = project()
348+
.file(
349+
"Cargo.toml",
350+
r#"
351+
[workspace]
352+
members = ["relative-bar"]
353+
resolver = "2"
354+
"#,
355+
)
356+
.file(
357+
"relative-bar/Cargo.toml",
358+
r#"
359+
[package]
360+
name = "relative-bar"
361+
version = "0.1.0"
362+
edition = "2021"
363+
364+
build = "./build.rs"
365+
366+
[[bin]]
367+
name = "bar"
368+
path = "./src/main.rs"
369+
370+
[lib]
371+
name = "lib"
372+
path = "./src/lib.rs"
373+
374+
[[example]]
375+
name = "example"
376+
path = "./example.rs"
377+
378+
[[test]]
379+
name = "test"
380+
path = "./test.rs"
381+
382+
[[bench]]
383+
name = "bench"
384+
path = "./bench.rs"
385+
"#,
386+
)
387+
.file("relative-bar/build.rs", "fn main() { let a = 1; }")
388+
.file("relative-bar/src/main.rs", "fn main() { let a = 1; }")
389+
.file("relative-bar/src/lib.rs", "fn a() {}")
390+
.file("relative-bar/example.rs", "fn main() { let a = 1; }")
391+
.file(
392+
"relative-bar/test.rs",
393+
r#"
394+
fn main() {}
395+
396+
#[test]
397+
fn test_a() { let a = 1; }
398+
"#,
399+
)
400+
.file(
401+
"relative-bar/bench.rs",
402+
r#"
403+
#![feature(test)]
404+
#[cfg(test)]
405+
extern crate test;
406+
407+
#[bench]
408+
fn bench_a(_b: &mut test::Bencher) { let a = 1; }
409+
"#,
410+
)
411+
.build();
412+
413+
p.cargo("check")
414+
.with_stderr_data(str![[r#"
415+
...
416+
--> relative-bar/./build.rs:1:17
417+
...
418+
--> relative-bar/./src/lib.rs:1:4
419+
...
420+
--> relative-bar/./src/main.rs:1:17
421+
...
422+
"#]])
423+
.run();
424+
425+
p.cargo("check --example example")
426+
.with_stderr_data(str![[r#"
427+
...
428+
--> relative-bar/./example.rs:1:17
429+
...
430+
"#]])
431+
.run();
432+
433+
p.cargo("check --test test")
434+
.with_stderr_data(str![[r#"
435+
...
436+
--> relative-bar/./test.rs:5:35
437+
...
438+
"#]])
439+
.run();
440+
441+
if is_nightly() {
442+
p.cargo("check --bench bench")
443+
.with_stderr_data(str![[r#"
444+
...
445+
--> relative-bar/./bench.rs:7:58
446+
...
447+
"#]])
448+
.run();
449+
}
450+
451+
// Disable Cargo target auto-discovery.
452+
p.change_file(
453+
"relative-bar/Cargo.toml",
454+
r#"
455+
[package]
456+
name = "relative-bar"
457+
version = "0.1.0"
458+
edition = "2021"
459+
460+
autolib = false
461+
autobins = false
462+
autoexamples = false
463+
autotests = false
464+
autobenches = false
465+
466+
build = "./build.rs"
467+
468+
[[bin]]
469+
name = "bar"
470+
path = "./src/main.rs"
471+
472+
[lib]
473+
name = "lib"
474+
path = "./src/lib.rs"
475+
476+
[[example]]
477+
name = "example"
478+
path = "./example.rs"
479+
480+
[[test]]
481+
name = "test"
482+
path = "./test.rs"
483+
484+
[[bench]]
485+
name = "bench"
486+
path = "./bench.rs"
487+
"#,
488+
);
489+
490+
p.cargo("check")
491+
.with_stderr_data(str![[r#"
492+
...
493+
--> relative-bar/./build.rs:1:17
494+
...
495+
--> relative-bar/./src/lib.rs:1:4
496+
...
497+
--> relative-bar/./src/main.rs:1:17
498+
...
499+
"#]])
500+
.run();
501+
502+
p.cargo("check --example example")
503+
.with_stderr_data(str![[r#"
504+
...
505+
--> relative-bar/./example.rs:1:17
506+
...
507+
"#]])
508+
.run();
509+
510+
p.cargo("check --test test")
511+
.with_stderr_data(str![[r#"
512+
...
513+
--> relative-bar/./test.rs:5:35
514+
...
515+
"#]])
516+
.run();
517+
518+
if is_nightly() {
519+
p.cargo("check --bench bench")
520+
.with_stderr_data(str![[r#"
521+
...
522+
--> relative-bar/./bench.rs:7:58
523+
...
524+
"#]])
525+
.run();
526+
}
527+
}

0 commit comments

Comments
 (0)