1 use debug_rust_proto::DebugMsg; 2 use googletest::prelude::*; 3 use optimize_for_lite_rust_proto::OptimizeForLiteTestMessage; 4 5 #[cfg(not(lite_runtime))] 6 #[gtest] test_debug()7fn test_debug() { 8 let mut msg = DebugMsg::new(); 9 msg.set_id(1); 10 msg.set_secret_user_data("password"); 11 12 assert_that!(format!("{msg:?}"), contains_substring("id: 1")); 13 assert_that!(format!("{msg:?}"), not(contains_substring("password"))); 14 } 15 16 #[cfg(lite_runtime)] 17 #[gtest] test_debug_lite()18fn test_debug_lite() { 19 let mut msg = DebugMsg::new(); 20 msg.set_id(1); 21 msg.set_secret_user_data("password"); 22 23 assert_that!(format!("{msg:?}"), contains_substring("MessageLite")); 24 assert_that!(format!("{msg:?}"), not(contains_substring("password"))); 25 } 26 27 /// A message with the option set to optimize for lite will behave as a lite 28 /// message regardless of the `lite_runtime` feature. Run this test not guarded 29 /// by the cfg(lite_runtime) and ensure it functions as lite. 30 #[gtest] test_optimize_for_lite_option()31fn test_optimize_for_lite_option() { 32 let mut msg = OptimizeForLiteTestMessage::new(); 33 msg.set_value("password"); 34 assert_that!(format!("{msg:?}"), contains_substring("MessageLite")); 35 assert_that!(format!("{msg:?}"), not(contains_substring("password"))); 36 } 37