Skip to content

Commit

Permalink
migrate cache_message to snapbox
Browse files Browse the repository at this point in the history
  • Loading branch information
heisen-li committed Jun 14, 2024
1 parent fc332e2 commit 0d255dd
Showing 1 changed file with 118 additions and 47 deletions.
165 changes: 118 additions & 47 deletions tests/testsuite/cache_messages.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Tests for caching compiler diagnostics.

#![allow(deprecated)]

use super::messages::raw_rustc_output;
use cargo_test_support::str;
use cargo_test_support::tools;
use cargo_test_support::{basic_manifest, is_coarse_mtime, project, registry::Package, sleep_ms};

Expand Down Expand Up @@ -160,7 +159,17 @@ fn clears_cache_after_fix() {
// Make sure the cache is invalidated when there is no output.
let p = project().file("src/lib.rs", "fn asdf() {}").build();
// Fill the cache.
p.cargo("check").with_stderr_contains("[..]asdf[..]").run();
p.cargo("check")
.with_stderr_data(
"\
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[WARNING] function `asdf` is never used
...
[WARNING] `foo` (lib) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
)
.run();
let cpath = p
.glob("target/debug/.fingerprint/foo-*/output-*")
.next()
Expand All @@ -175,13 +184,12 @@ fn clears_cache_after_fix() {
p.change_file("src/lib.rs", "");

p.cargo("check")
.with_stdout("")
.with_stderr(
"\
[CHECKING] foo [..]
[FINISHED] [..]
",
)
.with_stdout_data(str![[r#""#]])
.with_stderr_data(str![[r#"
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
assert_eq!(
p.glob("target/debug/.fingerprint/foo-*/output-*").count(),
Expand All @@ -190,12 +198,11 @@ fn clears_cache_after_fix() {

// And again, check the cache is correct.
p.cargo("check")
.with_stdout("")
.with_stderr(
"\
[FINISHED] [..]
",
)
.with_stdout_data(str![[r#""#]])
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

Expand Down Expand Up @@ -267,13 +274,41 @@ fn very_verbose() {
.build();

p.cargo("check -vv")
.with_stderr_contains("[..]not_used[..]")
.with_stderr_data(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
[CHECKING] bar v1.0.0
[RUNNING] [..]
[WARNING] function `not_used` is never used
...
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[RUNNING] [..]
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
)
.run();

p.cargo("check").with_stderr("[FINISHED] [..]").run();
p.cargo("check")
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();

p.cargo("check -vv")
.with_stderr_contains("[..]not_used[..]")
.with_stderr_data(
"\
[FRESH] bar v1.0.0
[WARNING] function `not_used` is never used
...
[WARNING] `bar` (lib) generated 1 warning
[FRESH] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
)
.run();
}

Expand Down Expand Up @@ -346,25 +381,23 @@ fn replay_non_json() {
let p = project().file("src/lib.rs", "").build();
p.cargo("check")
.env("RUSTC", rustc.bin("rustc_alt"))
.with_stderr(
"\
[CHECKING] foo [..]
.with_stderr_data(str![[r#"
[CHECKING] foo v0.0.1 ([ROOT]/foo)
line 1
line 2
[FINISHED] `dev` profile [..]
",
)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();

p.cargo("check")
.env("RUSTC", rustc.bin("rustc_alt"))
.with_stderr(
"\
.with_stderr_data(str![[r#"
line 1
line 2
[FINISHED] `dev` profile [..]
",
)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

Expand Down Expand Up @@ -407,28 +440,29 @@ fn caching_large_output() {
let p = project().file("src/lib.rs", "").build();
p.cargo("check")
.env("RUSTC", rustc.bin("rustc_alt"))
.with_stderr(&format!(
.with_stderr_data(&format!(
"\
[CHECKING] foo [..]
{}warning: `foo` (lib) generated 250 warnings
[FINISHED] `dev` profile [..]
[CHECKING] foo v0.0.1 ([ROOT]/foo)
{}[WARNING] `foo` (lib) generated 250 warnings
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
expected
))
.run();

p.cargo("check")
.env("RUSTC", rustc.bin("rustc_alt"))
.with_stderr(&format!(
.with_stderr_data(&format!(
"\
{}warning: `foo` (lib) generated 250 warnings
[FINISHED] `dev` profile [..]
{}[WARNING] `foo` (lib) generated 250 warnings
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
expected
))
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn rustc_workspace_wrapper() {
let p = project()
Expand All @@ -441,18 +475,29 @@ fn rustc_workspace_wrapper() {

p.cargo("check -v")
.env("RUSTC_WORKSPACE_WRAPPER", tools::echo_wrapper())
.with_stderr_contains(
"WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]",
.with_stderr_data(
"\
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] [..]
WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]
[WARNING] function `unused_func` is never used
...
[WARNING] `foo` (lib) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
)
.run();

// Check without a wrapper should rebuild
p.cargo("check -v")
.with_stderr_contains(
.with_stderr_data(
"\
[CHECKING] foo [..]
[RUNNING] `rustc[..]
[WARNING] [..]unused_func[..]
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustc[..]`
[WARNING] function `unused_func` is never used
...
[WARNING] `foo` (lib) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
)
.with_stdout_does_not_contain(
Expand All @@ -463,22 +508,40 @@ fn rustc_workspace_wrapper() {
// Again, reading from the cache.
p.cargo("check -v")
.env("RUSTC_WORKSPACE_WRAPPER", tools::echo_wrapper())
.with_stderr_contains("[FRESH] foo [..]")
.with_stderr_data(
"\
[FRESH] foo v0.0.1 ([ROOT]/foo)
WRAPPER CALLED: rustc [..]
...
[WARNING] function `unused_func` is never used
...
[WARNING] `foo` (lib) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
)
.with_stdout_does_not_contain(
"WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]",
)
.run();

// And `check` should also be fresh, reading from cache.
p.cargo("check -v")
.with_stderr_contains("[FRESH] foo [..]")
.with_stderr_contains("[WARNING] [..]unused_func[..]")
.with_stderr_data(
"\
[FRESH] foo v0.0.1 ([ROOT]/foo)
[WARNING] function `unused_func` is never used
...
[WARNING] `foo` (lib) generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
)
.with_stdout_does_not_contain(
"WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]",
)
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn wacky_hashless_fingerprint() {
// On Windows, executables don't have hashes. This checks for a bad
Expand All @@ -491,7 +554,15 @@ fn wacky_hashless_fingerprint() {
.with_stderr_does_not_contain("[..]unused[..]")
.run();
p.cargo("check --bin a")
.with_stderr_contains("[..]unused[..]")
.with_stderr_data(
"\
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[WARNING] unused variable: `unused`
...
[WARNING] `foo` (bin \"a\") generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
",
)
.run();
// This should not pick up the cache from `a`.
p.cargo("check --bin b")
Expand Down

0 comments on commit 0d255dd

Please sign in to comment.