Skip to content

Commit f171e94

Browse files
committed
test: migrate warn_on_failure to snapbox
1 parent ed0c6eb commit f171e94

File tree

1 file changed

+52
-32
lines changed

1 file changed

+52
-32
lines changed

tests/testsuite/warn_on_failure.rs

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
//! Tests for whether or not warnings are displayed for build scripts.
22
3-
#![allow(deprecated)]
4-
53
use cargo_test_support::registry::Package;
6-
use cargo_test_support::{project, Project};
7-
8-
static WARNING1: &str = "Hello! I'm a warning. :)";
9-
static WARNING2: &str = "And one more!";
4+
use cargo_test_support::{project, str, Project};
105

116
fn make_lib(lib_src: &str) {
7+
let warning1: &str = "Hello! I'm a warning. :)";
8+
let warning2: &str = "And one more!";
129
Package::new("bar", "0.0.1")
1310
.file(
1411
"Cargo.toml",
@@ -33,7 +30,7 @@ fn make_lib(lib_src: &str) {
3330
println!("cargo::warning={{}}", "{}");
3431
}}
3532
"#,
36-
WARNING1, WARNING2
33+
warning1, warning2
3734
),
3835
)
3936
.file("src/lib.rs", &format!("fn f() {{ {} }}", lib_src))
@@ -65,17 +62,16 @@ fn no_warning_on_success() {
6562
let upstream = make_upstream("");
6663
upstream
6764
.cargo("build")
68-
.with_stderr(
69-
"\
70-
[UPDATING] `[..]` index
65+
.with_stderr_data(str![[r#"
66+
[UPDATING] `dummy-registry` index
7167
[LOCKING] 2 packages to latest compatible versions
7268
[DOWNLOADING] crates ...
73-
[DOWNLOADED] bar v0.0.1 ([..])
69+
[DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
7470
[COMPILING] bar v0.0.1
75-
[COMPILING] foo v0.0.1 ([..])
76-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
77-
",
78-
)
71+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
72+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
73+
74+
"#]])
7975
.run();
8076
}
8177

@@ -86,31 +82,55 @@ fn no_warning_on_bin_failure() {
8682
upstream
8783
.cargo("build")
8884
.with_status(101)
89-
.with_stdout_does_not_contain("hidden stdout")
90-
.with_stderr_does_not_contain("hidden stderr")
91-
.with_stderr_does_not_contain(&format!("[WARNING] {}", WARNING1))
92-
.with_stderr_does_not_contain(&format!("[WARNING] {}", WARNING2))
93-
.with_stderr_contains("[UPDATING] `[..]` index")
94-
.with_stderr_contains("[DOWNLOADED] bar v0.0.1 ([..])")
95-
.with_stderr_contains("[COMPILING] bar v0.0.1")
96-
.with_stderr_contains("[COMPILING] foo v0.0.1 ([..])")
85+
.with_stdout_data("")
86+
.with_stderr_data(str![[r#"
87+
[UPDATING] `dummy-registry` index
88+
[LOCKING] 2 packages to latest compatible versions
89+
[DOWNLOADING] crates ...
90+
[DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
91+
[COMPILING] bar v0.0.1
92+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
93+
error[E0425]: cannot find function `hi` in this scope
94+
--> src/main.rs:1:13
95+
|
96+
1 | fn main() { hi() }
97+
| ^^ not found in this scope
98+
99+
For more information about this error, try `rustc --explain E0425`.
100+
[ERROR] could not compile `foo` (bin "foo") due to 1 previous error
101+
102+
"#]])
97103
.run();
98104
}
99105

100106
#[cargo_test]
101107
fn warning_on_lib_failure() {
102-
make_lib("err()");
108+
make_lib("hi()");
103109
let upstream = make_upstream("");
104110
upstream
105111
.cargo("build")
106112
.with_status(101)
107-
.with_stdout_does_not_contain("hidden stdout")
108-
.with_stderr_does_not_contain("hidden stderr")
109-
.with_stderr_does_not_contain("[COMPILING] foo v0.0.1 ([..])")
110-
.with_stderr_contains("[UPDATING] `[..]` index")
111-
.with_stderr_contains("[DOWNLOADED] bar v0.0.1 ([..])")
112-
.with_stderr_contains("[COMPILING] bar v0.0.1")
113-
.with_stderr_contains(&format!("[WARNING] [email protected]: {}", WARNING1))
114-
.with_stderr_contains(&format!("[WARNING] [email protected]: {}", WARNING2))
113+
.with_stdout_data("")
114+
.with_stderr_data(str![[r#"
115+
[UPDATING] `dummy-registry` index
116+
[LOCKING] 2 packages to latest compatible versions
117+
[DOWNLOADING] crates ...
118+
[DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
119+
[COMPILING] bar v0.0.1
120+
error[E0425]: cannot find function `hi` in this scope
121+
--> [ROOT]/home/.cargo/registry/src/-[HASH]/bar-0.0.1/src/lib.rs:1:10
122+
|
123+
1 | fn f() { hi() }
124+
| ^^ not found in this scope
125+
126+
For more information about this error, try `rustc --explain E0425`.
127+
The following warnings were emitted during compilation:
128+
129+
[WARNING] [email protected]: Hello! I'm a warning. :)
130+
[WARNING] [email protected]: And one more!
131+
132+
[ERROR] could not compile `bar` (lib) due to 1 previous error
133+
134+
"#]])
115135
.run();
116136
}

0 commit comments

Comments
 (0)