Skip to content

[codex] add optional mock labels - #142

Open
Old-Ding wants to merge 2 commits into
rust-embedded:mainfrom
Old-Ding:codex/add-mock-labels
Open

[codex] add optional mock labels#142
Old-Ding wants to merge 2 commits into
rust-embedded:mainfrom
Old-Ding:codex/add-mock-labels

Conversation

@Old-Ding

@Old-Ding Old-Ding commented Jun 29, 2026

Copy link
Copy Markdown

Summary

Closes #43.

This adds optional labels to the generic mock state so missing-expectation failures can identify which mock instance failed when a test uses several mocks at once. Unlabeled mocks retain their existing panic messages.

Changes

  • Added Generic::with_label(expected, label) while keeping Generic::new(expected) unchanged.
  • Added a shared next_expectation(message) helper that appends the label to the existing missing-expectation message when present.
  • Routed every Generic-backed expectation path in ADC, I2C, digital, delay, PWM, and SPI mocks through the shared helper.
  • Added regression tests for labeled and unlabeled messages, public type-alias usage, ADC, and both embedded-hal I2C generations.

Validation

Local checks passed:

  • cargo test --all-features (145 unit tests and 21 doc tests)
  • cargo +1.75.0 test --all-features (145 unit tests and 21 doc tests)
  • cargo fmt --all -- --check
  • git diff --check

@Old-Ding
Old-Ding marked this pull request as ready for review June 29, 2026 16:56

@newAM newAM left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

new_with_label should be with_label to match naming idioms (such as Vec::new / Vec::with_capacity) but it otherwise looks good to me.

Allow tests with multiple mocks to identify the failing instance in expectation errors.

Signed-off-by: Old-Ding <35417409+Old-Ding@users.noreply.github.com>
@Old-Ding
Old-Ding force-pushed the codex/add-mock-labels branch from 4c3a887 to 1353f86 Compare July 12, 2026 17:29
Preserve existing unlabeled panic messages while appending labels at the shared expectation-consumption layer. Route ADC and both I2C implementations through it and add regression coverage.

Signed-off-by: Old-Ding <35417409+Old-Ding@users.noreply.github.com>
@Old-Ding

Copy link
Copy Markdown
Author

Addressed on the current head (303db16): the public constructor is now Generic::with_label, and no new_with_label references remain. This follows the naming convention you noted.

Verification on the current head:

  • cargo test --all-features: 145 unit tests and 21 doc tests passed.
  • git diff --check upstream/main...HEAD: clean.

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.

Feature Request: Add Optional labels to Mocks

2 participants