[red-knot] Cleanup generated names of mdtest tests (#13831)

Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
Aditya Pratap Singh 2024-10-20 20:41:53 +05:30 committed by GitHub
parent 7ca3571194
commit 7fd8e30eed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 81 additions and 87 deletions

130
Cargo.lock generated
View file

@ -407,7 +407,7 @@ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -687,7 +687,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"strsim 0.10.0", "strsim 0.10.0",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -698,7 +698,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f"
dependencies = [ dependencies = [
"darling_core", "darling_core",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -750,6 +750,27 @@ dependencies = [
"crypto-common", "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]] [[package]]
name = "dirs" name = "dirs"
version = "4.0.0" version = "4.0.0"
@ -1246,7 +1267,7 @@ dependencies = [
"Inflector", "Inflector",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -1372,7 +1393,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2ae40017ac09cd2c6a53504cb3c871c7f2b41466eac5bc66ba63f39073b467b" checksum = "a2ae40017ac09cd2c6a53504cb3c871c7f2b41466eac5bc66ba63f39073b467b"
dependencies = [ dependencies = [
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -1827,7 +1848,7 @@ dependencies = [
"pest_meta", "pest_meta",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -2079,6 +2100,7 @@ dependencies = [
"camino", "camino",
"compact_str", "compact_str",
"countme", "countme",
"dir-test",
"hashbrown 0.15.0", "hashbrown 0.15.0",
"insta", "insta",
"itertools 0.13.0", "itertools 0.13.0",
@ -2086,7 +2108,6 @@ dependencies = [
"ordermap", "ordermap",
"red_knot_test", "red_knot_test",
"red_knot_vendored", "red_knot_vendored",
"rstest",
"ruff_db", "ruff_db",
"ruff_index", "ruff_index",
"ruff_python_ast", "ruff_python_ast",
@ -2267,12 +2288,6 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "relative-path"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2"
[[package]] [[package]]
name = "ring" name = "ring"
version = "0.17.8" version = "0.17.8"
@ -2288,33 +2303,6 @@ dependencies = [
"windows-sys 0.52.0", "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]] [[package]]
name = "ruff" name = "ruff"
version = "0.7.0" version = "0.7.0"
@ -2601,7 +2589,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"ruff_python_trivia", "ruff_python_trivia",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -2930,15 +2918,6 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" 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]] [[package]]
name = "rustix" name = "rustix"
version = "0.38.37" version = "0.38.37"
@ -3029,7 +3008,7 @@ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
"synstructure", "synstructure",
] ]
@ -3063,7 +3042,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"serde_derive_internals", "serde_derive_internals",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -3084,12 +3063,6 @@ version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b"
[[package]]
name = "semver"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.210" version = "1.0.210"
@ -3118,7 +3091,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -3129,7 +3102,7 @@ checksum = "330f01ce65a3a5fe59a60c82f3c9a024b573b8a6e875bd233fe5f934e71d54e3"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -3152,7 +3125,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -3193,7 +3166,7 @@ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -3295,7 +3268,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"rustversion", "rustversion",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -3304,6 +3277,17 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" 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]] [[package]]
name = "syn" name = "syn"
version = "2.0.79" version = "2.0.79"
@ -3323,7 +3307,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -3386,7 +3370,7 @@ dependencies = [
"cfg-if", "cfg-if",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -3397,7 +3381,7 @@ checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
"test-case-core", "test-case-core",
] ]
@ -3418,7 +3402,7 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -3530,7 +3514,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -3788,7 +3772,7 @@ checksum = "ee1cd046f83ea2c4e920d6ee9f7c3537ef928d75dce5d84a87c2c5d6b3999a3a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -3874,7 +3858,7 @@ dependencies = [
"once_cell", "once_cell",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -3908,7 +3892,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -3942,7 +3926,7 @@ checksum = "c97b2ef2c8d627381e51c071c2ab328eac606d3f69dd82bcbca20a9e389d95f0"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]
@ -4230,7 +4214,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.79",
] ]
[[package]] [[package]]

View file

@ -65,6 +65,7 @@ compact_str = "0.8.0"
criterion = { version = "0.5.1", default-features = false } criterion = { version = "0.5.1", default-features = false }
crossbeam = { version = "0.8.4" } crossbeam = { version = "0.8.4" }
dashmap = { version = "6.0.1" } dashmap = { version = "6.0.1" }
dir-test = { version = "0.3.0" }
drop_bomb = { version = "0.1.5" } drop_bomb = { version = "0.1.5" }
env_logger = { version = "0.11.0" } env_logger = { version = "0.11.0" }
etcetera = { version = "0.8.0" } etcetera = { version = "0.8.0" }
@ -114,7 +115,6 @@ quote = { version = "1.0.23" }
rand = { version = "0.8.5" } rand = { version = "0.8.5" }
rayon = { version = "1.10.0" } rayon = { version = "1.10.0" }
regex = { version = "1.10.2" } regex = { version = "1.10.2" }
rstest = { version = "0.22.0", default-features = false }
rustc-hash = { version = "2.0.0" } rustc-hash = { version = "2.0.0" }
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "b14be5c0392f4c55eca60b92e457a35549372382" } salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "b14be5c0392f4c55eca60b92e457a35549372382" }
schemars = { version = "0.8.16" } schemars = { version = "0.8.16" }

View file

@ -43,8 +43,8 @@ red_knot_test = { workspace = true }
red_knot_vendored = { workspace = true } red_knot_vendored = { workspace = true }
anyhow = { workspace = true } anyhow = { workspace = true }
dir-test = {workspace = true}
insta = { workspace = true } insta = { workspace = true }
rstest = { workspace = true }
tempfile = { workspace = true } tempfile = { workspace = true }
[lints] [lints]

View file

@ -1,14 +1,24 @@
use dir_test::{dir_test, Fixture};
use red_knot_test::run; 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. /// See `crates/red_knot_test/README.md` for documentation on these tests.
#[rstest::rstest] #[dir_test(
fn mdtest(#[files("resources/mdtest/**/*.md")] path: PathBuf) { dir: "$CARGO_MANIFEST_DIR/resources/mdtest",
let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")) glob: "**/*.md"
.join("resources") )]
.join("mdtest") #[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() .canonicalize()
.unwrap(); .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);
} }

View file

@ -34,14 +34,14 @@ syntax, it's just how this README embeds an example mdtest Markdown document.)
See actual example mdtest suites in 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). [`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`, > 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 > 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 > 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) > [`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. > 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, > 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 > 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. > following the addition of the new test file.

View file

@ -5,7 +5,7 @@ use ruff_db::files::system_path_to_file;
use ruff_db::parsed::parsed_module; use ruff_db::parsed::parsed_module;
use ruff_db::system::{DbWithTestSystem, SystemPathBuf}; use ruff_db::system::{DbWithTestSystem, SystemPathBuf};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::path::PathBuf; use std::path::Path;
type Failures = BTreeMap<SystemPathBuf, matcher::FailuresByLine>; type Failures = BTreeMap<SystemPathBuf, matcher::FailuresByLine>;
@ -19,7 +19,7 @@ mod parser;
/// ///
/// Panic on test failure, and print failure details. /// Panic on test failure, and print failure details.
#[allow(clippy::print_stdout)] #[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 source = std::fs::read_to_string(path).unwrap();
let suite = match test_parser::parse(title, &source) { let suite = match test_parser::parse(title, &source) {
Ok(suite) => suite, Ok(suite) => suite,