Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Defensive traits: Ensure doc tests are also working without `debug_as…
Browse files Browse the repository at this point in the history
…sertions` (#12952)

* Defensive traits: Ensure doc tests are also working without `debug_assertions`

Closes: #12940

* Only run 'panics' tests if they will panic

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
bkchr and ggwpez authored Dec 16, 2022
1 parent 85f660f commit 0798d52
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions frame/support/src/traits/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ pub trait DefensiveMin<T> {
/// assert_eq!(4, 4_u32.defensive_min(4_u32));
/// ```
///
/// ```should_panic
/// ```#[cfg_attr(debug_assertions, should_panic)]
/// use frame_support::traits::DefensiveMin;
/// // min(4, 3) panics.
/// 4_u32.defensive_min(3_u32);
Expand All @@ -462,7 +462,7 @@ pub trait DefensiveMin<T> {
/// assert_eq!(3, 3_u32.defensive_strict_min(4_u32));
/// ```
///
/// ```should_panic
/// ```#[cfg_attr(debug_assertions, should_panic)]
/// use frame_support::traits::DefensiveMin;
/// // min(4, 4) panics.
/// 4_u32.defensive_strict_min(4_u32);
Expand Down Expand Up @@ -509,7 +509,7 @@ pub trait DefensiveMax<T> {
/// assert_eq!(4, 4_u32.defensive_max(4_u32));
/// ```
///
/// ```should_panic
/// ```#[cfg_attr(debug_assertions, should_panic)]
/// use frame_support::traits::DefensiveMax;
/// // max(4, 5) panics.
/// 4_u32.defensive_max(5_u32);
Expand All @@ -526,7 +526,7 @@ pub trait DefensiveMax<T> {
/// assert_eq!(4, 4_u32.defensive_strict_max(3_u32));
/// ```
///
/// ```should_panic
/// ```#[cfg_attr(debug_assertions, should_panic)]
/// use frame_support::traits::DefensiveMax;
/// // max(4, 4) panics.
/// 4_u32.defensive_strict_max(4_u32);
Expand Down Expand Up @@ -1353,6 +1353,7 @@ mod test {
}

#[test]
#[cfg(debug_assertions)]
#[should_panic(expected = "Defensive failure has been triggered!: \"DefensiveMin\"")]
fn defensive_min_panics() {
10_u32.defensive_min(9_u32);
Expand All @@ -1365,6 +1366,7 @@ mod test {
}

#[test]
#[cfg(debug_assertions)]
#[should_panic(expected = "Defensive failure has been triggered!: \"DefensiveMin strict\"")]
fn defensive_strict_min_panics() {
9_u32.defensive_strict_min(9_u32);
Expand All @@ -1377,6 +1379,7 @@ mod test {
}

#[test]
#[cfg(debug_assertions)]
#[should_panic(expected = "Defensive failure has been triggered!: \"DefensiveMax\"")]
fn defensive_max_panics() {
9_u32.defensive_max(10_u32);
Expand All @@ -1389,6 +1392,7 @@ mod test {
}

#[test]
#[cfg(debug_assertions)]
#[should_panic(expected = "Defensive failure has been triggered!: \"DefensiveMax strict\"")]
fn defensive_strict_max_panics() {
9_u32.defensive_strict_max(9_u32);
Expand Down

0 comments on commit 0798d52

Please sign in to comment.