Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 6 additions & 11 deletions src/derived_spec/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,6 @@ fn extracting_ref_vec_contains_all_in_order() {

mod iterator_all_elements {
use super::*;
#[cfg(feature = "std")]
use crate::assert_panic_message;

#[derive(Debug, Clone)]
struct Person {
Expand Down Expand Up @@ -992,19 +990,16 @@ mod iterator_all_elements {
});
}

#[cfg(feature = "std")]
#[test]
#[should_panic = "expected numbers.val[1] to be not equal to 4\n but was: 4\n expected: not 4\n"]
fn assert_each_element_of_an_iterator_panics_if_one_assertion_fails() {
let subject = Numbers(vec![2, 4, 6, 8, 10]);

assert_panic_message!(
assert_that(subject)
.named("numbers")
.extracting_ref("val", |numbers| &numbers.0)
.is_not_empty()
.each_element(|e| e.is_not_equal_to(4)),
"expected numbers.val[1] to be not equal to 4\n but was: 4\n expected: not 4\n"
);
assert_that(subject)
.named("numbers")
.extracting_ref("val", |numbers| &numbers.0)
.is_not_empty()
.each_element(|e| e.is_not_equal_to(4));
}

#[test]
Expand Down
15 changes: 5 additions & 10 deletions src/iterator/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg(feature = "std")]
use crate::assert_panic_message;
use crate::prelude::*;
use crate::std::{string::String, vec, vec::Vec};

Expand Down Expand Up @@ -296,18 +294,15 @@ mod all_elements {
.each_element(|person| person.extracting("name", |p| &p.name).starts_with('J'));
}

#[cfg(feature = "std")]
#[test]
#[should_panic = "expected numbers [1] to be not equal to 4\n but was: 4\n expected: not 4\n"]
fn assert_each_element_of_an_iterator_panics_if_one_assertion_fails() {
let subject = [2, 4, 6, 8, 10];

assert_panic_message!(
assert_that(subject)
.named("numbers")
.is_not_empty()
.each_element(|e| e.is_not_equal_to(4)),
"expected numbers [1] to be not equal to 4\n but was: 4\n expected: not 4\n"
);
assert_that(subject)
.named("numbers")
.is_not_empty()
.each_element(|e| e.is_not_equal_to(4));
}

#[test]
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,6 @@ pub mod assertions;
pub mod colored;
pub mod derived_spec;
pub mod expectations;
pub mod panic;
pub mod prelude;
pub mod properties;
#[cfg(feature = "recursive")]
Expand Down
6 changes: 3 additions & 3 deletions src/option/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::spec::{
DiffFormat, DisplayRepresentation, Expectation, Expecting, Expression, FailingStrategy,
Invertible, Represent, Represented, RepresentedBy, Spec,
};
use crate::std::{format, string::String};
use crate::std::{format, panic, string::String};

impl<T, D, R> AssertOption for Spec<'_, Option<T>, D, R>
where
Expand Down Expand Up @@ -48,7 +48,7 @@ where
let value_representation = self.representation().clone();
self.mapping(|subject| match subject {
None => {
crate::panic::trigger_panic("expected the subject to be `Some(_)`, but was `None`")
panic!("expected the subject to be `Some(_)`, but was `None`")
},
Some(value) => value,
})
Expand All @@ -67,7 +67,7 @@ where
let value_representation = self.representation().clone();
self.mapping(|subject| match subject {
None => {
crate::panic::trigger_panic("expected the subject to be `Some(_)`, but was `None`")
panic!("expected the subject to be `Some(_)`, but was `None`")
},
Some(value) => value,
})
Expand Down
178 changes: 0 additions & 178 deletions src/panic/mod.rs

This file was deleted.

6 changes: 2 additions & 4 deletions src/panic_assertion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use crate::assertions::AssertCodePanics;
use crate::colored::{mark_missing, mark_unexpected};
use crate::expectations::{DoesNotPanic, DoesPanic, does_not_panic, does_panic};
use crate::panic::AssertionPanicPayload;
use crate::spec::{
Code, DebugRepresentation, DiffFormat, DisplayRepresentation, Expectation, Expecting,
Expression, FailingStrategy, Spec,
Expand Down Expand Up @@ -147,9 +146,8 @@ fn read_panic_message(error: Option<&Box<dyn Any + Send>>) -> Option<String> {
error.and_then(|message| {
let message = &**message;
message
.downcast_ref::<AssertionPanicPayload>()
.map(|payload| payload.message.clone())
.or_else(|| message.downcast_ref::<String>().cloned())
.downcast_ref::<String>()
.cloned()
.or_else(|| message.downcast_ref::<&str>().map(ToString::to_string))
})
}
Expand Down
26 changes: 9 additions & 17 deletions src/result/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::spec::{
};
use crate::std::fmt::{Debug, Display};
use crate::std::{
format,
format, panic,
string::{String, ToString},
};

Expand Down Expand Up @@ -58,9 +58,7 @@ where
Ok(value) => value,
Err(error) => {
let error = Represented::from((&error, &representation));
crate::panic::trigger_panic(format!(
"expected the subject to be `Ok(_)`, but was `Err({error:?})`"
))
panic!("expected the subject to be `Ok(_)`, but was `Err({error:?})`")
},
})
.represented_by(representation)
Expand All @@ -71,9 +69,7 @@ where
self.mapping(|subject| match subject {
Ok(value) => {
let value = Represented::from((&value, &representation));
crate::panic::trigger_panic(format!(
"expected the subject to be `Err(_)`, but was `Ok({value:?})`"
))
panic!("expected the subject to be `Err(_)`, but was `Ok({value:?})`")
},
Err(error) => error,
})
Expand All @@ -94,9 +90,7 @@ where
Ok(value) => value,
Err(error) => {
let error = Represented::from((error, &representation));
crate::panic::trigger_panic(format!(
"expected the subject to be `Ok(_)`, but was `Err({error:?})`"
))
panic!("expected the subject to be `Ok(_)`, but was `Err({error:?})`")
},
})
.represented_by(representation)
Expand All @@ -107,9 +101,7 @@ where
self.mapping(|subject| match subject {
Ok(value) => {
let value = Represented::from((value, &representation));
crate::panic::trigger_panic(format!(
"expected the subject to be `Err(_)`, but was `Ok({value:?})`"
))
panic!("expected the subject to be `Err(_)`, but was `Ok({value:?})`")
},
Err(error) => error,
})
Expand Down Expand Up @@ -180,9 +172,9 @@ where
Err(error) => Err(error.to_string()),
};
self.mapping(|_result| match subject {
Ok(value) => crate::panic::trigger_panic(format!(
Ok(value) => panic!(
r"expected the subject to be `Err(_)` with message {expected:?}, but was `{value}`"
)),
),
Err(error) => error,
})
.expecting(is_equal_to(expected))
Expand All @@ -208,9 +200,9 @@ where
Err(error) => Err(error.to_string()),
};
self.mapping(|_result| match subject {
Ok(value) => crate::panic::trigger_panic(format!(
Ok(value) => panic!(
r"expected the subject to be `Err(_)` with message {expected:?}, but was `{value}`"
)),
),
Err(error) => error,
})
.expecting(is_equal_to(expected))
Expand Down
4 changes: 2 additions & 2 deletions src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::std::{
fmt::{self, Debug, Display},
format,
ops::Deref,
slice,
panic, slice,
string::{String, ToString},
vec,
vec::Vec,
Expand Down Expand Up @@ -1657,7 +1657,7 @@ impl FailingStrategy for PanicOnFail {
.map(ToString::to_string)
.collect::<Vec<_>>()
.join("\n");
crate::panic::trigger_panic(message);
panic!("{message}");
}
}

Expand Down
Loading
Loading