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
2 changes: 1 addition & 1 deletion src/collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub(crate) struct CollectionDebug<'wrapper, C> {
pub(crate) collection: &'wrapper C,
}

impl<'wrapper, 'collection, C> Debug for CollectionDebug<'wrapper, C>
impl<'collection, C> Debug for CollectionDebug<'_, C>
where
C: Collection<'collection>,
C::Item: Debug
Expand Down
18 changes: 18 additions & 0 deletions src/collections/partial_eq/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,12 @@ mod tests {
but it "was <[ 2, 3, [5] ]>");
}

/// Test-case generator for assertions of the kind "contains_all_of", potentially with different
/// implementations (such as HashSet/BTreeSet/...).
///
/// # Arguments
///
/// * $assertion: The identifier of the assertion method.
#[macro_export]
macro_rules! test_contains_all_of {
($assertion:ident) => {
Expand Down Expand Up @@ -626,6 +632,12 @@ mod tests {

test_contains_all_of!(contains_all_of);

/// Test-case generator for assertions of the kind "contains_none_of", potentially with
/// different implementations (such as HashSet/BTreeSet/...).
///
/// # Arguments
///
/// * $assertion: The identifier of the assertion method.
#[macro_export]
macro_rules! test_contains_none_of {
($assertion:ident) => {
Expand Down Expand Up @@ -663,6 +675,12 @@ mod tests {

test_contains_none_of!(contains_none_of);

/// Test-case generator for assertions of the kind "contains_exactly_in_any_order", potentially
/// with different implementations (such as HashSet/BTreeSet/...).
///
/// # Arguments
///
/// * $assertion: The identifier of the assertion method.
#[macro_export]
macro_rules! test_contains_exactly_in_any_order {
($assertion:ident) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl_lock_ref!(Box<L>);
impl_lock_ref!(Rc<L>);
impl_lock_ref!(Arc<L>);

impl<'cow, L: Clone + Lock> Lock for Cow<'cow, L> {
impl<L: Clone + Lock> Lock for Cow<'_, L> {
fn is_poisoned(&self) -> bool {
L::is_poisoned(self.borrow())
}
Expand Down
8 changes: 4 additions & 4 deletions src/maps/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct MapEntryDebug<'reference, 'map, M: Map<'map>> {
entry: (&'reference M::Key, &'reference M::Value)
}

impl<'reference, 'map, M> Debug for MapEntryDebug<'reference, 'map, M>
impl<'map, M> Debug for MapEntryDebug<'_, 'map, M>
where
M: Map<'map>,
M::Key: Debug,
Expand Down Expand Up @@ -38,7 +38,7 @@ impl<'reference, 'map, M: Map<'map>> MapEntriesDebug<'reference, 'map, M> {
}
}

impl<'reference, 'map, M> Debug for MapEntriesDebug<'reference, 'map, M>
impl<'map, M> Debug for MapEntriesDebug<'_, 'map, M>
where
M: Map<'map>,
M::Key: Debug,
Expand All @@ -53,7 +53,7 @@ pub(crate) struct MapDebug<'wrapper, M> {
pub(crate) map: &'wrapper M
}

impl<'wrapper, 'map, M> Debug for MapDebug<'wrapper, M>
impl<'map, M> Debug for MapDebug<'_, M>
where
M: Map<'map>,
M::Key: Debug,
Expand All @@ -73,7 +73,7 @@ where
pub(crate) highlighted_key: &'key M::Key
}

impl<'wrapper, 'key, 'map, M> Debug for HighlightedMapDebug<'wrapper, 'key, 'map, M>
impl<'key, 'map, M> Debug for HighlightedMapDebug<'_, 'key, 'map, M>
where
M: Map<'map>,
'map: 'key,
Expand Down
13 changes: 12 additions & 1 deletion src/maps/partial_eq/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,12 @@ mod tests {
but it "was <[ \"apple\" => 41, [\"banana\" => 42], \"cherry\" => 43 ]>");
}

/// Test-case generator for assertions of the kind "contains_values", potentially with different
/// implementations (such as HashSet/BTreeSet/...).
///
/// # Arguments
///
/// * $assertion: The identifier of the assertion method.
#[macro_export]
macro_rules! test_contains_values {
($assertion:ident) => {
Expand Down Expand Up @@ -640,7 +646,12 @@ mod tests {
but it "was <[ \"apple\" => 1, [\"banana\" => 2] ]>");
}


/// Test-case generator for assertions of the kind "contains_exactly_values", potentially with
/// different implementations (such as HashSet/BTreeSet/...).
///
/// # Arguments
///
/// * $assertion: The identifier of the assertion method.
#[macro_export]
macro_rules! test_contains_exactly_values {
($assertion:ident) => {
Expand Down
34 changes: 32 additions & 2 deletions src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,42 @@ pub(crate) fn assert_fails_do<F: FnOnce() -> () + UnwindSafe>(
assert_that!(assertion).panics_with_message(expected_message);
}

/// Utility-macro to compactly write tests for failing assertions. As an example, consider the
/// following assertion.
///
/// ```norun
/// assert_that!(1).is_equal_to(2);
/// ```
///
/// To test that this assertion fails with the correct message, we would use this macro as follows.
///
/// ```norun
/// assert_fails!((1).is_equal_to(2),
/// expected it "to equal <2>"
/// but it "was <1>");
/// ```
///
/// # Arguments
///
/// * $input: The expression tested by the assertion which is expected to fail. Put inside
/// parentheses to ensure it is isolated from the rest (`.` would otherwise be interpreted as part
/// of the expression). In the example, this would be `1`.
/// * $assertion: The identifier of the assertion-method to test. In the example, this would be
/// `is_equal_to`.
/// * args: A parameter list to supply to the assertion expected to fail. In the example, this would
/// be `2`
/// * $expected_it: A string literal containing the expected part of the error message that comes
/// after `expected: <...> `. The first part of this line is asserted to be as the `Failure`
/// struct defines, with appropriate expression text. In the example, this would be
/// `"to equal <2>"`.
/// * $but_it: A string literal containing the expected part of the error message that comes
/// after `but: it <...> `. In the example, this would be `"was <1>"`.
#[macro_export]
macro_rules! assert_fails {
(( $input:expr ) . $assertion:ident ( $( $expected:expr ),* ),
(( $input:expr ) . $assertion:ident ( $( $args:expr ),* ),
expected it $expected_it:tt but it $but_it:tt) => {
$crate::test_util::assert_fails_do(
|| { $crate::assert_that!($input).$assertion($( $expected, )*); },
|| { $crate::assert_that!($input).$assertion($( $args, )*); },
stringify!($input),
$expected_it,
$but_it);
Expand Down
6 changes: 6 additions & 0 deletions src/util/multiset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ fn multiset_map_remove<T, M: MultisetMap<T>>(multiset_map: &mut M, item: &T) ->
#[cfg(test)]
mod tests {

/// Test-case generator for different Multiset-implementations, with different underlying data
/// structures (such as HashMap/BTreeMap/...).
///
/// # Arguments
///
/// * $multiset_type: The identifier of the tested type implementing Multiset.
#[macro_export]
macro_rules! test_multiset_impl {
($multiset_type:ident) => {
Expand Down