diff --git a/tests/testsuite/warn_on_failure.rs b/tests/testsuite/warn_on_failure.rs index 707a9d1d622d..42137e2c4efd 100644 --- a/tests/testsuite/warn_on_failure.rs +++ b/tests/testsuite/warn_on_failure.rs @@ -1,14 +1,11 @@ //! Tests for whether or not warnings are displayed for build scripts. -#![allow(deprecated)] - use cargo_test_support::registry::Package; -use cargo_test_support::{project, Project}; - -static WARNING1: &str = "Hello! I'm a warning. :)"; -static WARNING2: &str = "And one more!"; +use cargo_test_support::{project, str, Project}; fn make_lib(lib_src: &str) { + let warning1: &str = "Hello! I'm a warning. :)"; + let warning2: &str = "And one more!"; Package::new("bar", "0.0.1") .file( "Cargo.toml", @@ -33,7 +30,7 @@ fn make_lib(lib_src: &str) { println!("cargo::warning={{}}", "{}"); }} "#, - WARNING1, WARNING2 + warning1, warning2 ), ) .file("src/lib.rs", &format!("fn f() {{ {} }}", lib_src)) @@ -65,17 +62,16 @@ fn no_warning_on_success() { let upstream = make_upstream(""); upstream .cargo("build") - .with_stderr( - "\ -[UPDATING] `[..]` index + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index [LOCKING] 2 packages to latest compatible versions [DOWNLOADING] crates ... -[DOWNLOADED] bar v0.0.1 ([..]) +[DOWNLOADED] bar v0.0.1 (registry `dummy-registry`) [COMPILING] bar v0.0.1 -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -86,31 +82,55 @@ fn no_warning_on_bin_failure() { upstream .cargo("build") .with_status(101) - .with_stdout_does_not_contain("hidden stdout") - .with_stderr_does_not_contain("hidden stderr") - .with_stderr_does_not_contain(&format!("[WARNING] {}", WARNING1)) - .with_stderr_does_not_contain(&format!("[WARNING] {}", WARNING2)) - .with_stderr_contains("[UPDATING] `[..]` index") - .with_stderr_contains("[DOWNLOADED] bar v0.0.1 ([..])") - .with_stderr_contains("[COMPILING] bar v0.0.1") - .with_stderr_contains("[COMPILING] foo v0.0.1 ([..])") + .with_stdout_data("") + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[LOCKING] 2 packages to latest compatible versions +[DOWNLOADING] crates ... +[DOWNLOADED] bar v0.0.1 (registry `dummy-registry`) +[COMPILING] bar v0.0.1 +[COMPILING] foo v0.0.1 ([ROOT]/foo) +error[E0425]: cannot find function `hi` in this scope + --> src/main.rs:1:13 + | +1 | fn main() { hi() } + | ^^ not found in this scope + +For more information about this error, try `rustc --explain E0425`. +[ERROR] could not compile `foo` (bin "foo") due to 1 previous error + +"#]]) .run(); } #[cargo_test] fn warning_on_lib_failure() { - make_lib("err()"); + make_lib("hi()"); let upstream = make_upstream(""); upstream .cargo("build") .with_status(101) - .with_stdout_does_not_contain("hidden stdout") - .with_stderr_does_not_contain("hidden stderr") - .with_stderr_does_not_contain("[COMPILING] foo v0.0.1 ([..])") - .with_stderr_contains("[UPDATING] `[..]` index") - .with_stderr_contains("[DOWNLOADED] bar v0.0.1 ([..])") - .with_stderr_contains("[COMPILING] bar v0.0.1") - .with_stderr_contains(&format!("[WARNING] bar@0.0.1: {}", WARNING1)) - .with_stderr_contains(&format!("[WARNING] bar@0.0.1: {}", WARNING2)) + .with_stdout_data("") + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[LOCKING] 2 packages to latest compatible versions +[DOWNLOADING] crates ... +[DOWNLOADED] bar v0.0.1 (registry `dummy-registry`) +[COMPILING] bar v0.0.1 +error[E0425]: cannot find function `hi` in this scope + --> [ROOT]/home/.cargo/registry/src/-[HASH]/bar-0.0.1/src/lib.rs:1:10 + | +1 | fn f() { hi() } + | ^^ not found in this scope + +For more information about this error, try `rustc --explain E0425`. +The following warnings were emitted during compilation: + +[WARNING] bar@0.0.1: Hello! I'm a warning. :) +[WARNING] bar@0.0.1: And one more! + +[ERROR] could not compile `bar` (lib) due to 1 previous error + +"#]]) .run(); }