Skip to content

Commit de2a009

Browse files
authored
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
1 parent 5fd9c86 commit de2a009

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

tests/build.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,10 @@ fn main() {
3232
"Foo.Bar_Baz.Foo_barBaz.fuzz_buster",
3333
"#[derive(Eq, PartialOrd, Ord)]",
3434
);
35-
config.type_attribute("Foo.Custom.Attrs.Msg", "#[allow(missing_docs)]");
36-
config.type_attribute("Foo.Custom.Attrs.Msg.field", "/// Oneof docs");
37-
config.type_attribute("Foo.Custom.Attrs.AnEnum", "#[allow(missing_docs)]");
38-
config.type_attribute("Foo.Custom.Attrs.AnotherEnum", "/// Oneof docs");
3935
config.type_attribute(
4036
"Foo.Custom.OneOfAttrs.Msg.field",
4137
"#[derive(Eq, PartialOrd, Ord)]",
4238
);
43-
config.field_attribute("Foo.Custom.Attrs.AnotherEnum.C", "/// The C docs");
44-
config.field_attribute("Foo.Custom.Attrs.AnotherEnum.D", "/// The D docs");
45-
config.field_attribute("Foo.Custom.Attrs.Msg.field.a", "/// Oneof A docs");
46-
config.field_attribute("Foo.Custom.Attrs.Msg.field.b", "/// Oneof B docs");
4739

4840
config.file_descriptor_set_path(
4941
PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR environment variable not set"))
@@ -62,7 +54,15 @@ fn main() {
6254
.compile_protos(&[src.join("recursive_oneof.proto")], includes)
6355
.unwrap();
6456

65-
config
57+
prost_build::Config::new()
58+
.type_attribute("custom_attributes.Msg", "#[allow(missing_docs)]")
59+
.type_attribute("custom_attributes.Msg.field", "/// Oneof docs")
60+
.type_attribute("custom_attributes.AnEnum", "#[allow(missing_docs)]")
61+
.type_attribute("custom_attributes.AnotherEnum", "/// Oneof docs")
62+
.field_attribute("custom_attributes.AnotherEnum.C", "/// The C docs")
63+
.field_attribute("custom_attributes.AnotherEnum.D", "/// The D docs")
64+
.field_attribute("custom_attributes.Msg.field.a", "/// Oneof A docs")
65+
.field_attribute("custom_attributes.Msg.field.b", "/// Oneof B docs")
6666
.compile_protos(&[src.join("custom_attributes.proto")], includes)
6767
.unwrap();
6868

tests/src/custom_attributes.proto

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
syntax = "proto3";
22

3-
package Foo.Custom.Attrs;
3+
package custom_attributes;
44

55
message Msg {
6+
oneof field {
7+
string a = 1;
8+
bytes b = 2;
9+
}
610
}
711

812
enum AnEnum {

tests/src/custom_attributes.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//! This tests the custom attributes support by abusing docs.
2+
//!
3+
//! Docs really are full-blown attributes. So we use them to ensure we can place them on everything
4+
//! we need. If they aren't put onto something or allowed not to be there (by the generator),
5+
//! compilation fails.
6+
#![deny(missing_docs)]
7+
8+
include!(concat!(env!("OUT_DIR"), "/custom_attributes.rs"));

tests/src/lib.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ mod custom_debug;
6262
// Must be `pub` as doc tests are only executed on public types.
6363
pub mod disable_comments;
6464

65+
#[cfg(test)]
66+
// Must be `pub` as `missing_docs` lint is only executed on public types.
67+
pub mod custom_attributes;
68+
6569
mod test_enum_named_option_value {
6670
include!(concat!(env!("OUT_DIR"), "/myenum.optionn.rs"));
6771
}
@@ -92,16 +96,6 @@ pub mod recursive_oneof {
9296
include!(concat!(env!("OUT_DIR"), "/recursive_oneof.rs"));
9397
}
9498

95-
/// This tests the custom attributes support by abusing docs.
96-
///
97-
/// Docs really are full-blown attributes. So we use them to ensure we can place them on everything
98-
/// we need. If they aren't put onto something or allowed not to be there (by the generator),
99-
/// compilation fails.
100-
#[deny(missing_docs)]
101-
pub mod custom_attributes {
102-
include!(concat!(env!("OUT_DIR"), "/foo.custom.attrs.rs"));
103-
}
104-
10599
/// Also for testing custom attributes, but on oneofs.
106100
///
107101
/// Unfortunately, an OneOf field generates a companion module in the .rs file. There's no

0 commit comments

Comments
 (0)