Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking? #30

Open
cylewitruk opened this issue Apr 24, 2024 · 1 comment
Open

Mocking? #30

cylewitruk opened this issue Apr 24, 2024 · 1 comment

Comments

@cylewitruk
Copy link

cylewitruk commented Apr 24, 2024

I'd be curious to hear thoughts from you guys on adding a mocking framework like 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):

#[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:

#[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 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?

@crabdancing
Copy link

That sounds like a great idea! :D

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

No branches or pull requests

2 participants