From 387e9cfe8b9645afb2cdcc2d26cc60d900c8ca73 Mon Sep 17 00:00:00 2001 From: Casper Meijn Date: Fri, 1 Nov 2024 14:35:47 +0100 Subject: [PATCH] test(custom_debug): Merge `skip_debug` into `custom_debug` (#1178) - Rename `skip_debug` into `custom_debug` - Move related tests to the module - Make config dependency explicit in `build.rs` --- tests/build.rs | 4 ++-- tests/src/{skip_debug.rs => custom_debug.rs} | 22 ++++++++++++-------- tests/src/lib.rs | 17 +++------------ 3 files changed, 18 insertions(+), 25 deletions(-) rename tests/src/{skip_debug.rs => custom_debug.rs} (80%) diff --git a/tests/build.rs b/tests/build.rs index b707fb270..f90d36588 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -44,7 +44,6 @@ fn main() { config.field_attribute("Foo.Custom.Attrs.AnotherEnum.D", "/// The D docs"); config.field_attribute("Foo.Custom.Attrs.Msg.field.a", "/// Oneof A docs"); config.field_attribute("Foo.Custom.Attrs.Msg.field.b", "/// Oneof B docs"); - config.skip_debug(["custom_debug.Msg"]); config.file_descriptor_set_path( PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR environment variable not set")) @@ -103,7 +102,8 @@ fn main() { .compile_protos(&[src.join("default_string_escape.proto")], includes) .unwrap(); - config + prost_build::Config::new() + .skip_debug(["custom_debug.Msg"]) .compile_protos(&[src.join("custom_debug.proto")], includes) .unwrap(); diff --git a/tests/src/skip_debug.rs b/tests/src/custom_debug.rs similarity index 80% rename from tests/src/skip_debug.rs rename to tests/src/custom_debug.rs index 278f5f100..d67af02ec 100644 --- a/tests/src/skip_debug.rs +++ b/tests/src/custom_debug.rs @@ -1,27 +1,31 @@ //! Tests for skipping the default Debug implementation. -use std::fmt; +include!(concat!(env!("OUT_DIR"), "/custom_debug.rs")); -use prost::alloc::format; -#[cfg(not(feature = "std"))] -use prost::alloc::string::String; +use alloc::format; +use alloc::string::String; +use alloc::string::ToString; +use core::fmt; -use crate::custom_debug::{msg, AnEnum, Msg}; -use crate::message_encoding::BasicEnumeration; +impl fmt::Debug for Msg { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("Msg {..}") + } +} /// A special case with a tuple struct #[test] fn tuple_struct_custom_debug() { #[derive(Clone, PartialEq, prost::Message)] #[prost(skip_debug)] - struct NewType(#[prost(enumeration = "BasicEnumeration", tag = "5")] i32); + struct NewType(#[prost(enumeration = "AnEnum", tag = "5")] i32); impl fmt::Debug for NewType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("NewType(custom_debug)") } } assert_eq!( - format!("{:?}", NewType(BasicEnumeration::TWO as i32)), + format!("{:?}", NewType(AnEnum::B as i32)), "NewType(custom_debug)" ); assert_eq!(format!("{:?}", NewType(42)), "NewType(custom_debug)"); @@ -59,7 +63,7 @@ impl fmt::Debug for MessageWithOneofCustomDebug { /// Enumerations inside oneofs #[test] fn oneof_with_enum_custom_debug() { - let of = OneofWithEnumCustomDebug::Enumeration(BasicEnumeration::TWO as i32); + let of = OneofWithEnumCustomDebug::Enumeration(AnEnum::B as i32); assert_eq!(format!("{:?}", of), "OneofWithEnumCustomDebug {..}"); let msg = MessageWithOneofCustomDebug { of: Some(of) }; assert_eq!(format!("{:?}", msg), "MessageWithOneofCustomDebug {..}"); diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 473617d18..37347eacc 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -49,9 +49,6 @@ mod no_shadowed_types; #[cfg(test)] mod no_unused_results; #[cfg(test)] -#[cfg(feature = "std")] -mod skip_debug; -#[cfg(test)] mod submessage_without_package; #[cfg(test)] mod type_names; @@ -59,6 +56,9 @@ mod type_names; #[cfg(test)] mod boxed_field; +#[cfg(test)] +mod custom_debug; + mod test_enum_named_option_value { include!(concat!(env!("OUT_DIR"), "/myenum.optionn.rs")); } @@ -89,17 +89,6 @@ pub mod recursive_oneof { include!(concat!(env!("OUT_DIR"), "/recursive_oneof.rs")); } -#[cfg(feature = "std")] -pub mod custom_debug { - use std::fmt; - include!(concat!(env!("OUT_DIR"), "/custom_debug.rs")); - impl fmt::Debug for Msg { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str("Msg {..}") - } - } -} - /// This tests the custom attributes support by abusing docs. /// /// Docs really are full-blown attributes. So we use them to ensure we can place them on everything