From de2a00962d3e0b0ae0b9777b185ec7807b5a7c2d Mon Sep 17 00:00:00 2001 From: Casper Meijn Date: Wed, 20 Nov 2024 09:57:24 +0100 Subject: [PATCH] test(custom_attributes): Move module to separate file (#1187) - Use package name `custom_attributes` to ease finding related files - Make config dependency explicit in `build.rs` - Add oneof fields to make every `field_attribute` part of the test --- tests/build.rs | 18 +++++++++--------- tests/src/custom_attributes.proto | 6 +++++- tests/src/custom_attributes.rs | 8 ++++++++ tests/src/lib.rs | 14 ++++---------- 4 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 tests/src/custom_attributes.rs diff --git a/tests/build.rs b/tests/build.rs index 167be8f11..b78374d61 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -32,18 +32,10 @@ fn main() { "Foo.Bar_Baz.Foo_barBaz.fuzz_buster", "#[derive(Eq, PartialOrd, Ord)]", ); - config.type_attribute("Foo.Custom.Attrs.Msg", "#[allow(missing_docs)]"); - config.type_attribute("Foo.Custom.Attrs.Msg.field", "/// Oneof docs"); - config.type_attribute("Foo.Custom.Attrs.AnEnum", "#[allow(missing_docs)]"); - config.type_attribute("Foo.Custom.Attrs.AnotherEnum", "/// Oneof docs"); config.type_attribute( "Foo.Custom.OneOfAttrs.Msg.field", "#[derive(Eq, PartialOrd, Ord)]", ); - config.field_attribute("Foo.Custom.Attrs.AnotherEnum.C", "/// The C docs"); - 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.file_descriptor_set_path( PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR environment variable not set")) @@ -62,7 +54,15 @@ fn main() { .compile_protos(&[src.join("recursive_oneof.proto")], includes) .unwrap(); - config + prost_build::Config::new() + .type_attribute("custom_attributes.Msg", "#[allow(missing_docs)]") + .type_attribute("custom_attributes.Msg.field", "/// Oneof docs") + .type_attribute("custom_attributes.AnEnum", "#[allow(missing_docs)]") + .type_attribute("custom_attributes.AnotherEnum", "/// Oneof docs") + .field_attribute("custom_attributes.AnotherEnum.C", "/// The C docs") + .field_attribute("custom_attributes.AnotherEnum.D", "/// The D docs") + .field_attribute("custom_attributes.Msg.field.a", "/// Oneof A docs") + .field_attribute("custom_attributes.Msg.field.b", "/// Oneof B docs") .compile_protos(&[src.join("custom_attributes.proto")], includes) .unwrap(); diff --git a/tests/src/custom_attributes.proto b/tests/src/custom_attributes.proto index 5e6e4aed3..aecc7c6ef 100644 --- a/tests/src/custom_attributes.proto +++ b/tests/src/custom_attributes.proto @@ -1,8 +1,12 @@ syntax = "proto3"; -package Foo.Custom.Attrs; +package custom_attributes; message Msg { + oneof field { + string a = 1; + bytes b = 2; + } } enum AnEnum { diff --git a/tests/src/custom_attributes.rs b/tests/src/custom_attributes.rs new file mode 100644 index 000000000..329d552f7 --- /dev/null +++ b/tests/src/custom_attributes.rs @@ -0,0 +1,8 @@ +//! 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 +//! we need. If they aren't put onto something or allowed not to be there (by the generator), +//! compilation fails. +#![deny(missing_docs)] + +include!(concat!(env!("OUT_DIR"), "/custom_attributes.rs")); diff --git a/tests/src/lib.rs b/tests/src/lib.rs index c5dd29ff0..4c2f60d6e 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -62,6 +62,10 @@ mod custom_debug; // Must be `pub` as doc tests are only executed on public types. pub mod disable_comments; +#[cfg(test)] +// Must be `pub` as `missing_docs` lint is only executed on public types. +pub mod custom_attributes; + mod test_enum_named_option_value { include!(concat!(env!("OUT_DIR"), "/myenum.optionn.rs")); } @@ -92,16 +96,6 @@ pub mod recursive_oneof { include!(concat!(env!("OUT_DIR"), "/recursive_oneof.rs")); } -/// 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 -/// we need. If they aren't put onto something or allowed not to be there (by the generator), -/// compilation fails. -#[deny(missing_docs)] -pub mod custom_attributes { - include!(concat!(env!("OUT_DIR"), "/foo.custom.attrs.rs")); -} - /// Also for testing custom attributes, but on oneofs. /// /// Unfortunately, an OneOf field generates a companion module in the .rs file. There's no