-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: migrate warn_on_failure to snapbox
- Loading branch information
Showing
1 changed file
with
52 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] [email protected]: {}", WARNING1)) | ||
.with_stderr_contains(&format!("[WARNING] [email protected]: {}", 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] [email protected]: Hello! I'm a warning. :) | ||
[WARNING] [email protected]: And one more! | ||
[ERROR] could not compile `bar` (lib) due to 1 previous error | ||
"#]]) | ||
.run(); | ||
} |