mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:34:40 +00:00
Fix Black compatible snapshot deletion (#5646)
This commit is contained in:
parent
bd8f65814c
commit
089a671adb
1 changed files with 12 additions and 10 deletions
|
@ -32,18 +32,20 @@ fn black_compatibility() {
|
|||
// already perfectly captures the expected output.
|
||||
// The following code mimics insta's logic generating the snapshot name for a test.
|
||||
let workspace_path = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let snapshot_name = insta::_function_name!()
|
||||
.strip_prefix(&format!("{}::", module_path!()))
|
||||
.unwrap();
|
||||
let module_path = module_path!().replace("::", "__");
|
||||
|
||||
let mut components = input_path.components().rev();
|
||||
let file_name = components.next().unwrap();
|
||||
let test_suite = components.next().unwrap();
|
||||
|
||||
let snapshot_name = format!(
|
||||
"black_compatibility@{}__{}.snap",
|
||||
test_suite.as_os_str().to_string_lossy(),
|
||||
file_name.as_os_str().to_string_lossy()
|
||||
);
|
||||
|
||||
let snapshot_path = Path::new(&workspace_path)
|
||||
.join("src/snapshots")
|
||||
.join(format!(
|
||||
"{module_path}__{}.snap",
|
||||
snapshot_name.replace(&['/', '\\'][..], "__")
|
||||
));
|
||||
|
||||
.join("tests/snapshots")
|
||||
.join(snapshot_name);
|
||||
if snapshot_path.exists() && snapshot_path.is_file() {
|
||||
// SAFETY: This is a convenience feature. That's why we don't want to abort
|
||||
// when deleting a no longer needed snapshot fails.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue