Skip to content

Commit

Permalink
[red-knot] Improve mdtest output
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Nov 8, 2024
1 parent 953e862 commit 079b603
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
21 changes: 7 additions & 14 deletions crates/red_knot_python_semantic/tests/mdtest.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use dir_test::{dir_test, Fixture};
use red_knot_test::run;
use std::path::Path;
use std::{ffi::OsStr, path::Path};

/// See `crates/red_knot_test/README.md` for documentation on these tests.
#[dir_test(
Expand All @@ -9,16 +8,10 @@ use std::path::Path;
)]
#[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 relative_path = path
.strip_prefix(crate_dir.to_str().unwrap())
.unwrap_or(path);

run(Path::new(path), relative_path);
let path = Path::new(fixture.path());
let crate_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let workspace_root = crate_dir.parent().and_then(Path::parent).unwrap();
let long_title = path.strip_prefix(workspace_root).unwrap().to_str().unwrap();
let short_title = path.file_name().and_then(OsStr::to_str).unwrap();
red_knot_test::run(path, long_title, short_title);
}
8 changes: 4 additions & 4 deletions crates/red_knot_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ mod parser;
///
/// Panic on test failure, and print failure details.
#[allow(clippy::print_stdout)]
pub fn run(path: &Path, title: &str) {
pub fn run(path: &Path, long_title: &str, short_title: &str) {
let source = std::fs::read_to_string(path).unwrap();
let suite = match test_parser::parse(title, &source) {
let suite = match test_parser::parse(short_title, &source) {
Ok(suite) => suite,
Err(err) => {
panic!("Error parsing `{}`: {err}", path.to_str().unwrap())
Expand Down Expand Up @@ -49,8 +49,8 @@ pub fn run(path: &Path, title: &str) {
for failure in failures {
let absolute_line_number =
backtick_line.checked_add(relative_line_number).unwrap();
let line_info = format!("{title}:{absolute_line_number}").cyan();
println!(" {line_info} {failure}");
let line_info = format!("{long_title}:{absolute_line_number}").cyan();
println!(" {line_info} {failure}");
}
}
}
Expand Down

0 comments on commit 079b603

Please sign in to comment.