Show preview changes for tests with options (#9223)

This commit is contained in:
Micha Reiser 2023-12-22 08:36:19 +09:00 committed by GitHub
parent 1e7bc1dffe
commit d835b28d01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 236 additions and 0 deletions

View file

@ -157,6 +157,39 @@ fn format() {
CodeFrame::new("python", &formatted_code)
)
.unwrap();
if options.preview().is_enabled() {
continue;
}
// We want to capture the differences in the preview style in our fixtures
let options_preview = options.with_preview(PreviewMode::Enabled);
let printed_preview = format_module_source(&content, options_preview.clone())
.expect("Formatting to succeed");
let formatted_preview = printed_preview.as_code();
ensure_unchanged_ast(&content, formatted_preview, &options_preview, input_path);
ensure_stability_when_formatting_twice(
formatted_preview,
&options_preview,
input_path,
);
if formatted_code != formatted_preview {
// Having both snapshots makes it hard to see the difference, so we're keeping only
// diff.
writeln!(
snapshot,
"#### Preview changes\n{}",
CodeFrame::new(
"diff",
TextDiff::from_lines(formatted_code, formatted_preview)
.unified_diff()
.header("Stable", "Preview")
)
)
.unwrap();
}
}
} else {
// We want to capture the differences in the preview style in our fixtures