You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In serde_test, the family of assert_tokens functions, while useful, would be even more useful if converted to macros. During testing, the location of a failure is reported as the location where the panic occurred, which means assert_tokens failures get traced to the serde_test source file, e.g., /Users/rben01/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_test-1.0.130/src/ser.rs:111:9. If these functions were replaced with macros then the failure would get traced to the correct location in the user's source file. Example, with comments labeling the line they're on:
// Line 160#[test]fntest_fn(){let test_fn = || {assert!(false);//Line 165};test_fn();}// Line 170#[test]fntest_macro(){macro_rules! test_macro {//// Line 175() => {
assert!(false);
};}// Line 180test_macro!();}
The failure in test_fn is reported as being on line 164, where the assert!(false) is, whereas the failure in test_macro is reported as being on line 181, where the failing use of the test_macro! occurred.
In general, converting functions to macros "just because" does not make sense. But when those functions are intended to be used in a testing context, then converting them to macros does make sense because macros preserve line numbers when they fail, whereas functions do not.
The text was updated successfully, but these errors were encountered:
In
serde_test
, the family ofassert_tokens
functions, while useful, would be even more useful if converted to macros. During testing, the location of a failure is reported as the location where the panic occurred, which meansassert_tokens
failures get traced to theserde_test
source file, e.g.,/Users/rben01/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_test-1.0.130/src/ser.rs:111:9
. If these functions were replaced with macros then the failure would get traced to the correct location in the user's source file. Example, with comments labeling the line they're on:The failure in
test_fn
is reported as being on line 164, where theassert!(false)
is, whereas the failure intest_macro
is reported as being on line 181, where the failing use of thetest_macro!
occurred.In general, converting functions to macros "just because" does not make sense. But when those functions are intended to be used in a testing context, then converting them to macros does make sense because macros preserve line numbers when they fail, whereas functions do not.
The text was updated successfully, but these errors were encountered: