mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
mdtest: allow specifying a specific test inside a file (#14670)
This commit is contained in:
parent
b3b2c982cd
commit
a6402fb51e
2 changed files with 21 additions and 2 deletions
|
@ -184,8 +184,11 @@ The tests are run independently, in independent in-memory file systems and with
|
||||||
[Salsa](https://github.com/salsa-rs/salsa) databases. This means that each is a from-scratch run of
|
[Salsa](https://github.com/salsa-rs/salsa) databases. This means that each is a from-scratch run of
|
||||||
the type checker, with no data persisting from any previous test.
|
the type checker, with no data persisting from any previous test.
|
||||||
|
|
||||||
Due to `cargo test` limitations, an entire test suite (Markdown file) is run as a single Rust test,
|
It is possible to filter to individual tests within a single markdown file using the
|
||||||
so it's not possible to select individual tests within it to run.
|
`MDTEST_TEST_FILTER` environment variable. This variable will match any tests which contain the
|
||||||
|
value as a case-sensitive substring in its name. An example test name is
|
||||||
|
`unpacking.md - Unpacking - Tuple - Multiple assignment`, which contains the name of the markdown
|
||||||
|
file and its parent headers joined together with hyphens.
|
||||||
|
|
||||||
## Structured test suites
|
## Structured test suites
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@ mod diagnostic;
|
||||||
mod matcher;
|
mod matcher;
|
||||||
mod parser;
|
mod parser;
|
||||||
|
|
||||||
|
const MDTEST_TEST_FILTER: &str = "MDTEST_TEST_FILTER";
|
||||||
|
|
||||||
/// Run `path` as a markdown test suite with given `title`.
|
/// Run `path` as a markdown test suite with given `title`.
|
||||||
///
|
///
|
||||||
/// Panic on test failure, and print failure details.
|
/// Panic on test failure, and print failure details.
|
||||||
|
@ -30,8 +32,13 @@ pub fn run(path: &Path, long_title: &str, short_title: &str) {
|
||||||
|
|
||||||
let mut db = db::Db::setup(SystemPathBuf::from("/src"));
|
let mut db = db::Db::setup(SystemPathBuf::from("/src"));
|
||||||
|
|
||||||
|
let filter = std::env::var(MDTEST_TEST_FILTER).ok();
|
||||||
let mut any_failures = false;
|
let mut any_failures = false;
|
||||||
for test in suite.tests() {
|
for test in suite.tests() {
|
||||||
|
if filter.as_ref().is_some_and(|f| !test.name().contains(f)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove all files so that the db is in a "fresh" state.
|
// Remove all files so that the db is in a "fresh" state.
|
||||||
db.memory_file_system().remove_all();
|
db.memory_file_system().remove_all();
|
||||||
Files::sync_all(&mut db);
|
Files::sync_all(&mut db);
|
||||||
|
@ -54,6 +61,15 @@ pub fn run(path: &Path, long_title: &str, short_title: &str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"\nTo rerun this specific test, set the environment variable: {MDTEST_TEST_FILTER}=\"{}\"",
|
||||||
|
test.name()
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"{MDTEST_TEST_FILTER}=\"{}\" cargo test -p red_knot_python_semantic --test mdtest",
|
||||||
|
test.name()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue