fix: Make sure all tests are run during CI runs

Had to fix the tests in util/src/result.rs.
This commit is contained in:
Karolin Varner
2024-01-02 19:51:20 +01:00
committed by wucke13
parent 85c447052e
commit e3b72487db
2 changed files with 21 additions and 15 deletions

View File

@@ -101,7 +101,7 @@ jobs:
# liboqs requires quite a lot of stack memory, thus we adjust # liboqs requires quite a lot of stack memory, thus we adjust
# the default stack size picked for new threads (which is used # the default stack size picked for new threads (which is used
# by `cargo test`) to be _big enough_. Setting it to 8 MiB # by `cargo test`) to be _big enough_. Setting it to 8 MiB
- run: RUST_MIN_STACK=8388608 cargo test - run: RUST_MIN_STACK=8388608 cargo test --workspace
cargo-test-nix-devshell-x86_64-linux: cargo-test-nix-devshell-x86_64-linux:
runs-on: runs-on:
@@ -124,7 +124,7 @@ jobs:
with: with:
name: rosenpass name: rosenpass
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
- run: nix develop --command cargo test - run: nix develop --command cargo test --workspace
cargo-fuzz: cargo-fuzz:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@@ -35,25 +35,30 @@ pub trait GuaranteedValue {
/// ``` /// ```
/// use std::num::Wrapping; /// use std::num::Wrapping;
/// use std::result::Result; /// use std::result::Result;
/// use std::convert::Infallible /// use std::convert::Infallible;
/// use std::ops::Add;
/// ///
/// trait FailableAddition { /// use rosenpass_util::result::{Guaranteed, GuaranteedValue};
///
/// trait FailableAddition: Sized {
/// type Error; /// type Error;
/// fn failable_addition(&self, other: &Self) -> Result<Self, Self::Error>; /// fn failable_addition(&self, other: &Self) -> Result<Self, Self::Error>;
/// } /// }
/// ///
/// #[derive(Copy, Clone, Debug, Eq, PartialEq)]
/// struct OverflowError; /// struct OverflowError;
/// ///
/// impl<T> FailableAddition for Wrapping<T> { /// impl<T> FailableAddition for Wrapping<T>
/// where for <'a> &'a Wrapping<T>: Add<Output = Wrapping<T>> {
/// type Error = Infallible; /// type Error = Infallible;
/// fn failable_addition(&self, other: &Self) -> Guaranteed<Self> { /// fn failable_addition(&self, other: &Self) -> Guaranteed<Self> {
/// self + other /// Ok(self + other)
/// } /// }
/// } /// }
/// ///
/// impl<T> FailableAddition for u32 { /// impl FailableAddition for u32 {
/// type Error = Infallible; /// type Error = OverflowError;
/// fn failable_addition(&self, other: &Self) -> Guaranteed<Self> { /// fn failable_addition(&self, other: &Self) -> Result<Self, Self::Error> {
/// match self.checked_add(*other) { /// match self.checked_add(*other) {
/// Some(v) => Ok(v), /// Some(v) => Ok(v),
/// None => Err(OverflowError), /// None => Err(OverflowError),
@@ -64,10 +69,11 @@ pub trait GuaranteedValue {
/// fn failable_multiply<T>(a: &T, b: u32) /// fn failable_multiply<T>(a: &T, b: u32)
/// -> Result<T, T::Error> /// -> Result<T, T::Error>
/// where /// where
/// T: FailableAddition<Error> { /// T: FailableAddition {
/// assert!(b >= 2); // Acceptable only because this is for demonstration purposes
/// let mut accu = a.failable_addition(a)?; /// let mut accu = a.failable_addition(a)?;
/// for _ in ..(b-1) { /// for _ in 2..b {
/// accu.failable_addition(a)?; /// accu = accu.failable_addition(a)?;
/// } /// }
/// Ok(accu) /// Ok(accu)
/// } /// }
@@ -75,12 +81,12 @@ pub trait GuaranteedValue {
/// // We can use .guaranteed() with Wrapping<u32>, since the operation uses /// // We can use .guaranteed() with Wrapping<u32>, since the operation uses
/// // the Infallible error type. /// // the Infallible error type.
/// // We can also use unwrap which just happens to not raise an error. /// // We can also use unwrap which just happens to not raise an error.
/// assert_eq!(failable_multiply(&Wrapping::new(42u32), 3).guaranteed(), 126); /// assert_eq!(failable_multiply(&Wrapping(42u32), 3).guaranteed(), Wrapping(126));
/// assert_eq!(failable_multiply(&Wrapping::new(42u32), 3).unwrap(), 126); /// assert_eq!(failable_multiply(&Wrapping(42u32), 3).unwrap(), Wrapping(126));
/// ///
/// // We can not use .guaranteed() with u32, since there can be an error. /// // We can not use .guaranteed() with u32, since there can be an error.
/// // We can however use unwrap(), which may panic /// // We can however use unwrap(), which may panic
/// assert_eq!(failable_multiply(&42u32, 3).guaranteed(), 126); // COMPILER ERROR /// //assert_eq!(failable_multiply(&42u32, 3).guaranteed(), 126); // COMPILER ERROR
/// assert_eq!(failable_multiply(&42u32, 3).unwrap(), 126); /// assert_eq!(failable_multiply(&42u32, 3).unwrap(), 126);
/// ``` /// ```
pub type Guaranteed<T> = Result<T, Infallible>; pub type Guaranteed<T> = Result<T, Infallible>;