rust-embedded / rust-embedded/embedded-hal-mock

Feature Request: Add Optional labels to Mocks

Open
#43 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
146
Forks
29
PR merge metrics
No merged PRs in 30d

Description

First of all, thanks for your work here. This project has been a real time-saver.

When you have a large set of mocks, it can become quite difficult to debug a test failure.

Say for example that you have a test that mocks 4 GPIO pins, with a specific sequence of reads and writes. As it currently stands you might get a message like this;

---- context::tests::send_command stdout ----
thread 'context::tests::send_command' panicked at 'no expectation for pin::is_high call', /usr/local/cargo/git/checkouts/embedded-hal-mock-54d083840a293f52/d394c81/src/pin.rs:159:50
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Apart from the offending function call, this error message doesn't yield much useful information to track down where the failure has occurred. To improve these error messages I'd like to add a label so that;
'no expectation for pin::is_high call' becomes 'no expectation for pin::is_high call on pin my_label'

From the user facing API this might look something like;

// Not labelled
let mut pin = PinMock::new(&expectations);

// Labelled
let mut pin = PinMock::new_with_label(&expectations, "my_label");

I'm happy to have a crack at implementing this, but I thought I get some input before going ahead with it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the PinMock API and the code that produces the “no expectation for pin::is_high call” error. Add an optional label while preserving the existing constructor, and verify that labelled and unlabelled mocks produce the intended diagnostic messages.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.