Skip to content

Commit

Permalink
Fix corrupted tests and missing CI testing (#832)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucio Franco <[email protected]>
  • Loading branch information
ldm0 and LucioFranco authored Apr 3, 2023
1 parent 34d0e2b commit a4f5992
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 13 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/continuous-integration-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions prost-build/src/fixtures/helloworld/_expected_helloworld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Self> {
match value {
"UNKNOWN" => Some(Self::Unknown),
"SERVING" => Some(Self::Serving),
"NOT_SERVING" => Some(Self::NotServing),
_ => None,
}
}
}
11 changes: 9 additions & 2 deletions prost-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down Expand Up @@ -1395,11 +1396,12 @@ pub fn compile_protos(protos: &[impl AsRef<Path>], includes: &[impl AsRef<Path>]
///
/// # 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<()> {
Expand Down Expand Up @@ -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");
Expand Down
8 changes: 3 additions & 5 deletions prost-types/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,8 @@ impl From<DateTime> for Timestamp {

#[cfg(test)]
mod tests {

use std::convert::TryFrom;

use proptest::prelude::*;

use super::*;
use proptest::prelude::*;

#[test]
fn test_min_max() {
Expand All @@ -611,6 +607,7 @@ mod tests {
);
}

#[cfg(feature = "std")]
#[test]
fn test_datetime_from_timestamp() {
let case = |expected: &str, secs: i64, nanos: i32| {
Expand Down Expand Up @@ -850,6 +847,7 @@ mod tests {
)
}

#[cfg(feature = "std")]
#[test]
fn check_duration_parse_to_string_roundtrip(
duration in core::time::Duration::arbitrary(),
Expand Down
7 changes: 4 additions & 3 deletions prost-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down

0 comments on commit a4f5992

Please sign in to comment.