Skip to content

Commit 7ee4aee

Browse files
committed
test: migrate cache_message to snapbox
1 parent e41c718 commit 7ee4aee

File tree

1 file changed

+114
-60
lines changed

1 file changed

+114
-60
lines changed

tests/testsuite/cache_messages.rs

Lines changed: 114 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Tests for caching compiler diagnostics.
22
3-
#![allow(deprecated)]
4-
53
use super::messages::raw_rustc_output;
4+
use cargo_test_support::str;
65
use cargo_test_support::tools;
76
use cargo_test_support::{basic_manifest, is_coarse_mtime, project, registry::Package, sleep_ms};
87

@@ -160,7 +159,16 @@ fn clears_cache_after_fix() {
160159
// Make sure the cache is invalidated when there is no output.
161160
let p = project().file("src/lib.rs", "fn asdf() {}").build();
162161
// Fill the cache.
163-
p.cargo("check").with_stderr_contains("[..]asdf[..]").run();
162+
p.cargo("check")
163+
.with_stderr_data(str![[r#"
164+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
165+
[WARNING] function `asdf` is never used
166+
...
167+
[WARNING] `foo` (lib) generated 1 warning
168+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
169+
170+
"#]])
171+
.run();
164172
let cpath = p
165173
.glob("target/debug/.fingerprint/foo-*/output-*")
166174
.next()
@@ -175,13 +183,12 @@ fn clears_cache_after_fix() {
175183
p.change_file("src/lib.rs", "");
176184

177185
p.cargo("check")
178-
.with_stdout("")
179-
.with_stderr(
180-
"\
181-
[CHECKING] foo [..]
182-
[FINISHED] [..]
183-
",
184-
)
186+
.with_stdout_data(str![[r#""#]])
187+
.with_stderr_data(str![[r#"
188+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
189+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
190+
191+
"#]])
185192
.run();
186193
assert_eq!(
187194
p.glob("target/debug/.fingerprint/foo-*/output-*").count(),
@@ -190,12 +197,11 @@ fn clears_cache_after_fix() {
190197

191198
// And again, check the cache is correct.
192199
p.cargo("check")
193-
.with_stdout("")
194-
.with_stderr(
195-
"\
196-
[FINISHED] [..]
197-
",
198-
)
200+
.with_stdout_data(str![[r#""#]])
201+
.with_stderr_data(str![[r#"
202+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
203+
204+
"#]])
199205
.run();
200206
}
201207

@@ -267,13 +273,39 @@ fn very_verbose() {
267273
.build();
268274

269275
p.cargo("check -vv")
270-
.with_stderr_contains("[..]not_used[..]")
276+
.with_stderr_data(str![[r#"
277+
[UPDATING] `dummy-registry` index
278+
[LOCKING] 2 packages to latest compatible versions
279+
[DOWNLOADING] crates ...
280+
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
281+
[CHECKING] bar v1.0.0
282+
[RUNNING] [..]
283+
[WARNING] function `not_used` is never used
284+
...
285+
[CHECKING] foo v0.1.0 ([ROOT]/foo)
286+
[RUNNING] [..]
287+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
288+
289+
"#]])
271290
.run();
272291

273-
p.cargo("check").with_stderr("[FINISHED] [..]").run();
292+
p.cargo("check")
293+
.with_stderr_data(str![[r#"
294+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
295+
296+
"#]])
297+
.run();
274298

275299
p.cargo("check -vv")
276-
.with_stderr_contains("[..]not_used[..]")
300+
.with_stderr_data(str![[r#"
301+
[FRESH] bar v1.0.0
302+
[WARNING] function `not_used` is never used
303+
...
304+
[WARNING] `bar` (lib) generated 1 warning
305+
[FRESH] foo v0.1.0 ([ROOT]/foo)
306+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
307+
308+
"#]])
277309
.run();
278310
}
279311

@@ -346,25 +378,23 @@ fn replay_non_json() {
346378
let p = project().file("src/lib.rs", "").build();
347379
p.cargo("check")
348380
.env("RUSTC", rustc.bin("rustc_alt"))
349-
.with_stderr(
350-
"\
351-
[CHECKING] foo [..]
381+
.with_stderr_data(str![[r#"
382+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
352383
line 1
353384
line 2
354-
[FINISHED] `dev` profile [..]
355-
",
356-
)
385+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
386+
387+
"#]])
357388
.run();
358389

359390
p.cargo("check")
360391
.env("RUSTC", rustc.bin("rustc_alt"))
361-
.with_stderr(
362-
"\
392+
.with_stderr_data(str![[r#"
363393
line 1
364394
line 2
365-
[FINISHED] `dev` profile [..]
366-
",
367-
)
395+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
396+
397+
"#]])
368398
.run();
369399
}
370400

@@ -407,22 +437,22 @@ fn caching_large_output() {
407437
let p = project().file("src/lib.rs", "").build();
408438
p.cargo("check")
409439
.env("RUSTC", rustc.bin("rustc_alt"))
410-
.with_stderr(&format!(
440+
.with_stderr_data(&format!(
411441
"\
412-
[CHECKING] foo [..]
413-
{}warning: `foo` (lib) generated 250 warnings
414-
[FINISHED] `dev` profile [..]
442+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
443+
{}[WARNING] `foo` (lib) generated 250 warnings
444+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
415445
",
416446
expected
417447
))
418448
.run();
419449

420450
p.cargo("check")
421451
.env("RUSTC", rustc.bin("rustc_alt"))
422-
.with_stderr(&format!(
452+
.with_stderr_data(&format!(
423453
"\
424-
{}warning: `foo` (lib) generated 250 warnings
425-
[FINISHED] `dev` profile [..]
454+
{}[WARNING] `foo` (lib) generated 250 warnings
455+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
426456
",
427457
expected
428458
))
@@ -441,44 +471,61 @@ fn rustc_workspace_wrapper() {
441471

442472
p.cargo("check -v")
443473
.env("RUSTC_WORKSPACE_WRAPPER", tools::echo_wrapper())
444-
.with_stderr_contains(
445-
"WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]",
446-
)
474+
.with_stderr_data(str![[r#"
475+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
476+
[RUNNING] [..]/rustc-echo-wrapper[EXE] rustc --crate-name foo [..]
477+
WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]
478+
[WARNING] function `unused_func` is never used
479+
...
480+
[WARNING] `foo` (lib) generated 1 warning
481+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
482+
483+
"#]])
447484
.run();
448485

449486
// Check without a wrapper should rebuild
450487
p.cargo("check -v")
451-
.with_stderr_contains(
452-
"\
453-
[CHECKING] foo [..]
454-
[RUNNING] `rustc[..]
455-
[WARNING] [..]unused_func[..]
456-
",
457-
)
458-
.with_stdout_does_not_contain(
459-
"WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]",
460-
)
488+
.with_stderr_data(str![[r#"
489+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
490+
[RUNNING] `rustc[..]`
491+
[WARNING] function `unused_func` is never used
492+
...
493+
[WARNING] `foo` (lib) generated 1 warning
494+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
495+
496+
"#]])
497+
.with_stdout_data(str![[r#""#]])
461498
.run();
462499

463500
// Again, reading from the cache.
464501
p.cargo("check -v")
465502
.env("RUSTC_WORKSPACE_WRAPPER", tools::echo_wrapper())
466-
.with_stderr_contains("[FRESH] foo [..]")
467-
.with_stdout_does_not_contain(
468-
"WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]",
469-
)
503+
.with_stderr_data(str![[r#"
504+
[FRESH] foo v0.0.1 ([ROOT]/foo)
505+
WRAPPER CALLED: rustc [..]
506+
...
507+
[WARNING] `foo` (lib) generated 1 warning
508+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
509+
510+
"#]])
511+
.with_stdout_data(str![[r#""#]])
470512
.run();
471513

472514
// And `check` should also be fresh, reading from cache.
473515
p.cargo("check -v")
474-
.with_stderr_contains("[FRESH] foo [..]")
475-
.with_stderr_contains("[WARNING] [..]unused_func[..]")
476-
.with_stdout_does_not_contain(
477-
"WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]",
478-
)
516+
.with_stderr_data(str![[r#"
517+
[FRESH] foo v0.0.1 ([ROOT]/foo)
518+
[WARNING] function `unused_func` is never used
519+
...
520+
[WARNING] `foo` (lib) generated 1 warning
521+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
522+
523+
"#]])
524+
.with_stdout_data(str![[r#""#]])
479525
.run();
480526
}
481527

528+
#[allow(deprecated)]
482529
#[cargo_test]
483530
fn wacky_hashless_fingerprint() {
484531
// On Windows, executables don't have hashes. This checks for a bad
@@ -491,7 +538,14 @@ fn wacky_hashless_fingerprint() {
491538
.with_stderr_does_not_contain("[..]unused[..]")
492539
.run();
493540
p.cargo("check --bin a")
494-
.with_stderr_contains("[..]unused[..]")
541+
.with_stderr_data(str![[r#"
542+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
543+
[WARNING] unused variable: `unused`
544+
...
545+
[WARNING] `foo` (bin "a") generated 1 warning
546+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
547+
548+
"#]])
495549
.run();
496550
// This should not pick up the cache from `a`.
497551
p.cargo("check --bin b")

0 commit comments

Comments
 (0)