diff --git a/.github/workflows/continuous-integration-workflow.yaml b/.github/workflows/continuous-integration-workflow.yaml index 3dcc39df5..acd5e7e94 100644 --- a/.github/workflows/continuous-integration-workflow.yaml +++ b/.github/workflows/continuous-integration-workflow.yaml @@ -96,7 +96,12 @@ jobs: - name: test run: cargo test --workspace --all-targets - name: test no-default-features - run: cargo test --no-default-features + run: cargo test -p prost-build -p prost-derive -p prost-types --all-targets --no-default-features + # Run doc tests separately: https://github.com/rust-lang/cargo/issues/6669 + - name: test doc + run: cargo test --workspace --doc + - name: test doc + run: cargo test -p prost-build -p prost-derive -p prost-types --doc --no-default-features kani: runs-on: ubuntu-latest diff --git a/prost-build/src/fixtures/helloworld/_expected_helloworld.rs b/prost-build/src/fixtures/helloworld/_expected_helloworld.rs index a64c4da3c..2f05c46ed 100644 --- a/prost-build/src/fixtures/helloworld/_expected_helloworld.rs +++ b/prost-build/src/fixtures/helloworld/_expected_helloworld.rs @@ -2,14 +2,14 @@ #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct Message { - #[prost(string, tag = "1")] + #[prost(string, tag="1")] pub say: ::prost::alloc::string::String, } #[derive(derive_builder::Builder)] #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct Response { - #[prost(string, tag = "1")] + #[prost(string, tag="1")] pub say: ::prost::alloc::string::String, } #[some_enum_attr(u8)] diff --git a/prost-build/src/fixtures/helloworld/_expected_helloworld_formatted.rs b/prost-build/src/fixtures/helloworld/_expected_helloworld_formatted.rs new file mode 100644 index 000000000..a64c4da3c --- /dev/null +++ b/prost-build/src/fixtures/helloworld/_expected_helloworld_formatted.rs @@ -0,0 +1,44 @@ +#[derive(derive_builder::Builder)] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Message { + #[prost(string, tag = "1")] + pub say: ::prost::alloc::string::String, +} +#[derive(derive_builder::Builder)] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Response { + #[prost(string, tag = "1")] + pub say: ::prost::alloc::string::String, +} +#[some_enum_attr(u8)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum ServingStatus { + Unknown = 0, + Serving = 1, + NotServing = 2, +} +impl ServingStatus { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + ServingStatus::Unknown => "UNKNOWN", + ServingStatus::Serving => "SERVING", + ServingStatus::NotServing => "NOT_SERVING", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "UNKNOWN" => Some(Self::Unknown), + "SERVING" => Some(Self::Serving), + "NOT_SERVING" => Some(Self::NotServing), + _ => None, + } + } +} diff --git a/prost-build/src/lib.rs b/prost-build/src/lib.rs index 96a8f43a5..12c0e63af 100644 --- a/prost-build/src/lib.rs +++ b/prost-build/src/lib.rs @@ -887,12 +887,13 @@ impl Config { /// # Example `build.rs` /// /// ```rust,no_run + /// # use prost_types::FileDescriptorSet; /// # fn fds() -> FileDescriptorSet { todo!() } /// fn main() -> std::io::Result<()> { /// let file_descriptor_set = fds(); /// /// prost_build::Config::new() - /// .compile_fds(file_descriptor_set)?; + /// .compile_fds(file_descriptor_set) /// } /// ``` pub fn compile_fds(&mut self, fds: FileDescriptorSet) -> Result<()> { @@ -1395,11 +1396,12 @@ pub fn compile_protos(protos: &[impl AsRef], includes: &[impl AsRef] /// /// # Example /// ```rust,no_run +/// # use prost_types::FileDescriptorSet; /// # fn fds() -> FileDescriptorSet { todo!() } /// fn main() -> std::io::Result<()> { /// let file_descriptor_set = fds(); /// -/// prost_build::compile_fds(file_descriptor_set)?; +/// prost_build::compile_fds(file_descriptor_set) /// } /// ``` pub fn compile_fds(fds: FileDescriptorSet) -> Result<()> { @@ -1585,6 +1587,11 @@ mod tests { .as_path() .display() .to_string(); + #[cfg(feature = "format")] + let expected_content = + read_all_content("src/fixtures/helloworld/_expected_helloworld_formatted.rs") + .replace("\r\n", "\n"); + #[cfg(not(feature = "format"))] let expected_content = read_all_content("src/fixtures/helloworld/_expected_helloworld.rs") .replace("\r\n", "\n"); let content = read_all_content(&out_file).replace("\r\n", "\n"); diff --git a/prost-types/src/datetime.rs b/prost-types/src/datetime.rs index f6c3cca1c..56a6209d9 100644 --- a/prost-types/src/datetime.rs +++ b/prost-types/src/datetime.rs @@ -586,12 +586,8 @@ impl From for Timestamp { #[cfg(test)] mod tests { - - use std::convert::TryFrom; - - use proptest::prelude::*; - use super::*; + use proptest::prelude::*; #[test] fn test_min_max() { @@ -611,6 +607,7 @@ mod tests { ); } + #[cfg(feature = "std")] #[test] fn test_datetime_from_timestamp() { let case = |expected: &str, secs: i64, nanos: i32| { @@ -850,6 +847,7 @@ mod tests { ) } + #[cfg(feature = "std")] #[test] fn check_duration_parse_to_string_roundtrip( duration in core::time::Duration::arbitrary(), diff --git a/prost-types/src/lib.rs b/prost-types/src/lib.rs index dc41bdae1..7d60f885c 100644 --- a/prost-types/src/lib.rs +++ b/prost-types/src/lib.rs @@ -423,11 +423,12 @@ impl fmt::Display for Timestamp { #[cfg(test)] mod tests { - use std::time::{self, SystemTime, UNIX_EPOCH}; + use super::*; + #[cfg(feature = "std")] use proptest::prelude::*; - - use super::*; + #[cfg(feature = "std")] + use std::time::{self, SystemTime, UNIX_EPOCH}; #[cfg(feature = "std")] proptest! {