Skip to content

Commit 0c8f556

Browse files
committed
test: Add a test for issue #14227
1 parent 7f44292 commit 0c8f556

File tree

1 file changed

+208
-0
lines changed

1 file changed

+208
-0
lines changed

tests/testsuite/binary_name.rs

+208
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,210 @@ 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+
[COMPILING] relative-bar v0.1.0 ([ROOT]/foo/relative-bar)
416+
[WARNING] unused variable: `a`
417+
--> relative-bar/./build.rs:1:17
418+
|
419+
1 | fn main() { let a = 1; }
420+
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
421+
|
422+
= [NOTE] `#[warn(unused_variables)]` on by default
423+
424+
[WARNING] `relative-bar` (build script) generated 1 warning
425+
[WARNING] function `a` is never used
426+
--> relative-bar/./src/lib.rs:1:4
427+
|
428+
1 | fn a() {}
429+
| ^
430+
|
431+
= [NOTE] `#[warn(dead_code)]` on by default
432+
433+
[WARNING] `relative-bar` (lib) generated 1 warning
434+
[WARNING] unused variable: `a`
435+
--> relative-bar/./src/main.rs:1:17
436+
|
437+
1 | fn main() { let a = 1; }
438+
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
439+
|
440+
= [NOTE] `#[warn(unused_variables)]` on by default
441+
442+
[WARNING] `relative-bar` (bin "bar") generated 1 warning
443+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
444+
445+
"#]])
446+
.run();
447+
448+
p.cargo("check --example example")
449+
.with_stderr_data(str![[r#"
450+
[WARNING] unused variable: `a`
451+
--> relative-bar/./build.rs:1:17
452+
|
453+
1 | fn main() { let a = 1; }
454+
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
455+
|
456+
= [NOTE] `#[warn(unused_variables)]` on by default
457+
458+
[WARNING] `relative-bar` (build script) generated 1 warning
459+
[WARNING] function `a` is never used
460+
--> relative-bar/./src/lib.rs:1:4
461+
|
462+
1 | fn a() {}
463+
| ^
464+
|
465+
= [NOTE] `#[warn(dead_code)]` on by default
466+
467+
[WARNING] `relative-bar` (lib) generated 1 warning
468+
[CHECKING] relative-bar v0.1.0 ([ROOT]/foo/relative-bar)
469+
[WARNING] unused variable: `a`
470+
--> relative-bar/./example.rs:1:17
471+
|
472+
1 | fn main() { let a = 1; }
473+
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
474+
|
475+
= [NOTE] `#[warn(unused_variables)]` on by default
476+
477+
[WARNING] `relative-bar` (example "example") generated 1 warning
478+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
479+
480+
"#]])
481+
.run();
482+
483+
p.cargo("check --test test").with_stderr_data(str![[r#"
484+
[WARNING] unused variable: `a`
485+
--> relative-bar/./build.rs:1:17
486+
|
487+
1 | fn main() { let a = 1; }
488+
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
489+
|
490+
= [NOTE] `#[warn(unused_variables)]` on by default
491+
492+
[WARNING] `relative-bar` (build script) generated 1 warning
493+
[WARNING] function `a` is never used
494+
--> relative-bar/./src/lib.rs:1:4
495+
|
496+
1 | fn a() {}
497+
| ^
498+
|
499+
= [NOTE] `#[warn(dead_code)]` on by default
500+
501+
[WARNING] `relative-bar` (lib) generated 1 warning
502+
[CHECKING] relative-bar v0.1.0 ([ROOT]/foo/relative-bar)
503+
[WARNING] unused variable: `a`
504+
--> relative-bar/./test.rs:5:35
505+
|
506+
5 | fn test_a() { let a = 1; }
507+
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
508+
|
509+
= [NOTE] `#[warn(unused_variables)]` on by default
510+
511+
[WARNING] `relative-bar` (test "test") generated 1 warning
512+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
513+
514+
"#]]).run();
515+
516+
if is_nightly() {
517+
p.cargo("check --bench bench").with_stderr_data(str![[r#"
518+
[WARNING] unused variable: `a`
519+
--> relative-bar/./build.rs:1:17
520+
|
521+
1 | fn main() { let a = 1; }
522+
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
523+
|
524+
= [NOTE] `#[warn(unused_variables)]` on by default
525+
526+
[WARNING] `relative-bar` (build script) generated 1 warning
527+
[WARNING] function `a` is never used
528+
--> relative-bar/./src/lib.rs:1:4
529+
|
530+
1 | fn a() {}
531+
| ^
532+
|
533+
= [NOTE] `#[warn(dead_code)]` on by default
534+
535+
[WARNING] `relative-bar` (lib) generated 1 warning
536+
[CHECKING] relative-bar v0.1.0 ([ROOT]/foo/relative-bar)
537+
[WARNING] unused variable: `a`
538+
--> relative-bar/./bench.rs:7:58
539+
|
540+
7 | fn bench_a(_b: &mut test::Bencher) { let a = 1; }
541+
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
542+
|
543+
= [NOTE] `#[warn(unused_variables)]` on by default
544+
545+
[WARNING] `relative-bar` (bench "bench") generated 1 warning
546+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
547+
548+
"#]]).run();
549+
}
550+
}

0 commit comments

Comments
 (0)