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

Defensive traits: Ensure doc tests are also working without debug_assertions #12952

Merged
merged 2 commits into from
Dec 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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