Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(custom_debug): Merge skip_debug into custom_debug #1178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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();

Expand Down
22 changes: 13 additions & 9 deletions tests/src/skip_debug.rs → tests/src/custom_debug.rs
Original file line number Diff line number Diff line change
@@ -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)");
Expand Down Expand Up @@ -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 {..}");
Expand Down
17 changes: 3 additions & 14 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ 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;

#[cfg(test)]
mod boxed_field;

#[cfg(test)]
mod custom_debug;

mod test_enum_named_option_value {
include!(concat!(env!("OUT_DIR"), "/myenum.optionn.rs"));
}
Expand Down Expand Up @@ -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
Expand Down