From 079b6031fe1dfbc8f70004bfea5eae8e06df479c Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 8 Nov 2024 19:46:54 +0000 Subject: [PATCH] [red-knot] Improve mdtest output --- .../red_knot_python_semantic/tests/mdtest.rs | 21 +++++++------------ crates/red_knot_test/src/lib.rs | 8 +++---- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/crates/red_knot_python_semantic/tests/mdtest.rs b/crates/red_knot_python_semantic/tests/mdtest.rs index 74e07e65455a55..41c4a8cf3744e5 100644 --- a/crates/red_knot_python_semantic/tests/mdtest.rs +++ b/crates/red_knot_python_semantic/tests/mdtest.rs @@ -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( @@ -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); } diff --git a/crates/red_knot_test/src/lib.rs b/crates/red_knot_test/src/lib.rs index 058c7c6fca110f..83247e1e51bf24 100644 --- a/crates/red_knot_test/src/lib.rs +++ b/crates/red_knot_test/src/lib.rs @@ -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()) @@ -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}"); } } }