diff --git a/Cargo.lock b/Cargo.lock index 5435dcf943..f0c22e3ebb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -407,7 +407,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -687,7 +687,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn", + "syn 2.0.79", ] [[package]] @@ -698,7 +698,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core", "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -750,6 +750,27 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "dir-test" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c44bdf9319ad5223afb7eb15a7110452b0adf0373ea6756561b2c708eef0dd1" +dependencies = [ + "dir-test-macros", +] + +[[package]] +name = "dir-test-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "644f96047137dfaa7a09e34d4623f9e52a1926ecc25ba32ad2ba3fc422536b25" +dependencies = [ + "glob", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "dirs" version = "4.0.0" @@ -1246,7 +1267,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -1372,7 +1393,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2ae40017ac09cd2c6a53504cb3c871c7f2b41466eac5bc66ba63f39073b467b" dependencies = [ "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -1827,7 +1848,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -2079,6 +2100,7 @@ dependencies = [ "camino", "compact_str", "countme", + "dir-test", "hashbrown 0.15.0", "insta", "itertools 0.13.0", @@ -2086,7 +2108,6 @@ dependencies = [ "ordermap", "red_knot_test", "red_knot_vendored", - "rstest", "ruff_db", "ruff_index", "ruff_python_ast", @@ -2267,12 +2288,6 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" -[[package]] -name = "relative-path" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2" - [[package]] name = "ring" version = "0.17.8" @@ -2288,33 +2303,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rstest" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b423f0e62bdd61734b67cd21ff50871dfaeb9cc74f869dcd6af974fbcb19936" -dependencies = [ - "rstest_macros", - "rustc_version", -] - -[[package]] -name = "rstest_macros" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e1711e7d14f74b12a58411c542185ef7fb7f2e7f8ee6e2940a883628522b42" -dependencies = [ - "cfg-if", - "glob", - "proc-macro2", - "quote", - "regex", - "relative-path", - "rustc_version", - "syn", - "unicode-ident", -] - [[package]] name = "ruff" version = "0.7.0" @@ -2601,7 +2589,7 @@ dependencies = [ "proc-macro2", "quote", "ruff_python_trivia", - "syn", + "syn 2.0.79", ] [[package]] @@ -2930,15 +2918,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" -[[package]] -name = "rustc_version" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" -dependencies = [ - "semver", -] - [[package]] name = "rustix" version = "0.38.37" @@ -3029,7 +3008,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.79", "synstructure", ] @@ -3063,7 +3042,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn", + "syn 2.0.79", ] [[package]] @@ -3084,12 +3063,6 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" -[[package]] -name = "semver" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" - [[package]] name = "serde" version = "1.0.210" @@ -3118,7 +3091,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -3129,7 +3102,7 @@ checksum = "330f01ce65a3a5fe59a60c82f3c9a024b573b8a6e875bd233fe5f934e71d54e3" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -3152,7 +3125,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -3193,7 +3166,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -3295,7 +3268,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn", + "syn 2.0.79", ] [[package]] @@ -3304,6 +3277,17 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.79" @@ -3323,7 +3307,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -3386,7 +3370,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -3397,7 +3381,7 @@ checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.79", "test-case-core", ] @@ -3418,7 +3402,7 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -3530,7 +3514,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -3788,7 +3772,7 @@ checksum = "ee1cd046f83ea2c4e920d6ee9f7c3537ef928d75dce5d84a87c2c5d6b3999a3a" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -3874,7 +3858,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.79", "wasm-bindgen-shared", ] @@ -3908,7 +3892,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3942,7 +3926,7 @@ checksum = "c97b2ef2c8d627381e51c071c2ab328eac606d3f69dd82bcbca20a9e389d95f0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] @@ -4230,7 +4214,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 31656ce63c..1af4c047c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,7 @@ compact_str = "0.8.0" criterion = { version = "0.5.1", default-features = false } crossbeam = { version = "0.8.4" } dashmap = { version = "6.0.1" } +dir-test = { version = "0.3.0" } drop_bomb = { version = "0.1.5" } env_logger = { version = "0.11.0" } etcetera = { version = "0.8.0" } @@ -114,7 +115,6 @@ quote = { version = "1.0.23" } rand = { version = "0.8.5" } rayon = { version = "1.10.0" } regex = { version = "1.10.2" } -rstest = { version = "0.22.0", default-features = false } rustc-hash = { version = "2.0.0" } salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "b14be5c0392f4c55eca60b92e457a35549372382" } schemars = { version = "0.8.16" } diff --git a/crates/red_knot_python_semantic/Cargo.toml b/crates/red_knot_python_semantic/Cargo.toml index 7a74f5c307..27b7684544 100644 --- a/crates/red_knot_python_semantic/Cargo.toml +++ b/crates/red_knot_python_semantic/Cargo.toml @@ -43,8 +43,8 @@ red_knot_test = { workspace = true } red_knot_vendored = { workspace = true } anyhow = { workspace = true } +dir-test = {workspace = true} insta = { workspace = true } -rstest = { workspace = true } tempfile = { workspace = true } [lints] diff --git a/crates/red_knot_python_semantic/tests/mdtest.rs b/crates/red_knot_python_semantic/tests/mdtest.rs index 1215995700..74e07e6545 100644 --- a/crates/red_knot_python_semantic/tests/mdtest.rs +++ b/crates/red_knot_python_semantic/tests/mdtest.rs @@ -1,14 +1,24 @@ +use dir_test::{dir_test, Fixture}; use red_knot_test::run; -use std::path::PathBuf; +use std::path::Path; /// See `crates/red_knot_test/README.md` for documentation on these tests. -#[rstest::rstest] -fn mdtest(#[files("resources/mdtest/**/*.md")] path: PathBuf) { - let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("resources") - .join("mdtest") +#[dir_test( + dir: "$CARGO_MANIFEST_DIR/resources/mdtest", + glob: "**/*.md" +)] +#[allow(clippy::needless_pass_by_value)] +fn mdtest(fixture: Fixture<&str>) { + let path = fixture.path(); + + let crate_dir = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("resources/mdtest") .canonicalize() .unwrap(); - let title = path.strip_prefix(crate_dir).unwrap(); - run(&path, title.as_os_str().to_str().unwrap()); + + let relative_path = path + .strip_prefix(crate_dir.to_str().unwrap()) + .unwrap_or(path); + + run(Path::new(path), relative_path); } diff --git a/crates/red_knot_test/README.md b/crates/red_knot_test/README.md index 3c35862b4d..e53b9ca4ac 100644 --- a/crates/red_knot_test/README.md +++ b/crates/red_knot_test/README.md @@ -34,14 +34,14 @@ syntax, it's just how this README embeds an example mdtest Markdown document.) See actual example mdtest suites in [`crates/red_knot_python_semantic/resources/mdtest`](https://github.com/astral-sh/ruff/tree/main/crates/red_knot_python_semantic/resources/mdtest). -> ℹ️ Note: If you use `rstest` to generate a separate test for all Markdown files in a certain directory, +> ℹ️ Note: If you use `dir-test`, `rstest` or similar to generate a separate test for all Markdown files in a certain directory, > as with the example in `crates/red_knot_python_semantic/tests/mdtest.rs`, > you will likely want to also make sure that the crate the tests are in is rebuilt every time a > Markdown file is added or removed from the directory. See > [`crates/red_knot_python_semantic/build.rs`](https://github.com/astral-sh/ruff/tree/main/crates/red_knot_python_semantic/build.rs) > for an example of how to do this. > -> This is because `rstest` generates its tests at build time rather than at runtime. +> This is because these macros generate their tests at build time rather than at runtime. > Without the `build.rs` file to force a rebuild when a Markdown file is added or removed, > a new Markdown test suite might not be run unless some other change in the crate caused a rebuild > following the addition of the new test file. diff --git a/crates/red_knot_test/src/lib.rs b/crates/red_knot_test/src/lib.rs index 688b906ac0..58185da614 100644 --- a/crates/red_knot_test/src/lib.rs +++ b/crates/red_knot_test/src/lib.rs @@ -5,7 +5,7 @@ use ruff_db::files::system_path_to_file; use ruff_db::parsed::parsed_module; use ruff_db::system::{DbWithTestSystem, SystemPathBuf}; use std::collections::BTreeMap; -use std::path::PathBuf; +use std::path::Path; type Failures = BTreeMap; @@ -19,7 +19,7 @@ mod parser; /// /// Panic on test failure, and print failure details. #[allow(clippy::print_stdout)] -pub fn run(path: &PathBuf, title: &str) { +pub fn run(path: &Path, title: &str) { let source = std::fs::read_to_string(path).unwrap(); let suite = match test_parser::parse(title, &source) { Ok(suite) => suite,