embassy-rs / embassy-rs/chiptool
Mocking?
- Dominant language
- Rust
- Stars
- 65
- Forks
- 54
- PR merge metrics
- No merged PRs in 30d
Description
I'd be curious to hear thoughts from you guys on adding a mocking framework like [mockall](https://crates.io/crates/mockall) for PAC-generation?
Basically, I'd like to be able to `rp-pac { version = "0.1.0", features = ["mocking"] }` as a dev-dep, and have something like this in the generation (for example):
```rust
#[cfg(all(test, feature = "mocking"))]
use mockall:automock;
...
// in fieldset.rs
...
#[cfg_attr(all(test, feature = "mockall", automock))]
pub struct #name (pub #ty);
#[cfg_attr(all(test, feature = "mockall", automock))]
impl #name {
#items
}
...
```
Then, in my code I could use:
```rust
#[double]
use pac::PWM as PWM;
```
Which would automatically expand `PWM` to `MockPWM` when I'm in `test` -- this would let me mock registers etc. so that I can more easily test that the registers end up with the correct values (logic-wise, at least) in drivers without needing to involve a board.
Concrete example is working on [this PR](https://github.com/embassy-rs/embassy/pull/2855) where via mocks I could manually step through the PWM counter and verify that the correct div/top/compares/etc. are set for each step in a test.
Thoughts?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.