Skip to content

Commit 029fe2b

Browse files
committed
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.
1 parent c54fa88 commit 029fe2b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

crates/rustfix/tests/parse_and_replace.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
//! There are several debugging environment variables for this test that you can set:
1111
//!
1212
//! - `RUST_LOG=parse_and_replace=debug`: Print debug information.
13+
//! - `RUSTFIX_TEST_BLESS=test-name.rs`: When given the name of a test, this
14+
//! will overwrite the `.json` and `.fixed.rs` files with the expected
15+
//! values. This can be used when adding a new test.
1316
//! - `RUSTFIX_TEST_RECORD_JSON=1`: Records the JSON output to
1417
//! `*.recorded.json` files. You can then move that to `.json` or whatever
1518
//! you need.
@@ -39,6 +42,7 @@ mod settings {
3942
pub const CHECK_JSON: &str = "RUSTFIX_TEST_CHECK_JSON";
4043
pub const RECORD_JSON: &str = "RUSTFIX_TEST_RECORD_JSON";
4144
pub const RECORD_FIXED_RUST: &str = "RUSTFIX_TEST_RECORD_FIXED_RUST";
45+
pub const BLESS: &str = "RUSTFIX_TEST_BLESS";
4246
}
4347

4448
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
176180
fs::write(file.with_extension("recorded.rs"), &fixed)?;
177181
}
178182

183+
if let Some(bless_name) = std::env::var_os(settings::BLESS) {
184+
if bless_name == file.file_name().unwrap() {
185+
std::fs::write(&json_file, &errors)?;
186+
std::fs::write(&fixed_file, &fixed)?;
187+
}
188+
}
189+
179190
let expected_fixed = fs::read_to_string(&fixed_file)
180191
.context(format!("could read fixed file for {}", file.display()))?;
181192
ensure!(

0 commit comments

Comments
 (0)