cargo/tests/testsuite/rustc_info_cache.rs
Aleksey Kladov 1be3579396 Improve rustc cache
Even if we've failed to calculate fingerprint and thus can't persist
cache to disk, it is still valid to cache rustc output within single
process.
2018-04-18 17:44:23 +03:00

138 lines
4.2 KiB
Rust

use cargotest::support::{execs, project};
use cargotest::support::paths::CargoPathExt;
use hamcrest::assert_that;
use std::env;
#[test]
fn rustc_info_cache() {
let p = project("foo")
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
"#,
)
.file("src/main.rs", r#"fn main() { println!("hello"); }"#)
.build();
let miss = "[..] rustc info cache miss[..]";
let hit = "[..]rustc info cache hit[..]";
let update = "[..]updated rustc info cache[..]";
assert_that(
p.cargo("build").env("RUST_LOG", "cargo::util::rustc=info"),
execs()
.with_status(0)
.with_stderr_contains("[..]failed to read rustc info cache[..]")
.with_stderr_contains(miss)
.with_stderr_does_not_contain(hit)
.with_stderr_contains(update),
);
assert_that(
p.cargo("build").env("RUST_LOG", "cargo::util::rustc=info"),
execs()
.with_status(0)
.with_stderr_contains("[..]reusing existing rustc info cache[..]")
.with_stderr_contains(hit)
.with_stderr_does_not_contain(miss)
.with_stderr_does_not_contain(update),
);
assert_that(
p.cargo("build")
.env("RUST_LOG", "cargo::util::rustc=info")
.env("CARGO_CACHE_RUSTC_INFO", "0"),
execs()
.with_status(0)
.with_stderr_contains("[..]rustc info cache disabled[..]")
.with_stderr_does_not_contain(update),
);
let other_rustc = {
let p = project("compiler")
.file(
"Cargo.toml",
r#"
[package]
name = "compiler"
version = "0.1.0"
"#,
)
.file(
"src/main.rs",
r#"
use std::process::Command;
use std::env;
fn main() {
let mut cmd = Command::new("rustc");
for arg in env::args_os().skip(1) {
cmd.arg(arg);
}
std::process::exit(cmd.status().unwrap().code().unwrap());
}
"#,
)
.build();
assert_that(p.cargo("build"), execs().with_status(0));
p.root()
.join("target/debug/compiler")
.with_extension(env::consts::EXE_EXTENSION)
};
assert_that(
p.cargo("build")
.env("RUST_LOG", "cargo::util::rustc=info")
.env("RUSTC", other_rustc.display().to_string()),
execs()
.with_status(0)
.with_stderr_contains("[..]different compiler, creating new rustc info cache[..]")
.with_stderr_contains(miss)
.with_stderr_does_not_contain(hit)
.with_stderr_contains(update),
);
assert_that(
p.cargo("build")
.env("RUST_LOG", "cargo::util::rustc=info")
.env("RUSTC", other_rustc.display().to_string()),
execs()
.with_status(0)
.with_stderr_contains("[..]reusing existing rustc info cache[..]")
.with_stderr_contains(hit)
.with_stderr_does_not_contain(miss)
.with_stderr_does_not_contain(update),
);
other_rustc.move_into_the_future();
assert_that(
p.cargo("build")
.env("RUST_LOG", "cargo::util::rustc=info")
.env("RUSTC", other_rustc.display().to_string()),
execs()
.with_status(0)
.with_stderr_contains("[..]different compiler, creating new rustc info cache[..]")
.with_stderr_contains(miss)
.with_stderr_does_not_contain(hit)
.with_stderr_contains(update),
);
assert_that(
p.cargo("build")
.env("RUST_LOG", "cargo::util::rustc=info")
.env("RUSTC", other_rustc.display().to_string()),
execs()
.with_status(0)
.with_stderr_contains("[..]reusing existing rustc info cache[..]")
.with_stderr_contains(hit)
.with_stderr_does_not_contain(miss)
.with_stderr_does_not_contain(update),
);
}