Skip to content

Commit 70f51e9

Browse files
authored
[ty] Print display of types when a property test fails (#20720)
1 parent 9a29f7a commit 70f51e9

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

crates/ty_python_semantic/src/types/property_tests.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,41 @@ use type_generation::{intersection, union};
3838
///
3939
/// where `t1`, `t2`, ..., `tn` are identifiers that represent arbitrary types, and `<property>`
4040
/// is an expression using these identifiers.
41-
///
4241
macro_rules! type_property_test {
4342
($test_name:ident, $db:ident, forall types $($types:ident),+ . $property:expr) => {
4443
#[quickcheck_macros::quickcheck]
4544
#[ignore]
4645
fn $test_name($($types: crate::types::property_tests::type_generation::Ty),+) -> bool {
4746
let $db = &crate::types::property_tests::setup::get_cached_db();
4847
$(let $types = $types.into_type($db);)+
48+
let result = $property;
49+
50+
if !result {
51+
println!("\nFailing types were:");
52+
$(println!("{}", $types.display($db));)+
53+
}
4954

50-
$property
55+
result
5156
}
5257
};
58+
5359
($test_name:ident, $db:ident, forall fully_static_types $($types:ident),+ . $property:expr) => {
5460
#[quickcheck_macros::quickcheck]
5561
#[ignore]
5662
fn $test_name($($types: crate::types::property_tests::type_generation::FullyStaticTy),+) -> bool {
5763
let $db = &crate::types::property_tests::setup::get_cached_db();
5864
$(let $types = $types.into_type($db);)+
65+
let result = $property;
5966

60-
$property
67+
if !result {
68+
println!("\nFailing types were:");
69+
$(println!("{}", $types.display($db));)+
70+
}
71+
72+
result
6173
}
6274
};
75+
6376
// A property test with a logical implication.
6477
($name:ident, $db:ident, forall $typekind:ident $($types:ident),+ . $premise:expr => $conclusion:expr) => {
6578
type_property_test!($name, $db, forall $typekind $($types),+ . !($premise) || ($conclusion));

0 commit comments

Comments
 (0)