[MrBot] Add guidance: prefer enum type in ASSERT_ARE_EQUAL#335
Closed
darobs wants to merge 1 commit into
Closed
Conversation
Adds a note to .github/copilot-instructions.md instructing contributors to pass the actual enum type to CTEST_ASSERT_ARE_EQUAL rather than casting to int, so failure messages print symbolic enum names instead of raw integers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the repository’s Copilot contributor guidance to recommend asserting enum values using the enum type (rather than casting to int) so assertion failures can print symbolic enum names, improving CI log diagnostics.
Changes:
- Added a new documentation subsection recommending enum-typed equality assertions for enums.
- Added “BAD vs GOOD” examples illustrating enum assertions and enum type setup for tests.
Comment on lines
+92
to
+93
| When asserting a value whose declared type is an enum, always pass the enum type as the first argument to | ||
| `ASSERT_ARE_EQUAL`. Do not cast to `int` just to make the assert compile: |
Comment on lines
+96
to
+100
| // BAD - loses type information, no symbolic name on failure | ||
| ASSERT_ARE_EQUAL(int, (int)MY_RESULT_OK, (int)result); | ||
|
|
||
| // GOOD - prints the enum value names on failure | ||
| ASSERT_ARE_EQUAL(MY_RESULT, MY_RESULT_OK, result); |
| ASSERT_ARE_EQUAL(MY_RESULT, MY_RESULT_OK, result); | ||
| ``` | ||
|
|
||
| Use `TEST_DEFINE_ENUM_TYPE` to define the enum for the test. |
|
|
||
| Use `TEST_DEFINE_ENUM_TYPE` to define the enum for the test. | ||
| ```c | ||
| TEST_DEFINE_ENUM_TYPE(MY_RESULT, MY_RESULT_VALUES); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a note to
.github/copilot-instructions.mdinstructing contributors to pass the actual enum type toASSERT_ARE_EQUALrather than casting to int, so failure messages print symbolic enum names instead of raw integers.