Skip to content

matches_pattern! silently accepts tuple enums #626

@mgeisler

Description

@mgeisler

Hello!

I just realized that some of my tests pass, even when they shouldn't. The use matches_pattern! and look like this:

    #[gtest]
    fn test_with_wildcard() {
        let result: Option<i8> = None;
        expect_that!(result, matches_pattern!(Some(_)));
    }


    #[gtest]
    fn test_with_value() {
        let result: Option<i8> = None;
        expect_that!(result, matches_pattern!(Some(123)));
    }

The test_with_wildcard compiles and passes:

% cargo test   
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.08s
     Running unittests src/lib.rs (target/debug/deps/matches_pattern-27f44d6b49ac5855)

running 2 tests
test tests::test_with_wildcard ... ok
test tests::test_with_value ... FAILED

Both test should fail: I'm matching a None against a Some(_).

Reading the documentation closely, I see it says

This macro does not support plain (non-struct) tuples.

I don't know if that is what I'm seeing here?

My actual code is more complex: I'm matching a result against a larger Error enum:

        expect_that!(
            result,
            err(matches_pattern!(Error::InvalidInput(_)))
        );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions