From ad7f96df5860aab48f3f4c5f2ce077d601e8b803 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 6 Oct 2025 14:29:01 +0100 Subject: [PATCH] [ty] Print `display` of types when a property test fails --- .../src/types/property_tests.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/ty_python_semantic/src/types/property_tests.rs b/crates/ty_python_semantic/src/types/property_tests.rs index 3953b2ef9e865..2c3988bab4a3d 100644 --- a/crates/ty_python_semantic/src/types/property_tests.rs +++ b/crates/ty_python_semantic/src/types/property_tests.rs @@ -38,7 +38,6 @@ use type_generation::{intersection, union}; /// /// where `t1`, `t2`, ..., `tn` are identifiers that represent arbitrary types, and `` /// is an expression using these identifiers. -/// macro_rules! type_property_test { ($test_name:ident, $db:ident, forall types $($types:ident),+ . $property:expr) => { #[quickcheck_macros::quickcheck] @@ -46,20 +45,34 @@ macro_rules! type_property_test { fn $test_name($($types: crate::types::property_tests::type_generation::Ty),+) -> bool { let $db = &crate::types::property_tests::setup::get_cached_db(); $(let $types = $types.into_type($db);)+ + let result = $property; + + if !result { + println!("\nFailing types were:"); + $(println!("{}", $types.display($db));)+ + } - $property + result } }; + ($test_name:ident, $db:ident, forall fully_static_types $($types:ident),+ . $property:expr) => { #[quickcheck_macros::quickcheck] #[ignore] fn $test_name($($types: crate::types::property_tests::type_generation::FullyStaticTy),+) -> bool { let $db = &crate::types::property_tests::setup::get_cached_db(); $(let $types = $types.into_type($db);)+ + let result = $property; - $property + if !result { + println!("\nFailing types were:"); + $(println!("{}", $types.display($db));)+ + } + + result } }; + // A property test with a logical implication. ($name:ident, $db:ident, forall $typekind:ident $($types:ident),+ . $premise:expr => $conclusion:expr) => { type_property_test!($name, $db, forall $typekind $($types),+ . !($premise) || ($conclusion));