Skip to content

Feature Request: Add Optional labels to Mocks #43

Open

Description

@nathaniel-brough

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.

Activity

  1. ryankurte commented on May 13, 2022

    @ryankurte
    Contributor

    interesting, seems like a reasonable addition to me! aside, have you tried RUST_BACKTRACE=1? i have found this (+ color-backtrace) to be very helpful for determining the call site.

  2. dbrgn commented on May 13, 2022

    @dbrgn
    Collaborator

    @silvergasp looks useful, feel free to send a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions