Skip to content

[MrBot] Add guidance: prefer enum type in ASSERT_ARE_EQUAL#335

Closed
darobs wants to merge 1 commit into
masterfrom
darobs/assert-enum-type-instruction
Closed

[MrBot] Add guidance: prefer enum type in ASSERT_ARE_EQUAL#335
darobs wants to merge 1 commit into
masterfrom
darobs/assert-enum-type-instruction

Conversation

@darobs
Copy link
Copy Markdown
Contributor

@darobs darobs commented Jun 3, 2026

Adds a note to .github/copilot-instructions.md instructing contributors to pass the actual enum type to ASSERT_ARE_EQUAL rather than casting to int, so failure messages print symbolic enum names instead of raw integers.

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>
@darobs darobs requested review from Copilot and removed request for anporumb June 3, 2026 16:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
@darobs darobs closed this Jun 3, 2026
@darobs darobs deleted the darobs/assert-enum-type-instruction branch June 3, 2026 16:38
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.

2 participants