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

IO implementation for embedded-io #101

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Artur-Romaniuk
Copy link
Contributor

Related to #100

Copy link
Collaborator

@newAM newAM left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for adding the feature, just some structural changes I would make.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This should go under src/io.rs since embedded-io is versioned independently of embedded-hal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dbrgn If you could give your opinion on this?

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, I think the suggestion makes sense.

Cargo.toml Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
Copy link
Contributor Author

@Artur-Romaniuk Artur-Romaniuk left a comment

Choose a reason for hiding this comment

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

Will apply suggested changes.

Cargo.toml Outdated Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
src/eh1/io.rs Show resolved Hide resolved
src/eh1/io.rs Outdated Show resolved Hide resolved
src/eh1/io.rs Outdated Show resolved Hide resolved
src/eh1/io.rs Outdated Show resolved Hide resolved
src/eh1/io.rs Outdated Show resolved Hide resolved
src/eh1/io.rs Show resolved Hide resolved
Artur-Romaniuk added a commit to Artur-Romaniuk/embedded-hal-mock that referenced this pull request Dec 26, 2023
@Artur-Romaniuk Artur-Romaniuk requested a review from newAM January 10, 2024 08:46
Artur-Romaniuk added a commit to Artur-Romaniuk/embedded-hal-mock that referenced this pull request Jan 14, 2024
@Artur-Romaniuk
Copy link
Contributor Author

Rebased on main. Would love to have some feedback.

Copy link
Collaborator

@newAM newAM left a comment

Choose a reason for hiding this comment

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

I had some nitpicks with the documentation links but I just did the changes and pushed them since that's easier.

Looks good to me overall. We're going to have unfortunate conflicts with the other PR that touches delays, but that's unavoidable. Will wait for dbrgn's feedback on this too.

src/common.rs Show resolved Hide resolved
@Artur-Romaniuk
Copy link
Contributor Author

This PR went stale for a while now. @dbrgn could take a look?

@dbrgn
Copy link
Owner

dbrgn commented Feb 3, 2024

@Artur-Romaniuk because this PR was created on top of the delay branch (#104), I wanted to wait until that branch is ready and merged (and left feedback there) to make review easier.

If you want to make PRs easier to review, try to keep them small and focussed. Having a lot of practice with git rebase (especially interactive rebase) helps a lot with that.

Artur-Romaniuk added a commit to Artur-Romaniuk/embedded-hal-mock that referenced this pull request Feb 4, 2024
@Artur-Romaniuk
Copy link
Contributor Author

@Artur-Romaniuk because this PR was created on top of the delay branch (#104), I wanted to wait until that branch is ready and merged (and left feedback there) to make review easier.

If you want to make PRs easier to review, try to keep them small and focussed. Having a lot of practice with git rebase (especially interactive rebase) helps a lot with that.

That was a fuckup...
Must have rebased this branch on wrong origin/main. Force pushed rebased version with all unecessary commits dropped.

Copy link
Owner

@dbrgn dbrgn left a comment

Choose a reason for hiding this comment

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

I left a few last comments. The rest is looking great, I think once the comments are addressed this can be merged.

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, I think the suggestion makes sense.

src/eh1/io.rs Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
Comment on lines +24 to +25
/// Optional Data type allows for storage of arbitrary state data in mocks.
/// Mock data can be accessed via appropriate getter/setter methods, i.e. `mock_data()` and `set_mock_data()`.
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
/// Optional Data type allows for storage of arbitrary state data in mocks.
/// Mock data can be accessed via appropriate getter/setter methods, i.e. `mock_data()` and `set_mock_data()`.
/// The `mock_data` field allows for storage of arbitrary state data in mocks.
/// Mock data can be accessed via appropriate getter/setter methods, i.e. `mock_data()` and `set_mock_data()`.

#[derive(Debug, Clone)]
pub struct Generic<T: Clone + Debug + PartialEq> {
pub struct Generic<T: Clone + Debug + PartialEq, Data = ()> {
Copy link
Owner

@dbrgn dbrgn May 16, 2024

Choose a reason for hiding this comment

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

I like the T-prefix convention for type parameters. Can you rename Data to TData?

//! // Finalizing expectations
//! io.done();
//!
//! // optional async
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
//! // optional async
//! // Async is supported as well, if the `embedded-hal-async` feature is enabled

Comment on lines +95 to +98
pub fn write(expected: Vec<u8>) -> Transaction {
Transaction {
expected_mode: Mode::Write,
expected_data: expected,
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
pub fn write(expected: Vec<u8>) -> Transaction {
Transaction {
expected_mode: Mode::Write,
expected_data: expected,
pub fn write(expected_data: Vec<u8>) -> Transaction {
Transaction {
expected_mode: Mode::Write,
expected_data,

panic!("response longer than read buffer for io::read");
}

let len = std::cmp::min(buffer.len(), transaction.response.len());
Copy link
Owner

Choose a reason for hiding this comment

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

Since we already assert above, that the response length can't be larger than the buffer length, can't we just use the response length here?

Suggested change
let len = std::cmp::min(buffer.len(), transaction.response.len());
let len = transaction.response.len();

let transaction = self.next().expect("no expectation for io::seek call");

if let Mode::Seek(expected_pos) = transaction.expected_mode {
assert_eq!(expected_pos, pos, "io::seek unexpected mode");
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
assert_eq!(expected_pos, pos, "io::seek unexpected mode");
assert_eq!(expected_pos, pos, "io::seek unexpected pos");

Comment on lines +316 to +317
let response_vec = transaction.response;
self.set_mock_data(Some(response_vec));
Copy link
Owner

@dbrgn dbrgn May 16, 2024

Choose a reason for hiding this comment

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

Since this variable is only used once, I think it can be inlined.

Suggested change
let response_vec = transaction.response;
self.set_mock_data(Some(response_vec));
self.set_mock_data(Some(transaction.response));

@victorbnl
Copy link

Any chance this gets fixed and merged in a near future?

@dbrgn
Copy link
Owner

dbrgn commented Sep 13, 2024

@Artur-Romaniuk do you have plans to finish this PR, or would you like for someone else to take over?

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

Successfully merging this pull request may close these issues.

4 participants