Skip to content

Commit

Permalink
Update & Add tests for wrong target paths
Browse files Browse the repository at this point in the history
  • Loading branch information
CPerezz committed Jan 31, 2021
1 parent 9ae5239 commit 5ba1412
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 5 deletions.
51 changes: 51 additions & 0 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1755,3 +1755,54 @@ fn json_artifact_includes_executable_for_benchmark() {
)
.run();
}

#[cargo_test]
fn external_bench_warns_wrong_path() {
if !is_nightly() {
return;
}

let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
[[bench]]
name = "external"
"#,
)
.file(
"src/lib.rs",
r#"
#![feature(test)]
#[cfg(test)]
extern crate test;
pub fn get_hello() -> &'static str { "Hello" }
"#,
)
.file(
"./bench/external.rs",
r#"
#![feature(test)]
#[allow(unused_extern_crates)]
extern crate foo;
extern crate test;
#[bench]
fn external_bench(_b: &mut test::Bencher) {()}
"#,
)
.build();

p.cargo("bench")
.with_status(101)
.with_stderr_contains(
"[..]can't find `[..]` bench at `[..]`, specify [..] if you want to use a non-default path",
)
.run();
}
34 changes: 29 additions & 5 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,7 @@ fn non_existing_example() {
[ERROR] failed to parse manifest at `[..]`
Caused by:
can't find `hello` example, specify example.path",
can't find `[..]` example at `[..]`, specify [..] if you want to use a non-default path",
)
.run();
}
Expand All @@ -1869,7 +1869,7 @@ fn non_existing_binary() {
[ERROR] failed to parse manifest at `[..]`
Caused by:
can't find `foo` bin, specify bin.path",
can't find `[..]` bin at `[..]`, specify [..] if you want to use a non-default path",
)
.run();
}
Expand Down Expand Up @@ -4220,7 +4220,7 @@ fn no_bin_in_src_with_lib() {
[ERROR] failed to parse manifest at `[..]`
Caused by:
can't find `foo` bin, specify bin.path",
can't find `[..]` bin at `[..]`, specify [..] if you want to use a non-default path",
)
.run();
}
Expand Down Expand Up @@ -4397,7 +4397,7 @@ fn same_metadata_different_directory() {
}

#[cargo_test]
fn building_a_dependent_crate_witout_bin_should_fail() {
fn building_a_dependent_crate_without_bin_should_fail() {
Package::new("testless", "0.1.0")
.file(
"Cargo.toml",
Expand Down Expand Up @@ -4430,7 +4430,7 @@ fn building_a_dependent_crate_witout_bin_should_fail() {

p.cargo("build")
.with_status(101)
.with_stderr_contains("[..]can't find `a_bin` bin, specify bin.path")
.with_stderr_contains("[..]can't find `[..]` bin at `[..]`, specify [..] if you want to use a non-default path")
.run();
}

Expand Down Expand Up @@ -5438,3 +5438,27 @@ fn primary_package_env_var() {

foo.cargo("test").run();
}

#[cargo_test]
fn using_bins_instead_of_bin_is_warned_in_err() {
let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.1.0"
[[bin]]
name = "a_bin"
"#,
)
.file("src/lib.rs", "")
.file("bins/a_bin.rs", "fn main { () }")
.build();

p.cargo("build")
.with_status(101)
.with_stderr_contains("[..]can't find `[..]` bin at `[..]`, specify [..] if you want to use a non-default path")
.run();
}

0 comments on commit 5ba1412

Please sign in to comment.