Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the test assertion failure message when the wrong enum variant is used in matches_pattern!. #245

Merged
merged 1 commit into from
Jun 30, 2023

Conversation

hovinen
Copy link
Collaborator

@hovinen hovinen commented Jun 30, 2023

Previously, the match explanation when the wrong enum variant was used would just state that there was no such field:

Value of: actual
Expected: is AnEnum :: B which has field `0`, which is equal to 123
Actual: A(123),
  which has no field `0`

This is confusing, since the actual value does have such a field. It's just of the wrong enum variant.

This fixes the error message to indicate that the wrong variant was supplied:

Value of: actual
Expected: is AnEnum :: B which has field `0`, which is equal to 123
Actual: A(123),
  which has the wrong enum variant `A`

To output the supplied enum variant, it is necessary to construct the debug output and strip it of any fields it may have. This is inefficient, but unfortunately there is no obvious way to directly debug-output just the enum variant with no fields.

…t is used in `matches_pattern!`.

Previously, the match explanation when the wrong enum variant was used would just state that there was no such field:

```
Value of: actual
Expected: is AnEnum :: B which has field `0`, which is equal to 123
Actual: A(123),
  which has no field `0`
```

This is confusing, since the actual value _does_ have such a field. It's just of the wrong enum variant.

This fixes the error message to indicate that the wrong variant was supplied:

```
Value of: actual
Expected: is AnEnum :: B which has field `0`, which is equal to 123
Actual: A(123),
  which has the wrong enum variant `A`
```

To output the supplied enum variant, it is necessary to construct the debug output and strip it of any fields it may have. This is inefficient, but unfortunately there is no obvious way to directly debug-output just the enum variant with no fields.
@copybara-service copybara-service bot merged commit e8eebff into main Jun 30, 2023
@gribozavr gribozavr deleted the show-wrong-enum-variant-in-matches-pattern branch February 17, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant