mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Add a primitive way to add new tests to parse_and_replace.
This adds an environment variable to make it easier to add new tests.
This commit is contained in:
parent
c54fa88ea4
commit
029fe2bafc
@ -10,6 +10,9 @@
|
||||
//! There are several debugging environment variables for this test that you can set:
|
||||
//!
|
||||
//! - `RUST_LOG=parse_and_replace=debug`: Print debug information.
|
||||
//! - `RUSTFIX_TEST_BLESS=test-name.rs`: When given the name of a test, this
|
||||
//! will overwrite the `.json` and `.fixed.rs` files with the expected
|
||||
//! values. This can be used when adding a new test.
|
||||
//! - `RUSTFIX_TEST_RECORD_JSON=1`: Records the JSON output to
|
||||
//! `*.recorded.json` files. You can then move that to `.json` or whatever
|
||||
//! you need.
|
||||
@ -39,6 +42,7 @@ mod settings {
|
||||
pub const CHECK_JSON: &str = "RUSTFIX_TEST_CHECK_JSON";
|
||||
pub const RECORD_JSON: &str = "RUSTFIX_TEST_RECORD_JSON";
|
||||
pub const RECORD_FIXED_RUST: &str = "RUSTFIX_TEST_RECORD_FIXED_RUST";
|
||||
pub const BLESS: &str = "RUSTFIX_TEST_BLESS";
|
||||
}
|
||||
|
||||
fn compile(file: &Path) -> Result<Output, Error> {
|
||||
@ -176,6 +180,13 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P, mode: &str) -> Result<(), Err
|
||||
fs::write(file.with_extension("recorded.rs"), &fixed)?;
|
||||
}
|
||||
|
||||
if let Some(bless_name) = std::env::var_os(settings::BLESS) {
|
||||
if bless_name == file.file_name().unwrap() {
|
||||
std::fs::write(&json_file, &errors)?;
|
||||
std::fs::write(&fixed_file, &fixed)?;
|
||||
}
|
||||
}
|
||||
|
||||
let expected_fixed = fs::read_to_string(&fixed_file)
|
||||
.context(format!("could read fixed file for {}", file.display()))?;
|
||||
ensure!(
|
||||
|
Loading…
x
Reference in New Issue
Block a user