diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3331ffbd7f..a33c8353c7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ exclude: | crates/ruff/src/rules/.*/snapshots/.*| crates/ruff_cli/resources/.*| crates/ruff_python_formatter/resources/.*| - crates/ruff_python_formatter/src/snapshots/.* + crates/ruff_python_formatter/tests/snapshots/.* )$ repos: diff --git a/Cargo.lock b/Cargo.lock index 1645b94509..91d79253be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -988,9 +988,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28491f7753051e5704d4d0ae7860d45fae3238d7d235bc4289dcd45c48d3cec3" dependencies = [ "console", + "globset", "lazy_static", "linked-hash-map", "similar", + "walkdir", "yaml-rust", ] @@ -2060,7 +2062,6 @@ dependencies = [ "ruff_formatter", "ruff_python_ast", "ruff_python_whitespace", - "ruff_testing_macros", "ruff_text_size", "rustc-hash", "rustpython-parser", @@ -2105,16 +2106,6 @@ dependencies = [ "rustpython-parser", ] -[[package]] -name = "ruff_testing_macros" -version = "0.0.0" -dependencies = [ - "glob", - "proc-macro2", - "quote", - "syn 2.0.22", -] - [[package]] name = "ruff_text_size" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 4066cb9c1e..047c7994ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ filetime = { version = "0.2.20" } glob = { version = "0.3.1" } globset = { version = "0.4.10" } ignore = { version = "0.4.20" } -insta = { version = "1.28.0" } +insta = { version = "1.30.0" } is-macro = { version = "0.2.2" } itertools = { version = "0.10.5" } log = { version = "0.4.17" } diff --git a/crates/ruff_python_formatter/Cargo.toml b/crates/ruff_python_formatter/Cargo.toml index 0701907975..91ba277792 100644 --- a/crates/ruff_python_formatter/Cargo.toml +++ b/crates/ruff_python_formatter/Cargo.toml @@ -27,8 +27,6 @@ rustc-hash = { workspace = true } rustpython-parser = { workspace = true } [dev-dependencies] -ruff_testing_macros = { path = "../ruff_testing_macros" } - -insta = { workspace = true, features = [] } +insta = { workspace = true, features = ["glob"] } test-case = { workspace = true } similar = { workspace = true } diff --git a/crates/ruff_python_formatter/src/lib.rs b/crates/ruff_python_formatter/src/lib.rs index 790b08faa9..93197b2ca2 100644 --- a/crates/ruff_python_formatter/src/lib.rs +++ b/crates/ruff_python_formatter/src/lib.rs @@ -263,18 +263,12 @@ impl TryFrom for QuoteStyle { #[cfg(test)] mod tests { + use crate::{format_module, format_node}; use anyhow::Result; use insta::assert_snapshot; use ruff_python_ast::source_code::CommentRangesBuilder; - use ruff_testing_macros::fixture; use rustpython_parser::lexer::lex; use rustpython_parser::{parse_tokens, Mode}; - use similar::TextDiff; - use std::fmt::{Formatter, Write}; - use std::fs; - use std::path::Path; - - use crate::{format_module, format_node}; /// Very basic test intentionally kept very similar to the CLI #[test] @@ -295,138 +289,6 @@ if True: Ok(()) } - #[fixture(pattern = "resources/test/fixtures/black/**/*.py")] - #[test] - fn black_test(input_path: &Path) -> Result<()> { - let content = fs::read_to_string(input_path)?; - - let printed = format_module(&content)?; - - let expected_path = input_path.with_extension("py.expect"); - let expected_output = fs::read_to_string(&expected_path) - .unwrap_or_else(|_| panic!("Expected Black output file '{expected_path:?}' to exist")); - - let formatted_code = printed.as_code(); - - ensure_stability_when_formatting_twice(formatted_code); - - if formatted_code == expected_output { - // Black and Ruff formatting matches. Delete any existing snapshot files because the Black output - // 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 snapshot_path = Path::new(&workspace_path) - .join("src/snapshots") - .join(format!( - "{module_path}__{}.snap", - snapshot_name.replace(&['/', '\\'][..], "__") - )); - - 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. - fs::remove_file(&snapshot_path).ok(); - } - - let new_snapshot_path = snapshot_path.with_extension("snap.new"); - if new_snapshot_path.exists() && new_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. - fs::remove_file(&new_snapshot_path).ok(); - } - } else { - // Black and Ruff have different formatting. Write out a snapshot that covers the differences - // today. - let mut snapshot = String::new(); - write!(snapshot, "{}", Header::new("Input"))?; - write!(snapshot, "{}", CodeFrame::new("py", &content))?; - - write!(snapshot, "{}", Header::new("Black Differences"))?; - - let diff = TextDiff::from_lines(expected_output.as_str(), formatted_code) - .unified_diff() - .header("Black", "Ruff") - .to_string(); - - write!(snapshot, "{}", CodeFrame::new("diff", &diff))?; - - write!(snapshot, "{}", Header::new("Ruff Output"))?; - write!(snapshot, "{}", CodeFrame::new("py", formatted_code))?; - - write!(snapshot, "{}", Header::new("Black Output"))?; - write!(snapshot, "{}", CodeFrame::new("py", &expected_output))?; - - insta::with_settings!({ omit_expression => false, input_file => input_path }, { - insta::assert_snapshot!(snapshot); - }); - } - - Ok(()) - } - - #[fixture(pattern = "resources/test/fixtures/ruff/**/*.py")] - #[test] - fn ruff_test(input_path: &Path) -> Result<()> { - let content = fs::read_to_string(input_path)?; - - let printed = format_module(&content)?; - let formatted_code = printed.as_code(); - - ensure_stability_when_formatting_twice(formatted_code); - - let snapshot = format!( - r#"## Input -{} - -## Output -{}"#, - CodeFrame::new("py", &content), - CodeFrame::new("py", formatted_code) - ); - assert_snapshot!(snapshot); - - Ok(()) - } - - /// Format another time and make sure that there are no changes anymore - fn ensure_stability_when_formatting_twice(formatted_code: &str) { - let reformatted = match format_module(formatted_code) { - Ok(reformatted) => reformatted, - Err(err) => { - panic!( - "Expected formatted code to be valid syntax: {err}:\ - \n---\n{formatted_code}---\n", - ); - } - }; - - if reformatted.as_code() != formatted_code { - let diff = TextDiff::from_lines(formatted_code, reformatted.as_code()) - .unified_diff() - .header("Formatted once", "Formatted twice") - .to_string(); - panic!( - r#"Reformatting the formatted code a second time resulted in formatting changes. ---- -{diff}--- - -Formatted once: ---- -{formatted_code}--- - -Formatted twice: ---- -{}---"#, - reformatted.as_code() - ); - } - } - /// Use this test to debug the formatting of some snipped #[ignore] #[test] @@ -549,41 +411,4 @@ if [ assert_snapshot!(output.print().expect("Printing to succeed").as_code()); } - - struct Header<'a> { - title: &'a str, - } - - impl<'a> Header<'a> { - fn new(title: &'a str) -> Self { - Self { title } - } - } - - impl std::fmt::Display for Header<'_> { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - writeln!(f, "## {}", self.title)?; - writeln!(f) - } - } - - struct CodeFrame<'a> { - language: &'a str, - code: &'a str, - } - - impl<'a> CodeFrame<'a> { - fn new(language: &'a str, code: &'a str) -> Self { - Self { language, code } - } - } - - impl std::fmt::Display for CodeFrame<'_> { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - writeln!(f, "```{}", self.language)?; - write!(f, "{}", self.code)?; - writeln!(f, "```")?; - writeln!(f) - } - } } diff --git a/crates/ruff_python_formatter/tests/fixtures.rs b/crates/ruff_python_formatter/tests/fixtures.rs new file mode 100644 index 0000000000..edfc112a86 --- /dev/null +++ b/crates/ruff_python_formatter/tests/fixtures.rs @@ -0,0 +1,187 @@ +use ruff_python_formatter::format_module; +use similar::TextDiff; +use std::fmt::{Formatter, Write}; +use std::fs; +use std::path::Path; + +#[test] +fn black_compatibility() { + let test_file = |input_path: &Path| { + let content = fs::read_to_string(input_path).unwrap(); + + let printed = format_module(&content).expect("Formatting to succeed"); + + let expected_path = input_path.with_extension("py.expect"); + let expected_output = fs::read_to_string(&expected_path) + .unwrap_or_else(|_| panic!("Expected Black output file '{expected_path:?}' to exist")); + + let formatted_code = printed.as_code(); + + ensure_stability_when_formatting_twice(formatted_code); + + if formatted_code == expected_output { + // Black and Ruff formatting matches. Delete any existing snapshot files because the Black output + // 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 snapshot_path = Path::new(&workspace_path) + .join("src/snapshots") + .join(format!( + "{module_path}__{}.snap", + snapshot_name.replace(&['/', '\\'][..], "__") + )); + + 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. + fs::remove_file(&snapshot_path).ok(); + } + + let new_snapshot_path = snapshot_path.with_extension("snap.new"); + if new_snapshot_path.exists() && new_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. + fs::remove_file(&new_snapshot_path).ok(); + } + } else { + // Black and Ruff have different formatting. Write out a snapshot that covers the differences + // today. + let mut snapshot = String::new(); + write!(snapshot, "{}", Header::new("Input")).unwrap(); + write!(snapshot, "{}", CodeFrame::new("py", &content)).unwrap(); + + write!(snapshot, "{}", Header::new("Black Differences")).unwrap(); + + let diff = TextDiff::from_lines(expected_output.as_str(), formatted_code) + .unified_diff() + .header("Black", "Ruff") + .to_string(); + + write!(snapshot, "{}", CodeFrame::new("diff", &diff)).unwrap(); + + write!(snapshot, "{}", Header::new("Ruff Output")).unwrap(); + write!(snapshot, "{}", CodeFrame::new("py", formatted_code)).unwrap(); + + write!(snapshot, "{}", Header::new("Black Output")).unwrap(); + write!(snapshot, "{}", CodeFrame::new("py", &expected_output)).unwrap(); + + insta::with_settings!({ + omit_expression => true, + input_file => input_path, + prepend_module_to_snapshot => false, + }, { + insta::assert_snapshot!(snapshot); + }); + } + }; + + insta::glob!("../resources", "test/fixtures/black/**/*.py", test_file); +} + +#[test] +fn format() { + let test_file = |input_path: &Path| { + let content = fs::read_to_string(input_path).unwrap(); + + let printed = format_module(&content).expect("Formatting to succeed"); + let formatted_code = printed.as_code(); + + ensure_stability_when_formatting_twice(formatted_code); + + let snapshot = format!( + r#"## Input +{} + +## Output +{}"#, + CodeFrame::new("py", &content), + CodeFrame::new("py", formatted_code) + ); + + insta::with_settings!({ + omit_expression => true, + input_file => input_path, + prepend_module_to_snapshot => false, + }, { + insta::assert_snapshot!(snapshot); + }); + }; + + insta::glob!("../resources", "test/fixtures/ruff/**/*.py", test_file); +} + +/// Format another time and make sure that there are no changes anymore +fn ensure_stability_when_formatting_twice(formatted_code: &str) { + let reformatted = match format_module(formatted_code) { + Ok(reformatted) => reformatted, + Err(err) => { + panic!( + "Expected formatted code to be valid syntax: {err}:\ + \n---\n{formatted_code}---\n", + ); + } + }; + + if reformatted.as_code() != formatted_code { + let diff = TextDiff::from_lines(formatted_code, reformatted.as_code()) + .unified_diff() + .header("Formatted once", "Formatted twice") + .to_string(); + panic!( + r#"Reformatting the formatted code a second time resulted in formatting changes. +--- +{diff}--- + +Formatted once: +--- +{formatted_code}--- + +Formatted twice: +--- +{}---"#, + reformatted.as_code() + ); + } +} + +struct Header<'a> { + title: &'a str, +} + +impl<'a> Header<'a> { + fn new(title: &'a str) -> Self { + Self { title } + } +} + +impl std::fmt::Display for Header<'_> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + writeln!(f, "## {}", self.title)?; + writeln!(f) + } +} + +struct CodeFrame<'a> { + language: &'a str, + code: &'a str, +} + +impl<'a> CodeFrame<'a> { + fn new(language: &'a str, code: &'a str) -> Self { + Self { language, code } + } +} + +impl std::fmt::Display for CodeFrame<'_> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + writeln!(f, "```{}", self.language)?; + write!(f, "{}", self.code)?; + writeln!(f, "```")?; + writeln!(f) + } +} diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__attribute_access_on_number_literals_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@attribute_access_on_number_literals.py.snap similarity index 97% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__attribute_access_on_number_literals_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@attribute_access_on_number_literals.py.snap index 62da55712c..cfa4c7cd05 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__attribute_access_on_number_literals_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@attribute_access_on_number_literals.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/attribute_access_on_number_literals.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__beginning_backslash_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@beginning_backslash.py.snap similarity index 85% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__beginning_backslash_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@beginning_backslash.py.snap index 6b56a193c0..1bd0c3f921 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__beginning_backslash_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@beginning_backslash.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/beginning_backslash.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__bracketmatch_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@bracketmatch.py.snap similarity index 92% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__bracketmatch_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@bracketmatch.py.snap index 548945997c..ae89b4e872 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__bracketmatch_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@bracketmatch.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/bracketmatch.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_methods_new_line_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@class_methods_new_line.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_methods_new_line_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@class_methods_new_line.py.snap index d519958e1a..436b6923ff 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_methods_new_line_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@class_methods_new_line.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_methods_new_line.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__collections_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@collections.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__collections_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@collections.py.snap index 1c961a36e7..6e6ec5275c 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__collections_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@collections.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/collections.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comment_after_escaped_newline_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comment_after_escaped_newline.py.snap similarity index 91% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comment_after_escaped_newline_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@comment_after_escaped_newline.py.snap index 92e670eafa..5a209c5759 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comment_after_escaped_newline_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comment_after_escaped_newline.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comment_after_escaped_newline.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments.py.snap index cb44cb8f7f..1317f43548 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments2_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments2.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments2_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments2.py.snap index 07c15327b0..2778d433ad 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments2_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments2.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments2.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments3_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments3.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments3_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments3.py.snap index 73e02a1e27..5bd61dca47 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments3_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments3.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments3.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments4_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments4.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments4_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments4.py.snap index 620587b2e6..7b3c1751cc 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments4_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments4.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments4.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments5_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments5.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments5_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments5.py.snap index 51320a8e86..269d9cdd25 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments5_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments5.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments5.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments6_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments6.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments6_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments6.py.snap index 86c3b34f2d..120d15c6fe 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments6_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments6.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments6.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments9_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments9.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments9_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments9.py.snap index 8ae0c972f4..b6b4ce39f0 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments9_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments9.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments9.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_non_breaking_space_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments_non_breaking_space.py.snap similarity index 97% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_non_breaking_space_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments_non_breaking_space.py.snap index 6ff36ce6c3..cae2d7d069 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_non_breaking_space_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@comments_non_breaking_space.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments_non_breaking_space.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@composition.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@composition.py.snap index de890ccedd..25490c1887 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@composition.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/composition.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_no_trailing_comma_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@composition_no_trailing_comma.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_no_trailing_comma_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@composition_no_trailing_comma.py.snap index f47fb08de7..30953137ad 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_no_trailing_comma_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@composition_no_trailing_comma.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/composition_no_trailing_comma.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@docstring.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@docstring.py.snap index da177f0353..60a50df3a5 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@docstring.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_preview_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@docstring_preview.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_preview_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@docstring_preview.py.snap index 296bb4715d..3101537b9d 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_preview_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@docstring_preview.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_preview.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__empty_lines_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@empty_lines.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__empty_lines_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@empty_lines.py.snap index 874c26f461..b8e1bf9f55 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__empty_lines_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@empty_lines.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/empty_lines.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__expression_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@expression.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__expression_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@expression.py.snap index 1499731809..47e1d61f92 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__expression_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@expression.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/expression.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff.py.snap index 3bf9990399..baf9eaa6af 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff2_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff2.py.snap similarity index 97% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff2_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff2.py.snap index 076c32ce50..548b61e58d 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff2_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff2.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff2.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff3_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff3.py.snap similarity index 91% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff3_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff3.py.snap index 1d24dd47e2..9dacee57d5 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff3_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff3.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff3.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff4_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff4.py.snap similarity index 93% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff4_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff4.py.snap index 9b5d673289..63a650ff45 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff4_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff4.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff4.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff5_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff5.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff5_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff5.py.snap index 55baa4ec3a..3bbc9eaea4 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff5_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtonoff5.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff5.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip.py.snap similarity index 86% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip.py.snap index c4deeaed9c..3c9f58710b 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip2_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip2.py.snap similarity index 95% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip2_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip2.py.snap index 13bf3277f2..487290c418 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip2_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip2.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip2.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip3_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip3.py.snap similarity index 92% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip3_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip3.py.snap index 2e54d4b721..002454e8da 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip3_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip3.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip3.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip4_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip4.py.snap similarity index 86% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip4_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip4.py.snap index 6d4c587187..93b2d701b1 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip4_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip4.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip4.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip5_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip5.py.snap similarity index 93% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip5_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip5.py.snap index 32b6d86155..156c1d3712 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip5_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip5.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip5.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip6_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip6.py.snap similarity index 92% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip6_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip6.py.snap index 5a73724ef4..5c22c86651 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip6_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip6.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip6.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip7_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip7.py.snap similarity index 93% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip7_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip7.py.snap index 4eb0c61744..cd13d57248 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip7_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip7.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip7.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip8_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip8.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip8_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip8.py.snap index 408c2b92e9..8e54712280 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip8_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fmtskip8.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip8.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fstring_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fstring.py.snap similarity index 96% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fstring_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@fstring.py.snap index d442a2cf0f..852778fb08 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fstring_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@fstring.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fstring.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@function.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@function.py.snap index da23fa784a..2be379cb33 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@function.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function2_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@function2.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function2_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@function2.py.snap index 2a6e53604d..d70e4ac234 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function2_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@function2.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function2.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_trailing_comma_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@function_trailing_comma.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_trailing_comma_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@function_trailing_comma.py.snap index e117c52399..e98815a64f 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_trailing_comma_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@function_trailing_comma.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function_trailing_comma.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__import_spacing_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@import_spacing.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__import_spacing_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@import_spacing.py.snap index 30c49898e4..6b2e7df8f3 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__import_spacing_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@import_spacing.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/import_spacing.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__one_element_subscript_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@one_element_subscript.py.snap similarity index 96% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__one_element_subscript_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@one_element_subscript.py.snap index 66e37c3bad..68bddbd301 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__one_element_subscript_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@one_element_subscript.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/one_element_subscript.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__power_op_spacing_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@power_op_spacing.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__power_op_spacing_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@power_op_spacing.py.snap index 693a6f7001..ea7c78d2a9 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__power_op_spacing_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@power_op_spacing.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/power_op_spacing.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__prefer_rhs_split_reformatted_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@prefer_rhs_split_reformatted.py.snap similarity index 97% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__prefer_rhs_split_reformatted_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@prefer_rhs_split_reformatted.py.snap index db5e55f09b..855222248f 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__prefer_rhs_split_reformatted_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@prefer_rhs_split_reformatted.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/prefer_rhs_split_reformatted.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_await_parens_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_await_parens.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_await_parens_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_await_parens.py.snap index b13ce8545b..d702a291b9 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_await_parens_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_await_parens.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_await_parens.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_except_parens_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_except_parens.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_except_parens_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_except_parens.py.snap index 680584a6d7..a845bf4af2 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_except_parens_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_except_parens.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_except_parens.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_for_brackets_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_for_brackets.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_for_brackets_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_for_brackets.py.snap index ab7e8ada6d..87a792c38b 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_for_brackets_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_for_brackets.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_for_brackets.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_newline_after_code_block_open_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_newline_after_code_block_open.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_newline_after_code_block_open_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_newline_after_code_block_open.py.snap index 1bf0525ecc..05400a9c8d 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_newline_after_code_block_open_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_newline_after_code_block_open.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_newline_after_code_block_open.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_parens_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_parens.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_parens_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_parens.py.snap index c9d1141cbf..1ed5be6a16 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_parens_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@remove_parens.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_parens.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__return_annotation_brackets_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@return_annotation_brackets.py.snap similarity index 99% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__return_annotation_brackets_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@return_annotation_brackets.py.snap index db50309690..664ee153eb 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__return_annotation_brackets_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@return_annotation_brackets.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/return_annotation_brackets.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__skip_magic_trailing_comma_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@skip_magic_trailing_comma.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__skip_magic_trailing_comma_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@skip_magic_trailing_comma.py.snap index 227fddc38c..4fccb92505 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__skip_magic_trailing_comma_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@skip_magic_trailing_comma.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/skip_magic_trailing_comma.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__slices_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@slices.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__slices_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@slices.py.snap index 914dc2e5fd..ec47eb18f9 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__slices_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@slices.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/slices.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__string_prefixes_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@string_prefixes.py.snap similarity index 97% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__string_prefixes_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@string_prefixes.py.snap index 1af332dee3..93c5a7f651 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__string_prefixes_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@string_prefixes.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/string_prefixes.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__torture_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@torture.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__torture_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@torture.py.snap index b270fd1801..ec5eeae618 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__torture_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@torture.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/torture.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens1_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@trailing_comma_optional_parens1.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens1_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@trailing_comma_optional_parens1.py.snap index 70f66ad05c..177fde22db 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens1_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@trailing_comma_optional_parens1.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens1.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens2_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@trailing_comma_optional_parens2.py.snap similarity index 92% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens2_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@trailing_comma_optional_parens2.py.snap index 122f1f4cfb..c4dddaa5b1 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens2_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@trailing_comma_optional_parens2.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens2.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens3_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@trailing_comma_optional_parens3.py.snap similarity index 96% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens3_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@trailing_comma_optional_parens3.py.snap index 106c7c2554..3a574ac557 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens3_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@trailing_comma_optional_parens3.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens3.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_commas_in_leading_parts_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@trailing_commas_in_leading_parts.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_commas_in_leading_parts_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@trailing_commas_in_leading_parts.py.snap index b6cdaf967b..e799084c77 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_commas_in_leading_parts_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@trailing_commas_in_leading_parts.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_commas_in_leading_parts.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tupleassign_py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@tupleassign.py.snap similarity index 95% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tupleassign_py.snap rename to crates/ruff_python_formatter/tests/snapshots/black_compatibility@tupleassign.py.snap index d67608accf..d54c56272e 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tupleassign_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@tupleassign.py.snap @@ -1,6 +1,5 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/tupleassign.py --- ## Input diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__attribute_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__attribute.py.snap similarity index 87% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__attribute_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@expression__attribute.py.snap index 991210a185..82792c7d3c 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__attribute_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__attribute.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/attribute.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__binary_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__binary.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__binary_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@expression__binary.py.snap index f79bc76fa1..a84c4a7201 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__binary_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__binary.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/binary.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__boolean_operation_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__boolean_operation.py.snap similarity index 94% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__boolean_operation_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@expression__boolean_operation.py.snap index cfc2bd43fe..0b98b8df25 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__boolean_operation_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__boolean_operation.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/boolean_operation.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__compare_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__compare.py.snap similarity index 95% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__compare_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@expression__compare.py.snap index 7abb3e4b1e..34e1cfbb3f 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__compare_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__compare.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/compare.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__dict_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__dict.py.snap similarity index 92% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__dict_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@expression__dict.py.snap index d59022c544..52a5965a90 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__dict_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__dict.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/dict.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__list_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__list.py.snap similarity index 79% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__list_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@expression__list.py.snap index 6ecef01df1..892d93b62e 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__list_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__list.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/list.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__slice_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__slice.py.snap similarity index 93% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__slice_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@expression__slice.py.snap index 80370410e7..e316dd5218 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__slice_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__slice.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/slice.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__string_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__string.py.snap similarity index 90% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__string_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@expression__string.py.snap index d57de901e1..4a2e6ed032 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__string_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__string.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/string.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__tuple_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__tuple.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__tuple_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@expression__tuple.py.snap index cce6cccafc..2ddb3cd9ad 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__tuple_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__tuple.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/tuple.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__unary_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__unary.py.snap similarity index 97% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__unary_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@expression__unary.py.snap index 48e8852375..f461d88180 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__unary_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__unary.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/unary.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__assign_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__assign.py.snap similarity index 84% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__assign_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@statement__assign.py.snap index b4237a40c7..4d02cf905c 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__assign_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__assign.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/assign.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__break_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__break.py.snap similarity index 66% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__break_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@statement__break.py.snap index 3087672f75..d48901046e 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__break_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__break.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/break.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__class_definition_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__class_definition.py.snap similarity index 90% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__class_definition_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@statement__class_definition.py.snap index 24adda2166..49aa2a4879 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__class_definition_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__class_definition.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/class_definition.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__for_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__for.py.snap similarity index 91% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__for_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@statement__for.py.snap index b176abbfb0..a240652d9c 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__for_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__for.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/for.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__function_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__function.py.snap similarity index 98% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__function_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@statement__function.py.snap index c2f44bcdba..00c72398e5 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__function_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__function.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/function.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__if_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__if.py.snap similarity index 95% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__if_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@statement__if.py.snap index 1c41ddd972..6292de6914 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__if_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__if.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/if.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__while_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__while.py.snap similarity index 91% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__while_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@statement__while.py.snap index 785c69cb8e..799424b4ea 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__while_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__while.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/while.py --- ## Input ```py diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__trivia_py.snap b/crates/ruff_python_formatter/tests/snapshots/format@trivia.py.snap similarity index 87% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__trivia_py.snap rename to crates/ruff_python_formatter/tests/snapshots/format@trivia.py.snap index 1d1c0586db..773e564e68 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__trivia_py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@trivia.py.snap @@ -1,6 +1,6 @@ --- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/trivia.py --- ## Input ```py diff --git a/crates/ruff_testing_macros/Cargo.toml b/crates/ruff_testing_macros/Cargo.toml deleted file mode 100644 index 49daf16a71..0000000000 --- a/crates/ruff_testing_macros/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "ruff_testing_macros" -version = "0.0.0" -publish = false -authors = { workspace = true } -edition = { workspace = true } -rust-version = { workspace = true } -homepage = { workspace = true } -documentation = { workspace = true } -repository = { workspace = true } -license = { workspace = true } - -[lib] -proc-macro = true - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -glob = { workspace = true } -proc-macro2 = { workspace = true } -quote = { workspace = true } -syn = { workspace = true, features = ["extra-traits", "full"] } diff --git a/crates/ruff_testing_macros/src/lib.rs b/crates/ruff_testing_macros/src/lib.rs deleted file mode 100644 index 23815540a1..0000000000 --- a/crates/ruff_testing_macros/src/lib.rs +++ /dev/null @@ -1,403 +0,0 @@ -use proc_macro::TokenStream; -use std::borrow::Cow; -use std::collections::BTreeMap; -use std::env; -use std::path::{Component, PathBuf}; - -use glob::{glob, Pattern}; -use proc_macro2::Span; -use quote::{format_ident, quote}; -use syn::parse::{Parse, ParseStream}; -use syn::punctuated::Punctuated; -use syn::spanned::Spanned; -use syn::{bracketed, parse_macro_input, parse_quote, Error, FnArg, ItemFn, LitStr, Pat, Token}; - -#[derive(Debug)] -struct FixtureConfiguration { - pattern: Pattern, - pattern_span: Span, - exclude: Vec, -} - -struct Arg { - name: syn::Ident, - value: ArgValue, -} - -impl Parse for Arg { - fn parse(input: ParseStream) -> syn::Result { - let name = input.parse()?; - let _equal_token: Token![=] = input.parse()?; - let value = input.parse()?; - - Ok(Self { name, value }) - } -} - -enum ArgValue { - LitStr(LitStr), - List(Punctuated), -} - -impl Parse for ArgValue { - fn parse(input: ParseStream) -> syn::Result { - let value = if input.peek(syn::token::Bracket) { - let inner; - _ = bracketed!(inner in input); - - let values = inner.parse_terminated( - |parser| { - let value: LitStr = parser.parse()?; - Ok(value) - }, - Token![,], - )?; - ArgValue::List(values) - } else { - ArgValue::LitStr(input.parse()?) - }; - - Ok(value) - } -} - -impl Parse for FixtureConfiguration { - fn parse(input: ParseStream) -> syn::Result { - let args: Punctuated<_, Token![,]> = input.parse_terminated(Arg::parse, Token![,])?; - - let mut pattern = None; - let mut exclude = None; - - for arg in args { - match arg.name.to_string().as_str() { - "pattern" => match arg.value { - ArgValue::LitStr(value) => { - pattern = Some(try_parse_pattern(&value)?); - } - ArgValue::List(list) => { - return Err(Error::new( - list.span(), - "The pattern must be a string literal", - )) - } - }, - - "exclude" => { - match arg.value { - ArgValue::LitStr(lit) => return Err(Error::new( - lit.span(), - "The exclude argument must be an array of globs: 'exclude=[\"a.py\"]", - )), - ArgValue::List(list) => { - let mut exclude_patterns = Vec::with_capacity(list.len()); - - for pattern in list { - let (pattern, _) = try_parse_pattern(&pattern)?; - exclude_patterns.push(pattern); - } - - exclude = Some(exclude_patterns); - } - } - } - - _ => { - return Err(Error::new( - arg.name.span(), - format!("Unknown argument {}.", arg.name), - )); - } - } - } - - let exclude = exclude.unwrap_or_default(); - - match pattern { - None => Err(Error::new( - input.span(), - "'fixture' macro must have a pattern attribute", - )), - Some((pattern, pattern_span)) => Ok(Self { - pattern, - pattern_span, - exclude, - }), - } - } -} - -fn try_parse_pattern(pattern_lit: &LitStr) -> syn::Result<(Pattern, Span)> { - let raw_pattern = pattern_lit.value(); - match Pattern::new(&raw_pattern) { - Ok(pattern) => Ok((pattern, pattern_lit.span())), - Err(err) => Err(Error::new( - pattern_lit.span(), - format!("'{raw_pattern}' is not a valid glob pattern: '{}'", err.msg), - )), - } -} - -/// Generates a test for each file that matches the specified pattern. -/// -/// The attributed function must have exactly one argument of the type `&Path`. -/// The `#[test]` attribute must come after the `#[fixture]` argument or `test` will complain -/// that your function can not have any arguments. -/// -/// ## Examples -/// -/// Creates a test for every python file file in the `fixtures` directory. -/// -/// ```ignore -/// #[fixture(pattern="fixtures/*.py")] -/// #[test] -/// fn my_test(path: &Path) -> std::io::Result<()> { -/// // ... implement the test -/// Ok(()) -/// } -/// ``` -/// -/// ### Excluding Files -/// -/// You can exclude files by specifying optional `exclude` patterns. -/// -/// ```ignore -/// #[fixture(pattern="fixtures/*.py", exclude=["a_*.py"])] -/// #[test] -/// fn my_test(path: &Path) -> std::io::Result<()> { -/// // ... implement the test -/// Ok(()) -/// } -/// ``` -/// -/// Creates tests for each python file in the `fixtures` directory except for files matching the `a_*.py` pattern. -#[proc_macro_attribute] -pub fn fixture(attribute: TokenStream, item: TokenStream) -> TokenStream { - let test_fn = parse_macro_input!(item as ItemFn); - let configuration = parse_macro_input!(attribute as FixtureConfiguration); - - let result = generate_fixtures(test_fn, &configuration); - - let stream = match result { - Ok(output) => output, - Err(err) => err.to_compile_error(), - }; - - TokenStream::from(stream) -} - -fn generate_fixtures( - mut test_fn: ItemFn, - configuration: &FixtureConfiguration, -) -> syn::Result { - // Remove the fixtures attribute - test_fn - .attrs - .retain(|attr| !attr.path().is_ident("fixtures")); - - // Extract the name of the only argument of the test function. - let last_arg = test_fn.sig.inputs.last(); - let path_ident = match (test_fn.sig.inputs.len(), last_arg) { - (1, Some(last_arg)) => match last_arg { - FnArg::Typed(typed) => match typed.pat.as_ref() { - Pat::Ident(ident) => ident.ident.clone(), - pat => { - return Err(Error::new( - pat.span(), - "#[fixture] function argument name must be an identifier", - )); - } - }, - FnArg::Receiver(receiver) => { - return Err(Error::new( - receiver.span(), - "#[fixture] function argument name must be an identifier", - )); - } - }, - _ => { - return Err(Error::new( - test_fn.sig.inputs.span(), - "#[fixture] function must have exactly one argument with the type '&Path'", - )); - } - }; - - // Remove all arguments - test_fn.sig.inputs.clear(); - - let crate_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect( - "#[fixture] requires CARGO_MANIFEST_DIR to be set during the build to resolve the relative paths to the test files.", - )); - - let pattern = if configuration.pattern.as_str().starts_with('/') { - Cow::from(configuration.pattern.as_str()) - } else { - Cow::from(format!( - "{}/{}", - crate_dir - .to_str() - .expect("CARGO_MANIFEST_DIR must point to a directory with a UTF8 path"), - configuration.pattern.as_str() - )) - }; - - let files = glob(&pattern).expect("Pattern to be valid").flatten(); - let mut modules = Modules::default(); - - for file in files { - if configuration - .exclude - .iter() - .any(|exclude| exclude.matches_path(&file)) - { - continue; - } - - let mut test_fn = test_fn.clone(); - - let test_name = file - .file_name() - // SAFETY: Glob only matches on file names. - .unwrap() - .to_str() - .expect("Expected path to be valid UTF8") - .replace('.', "_"); - - test_fn.sig.ident = format_ident!("{test_name}"); - - let path = file.as_os_str().to_str().unwrap(); - - test_fn.block.stmts.insert( - 0, - parse_quote!(let #path_ident = std::path::Path::new(#path);), - ); - - modules.push_test(Test { - path: file, - test_fn, - }); - } - - if modules.is_empty() { - return Err(Error::new( - configuration.pattern_span, - "No file matches the specified glob pattern", - )); - } - - let root = find_highest_common_ancestor_module(&modules.root); - - root.generate(&test_fn.sig.ident.to_string()) -} - -fn find_highest_common_ancestor_module(module: &Module) -> &Module { - let children = &module.children; - - if children.len() == 1 { - let (_, child) = children.iter().next().unwrap(); - - match child { - Child::Module(common_child) => find_highest_common_ancestor_module(common_child), - Child::Test(_) => module, - } - } else { - module - } -} - -#[derive(Debug)] -struct Test { - path: PathBuf, - test_fn: ItemFn, -} - -impl Test { - fn generate(&self, _: &str) -> proc_macro2::TokenStream { - let test_fn = &self.test_fn; - quote!(#test_fn) - } -} - -#[derive(Debug, Default)] -struct Module { - children: BTreeMap, -} - -impl Module { - fn generate(&self, name: &str) -> syn::Result { - let mut inner = Vec::with_capacity(self.children.len()); - - for (name, child) in &self.children { - inner.push(child.generate(name)?); - } - - let module_ident = format_ident!("{name}"); - - Ok(quote!( - mod #module_ident { - use super::*; - - #(#inner)* - } - )) - } -} - -#[derive(Debug)] -enum Child { - Module(Module), - Test(Test), -} - -impl Child { - fn generate(&self, name: &str) -> syn::Result { - match self { - Child::Module(module) => module.generate(name), - Child::Test(test) => Ok(test.generate(name)), - } - } -} - -#[derive(Debug, Default)] -struct Modules { - root: Module, -} - -impl Modules { - fn push_test(&mut self, test: Test) { - let mut components = test - .path - .as_path() - .components() - .skip_while(|c| matches!(c, Component::RootDir)) - .peekable(); - - let mut current = &mut self.root; - while let Some(component) = components.next() { - let name = component.as_os_str().to_str().unwrap(); - // A directory - if components.peek().is_some() { - let name = component.as_os_str().to_str().unwrap(); - let entry = current.children.entry(name.to_owned()); - - match entry.or_insert_with(|| Child::Module(Module::default())) { - Child::Module(module) => { - current = module; - } - Child::Test(_) => { - unreachable!() - } - } - } else { - // We reached the final component, insert the test - drop(components); - current.children.insert(name.to_owned(), Child::Test(test)); - break; - } - } - } - - fn is_empty(&self) -> bool { - self.root.children.is_empty() - } -}