Skip to content

Commit 2ec3594

Browse files
Merge branch 'dbrgn:main' into io-mock
2 parents 2705618 + e01d736 commit 2ec3594

17 files changed

Lines changed: 120 additions & 138 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
runs-on: ubuntu-latest
5353
steps:
5454
- uses: actions/checkout@v4
55-
- uses: dtolnay/rust-toolchain@stable
55+
- uses: dtolnay/rust-toolchain@nightly
5656
with:
5757
components: rustfmt
58-
- run: cargo fmt --all -- --check
58+
- run: cargo +nightly fmt --all -- --check

.rustfmt.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,56 +14,37 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1414

1515
### Changed
1616

17-
- Updated `embedded-hal` to `1.0.0`.
18-
- Changed the `embedded-hal` version 1 SPI implementation to be generic over
19-
word size.
2017

21-
## 0.10.0-rc.4 - 2023-12-14
22-
23-
### Changed
24-
25-
- Updated `embedded-hal` to `1.0.0-rc.3`.
26-
27-
28-
## 0.10.0-rc.3 - 2023-11-29
29-
30-
### Changed
31-
32-
- Updated `embedded-hal` to `1.0.0-rc.2`.
33-
34-
35-
## 0.10.0-rc.2 - 2023-11-23
36-
37-
### Added
38-
39-
- Implement mock for `eh1::pwm::SetDutyCycle`
40-
41-
### Changed
42-
43-
- Renamed `.expect(...)` method to `.update_expectations(...)` to avoid
44-
confusion with the expect method in `Option` and `Result` (#63)
45-
- When updating expectations on a mock by calling `.expect(...)` /
46-
`.update_expectations(...)` on it, assert that previous expectations have
47-
been consumed (#63)
48-
49-
50-
## 0.10.0-rc.1 - 2023-11-01
18+
## 0.10.0 - 2024-01-10
5119

5220
This release contains a big change: `embedded-hal-mock` now supports both
53-
`embedded-hal` 0.x and 1.x (currently at version `1.0.0-rc.1`)! Please test it,
54-
and if there are any issues, leave feedback in the GitHub issue tracker.
21+
`embedded-hal` 0.x and 1.x! The two variants are accessible through
22+
`embedded_hal_mock::eh0::*` and `embedded_hal_mock::eh1::*`. If there are any
23+
issues, leave feedback in the GitHub issue tracker.
5524

5625
Additionally, tests now fail if you forgot to call `.done()`. This should
5726
reduce the chance of accidentally writing a broken test.
5827

59-
This release contains commits by 10 different people, thanks a lot for the
28+
This release contains commits by 12 different people, thanks a lot for the
6029
contributions!
6130

31+
### Migrating to 0.10.0
32+
33+
- Update your imports: Change `use embedded_hal_mock::*` to
34+
`use embedded_hal_mock::eh0::*`
35+
- Rename all `.expect(...)` calls on mocks to `.update_expectations(...)`
36+
- Rename all `eh0::delay::MockNoop` usages to `eh0::delay::NoopDelay`
37+
- Run your tests to ensure that you don't have any missing `.done()` calls in
38+
your code
39+
- Look through the rest of the changes below and check if they might affect
40+
your code
41+
6242
### Added
6343

6444
- Support for both `embedded-hal` 0.x and 1.x in the same crate (#75)
6545
- Print a warning to stderr and fail test if a mock is dropped without having
6646
calling `.done()` on it, or if `.done()` is called twice (#59, #61)
47+
- Implement mock for `eh1::pwm::SetDutyCycle`
6748

6849
### Fixed
6950

@@ -74,8 +55,16 @@ contributions!
7455

7556
### Changed
7657

58+
- Renamed `.expect(...)` method to `.update_expectations(...)` to avoid
59+
confusion with the expect method in `Option` and `Result` (#63)
60+
- When updating expectations on a mock by calling `.expect(...)` /
61+
`.update_expectations(...)` on it, assert that previous expectations have
62+
been consumed (#63)
7763
- Rename `delay::MockNoop` to `delay::NoopDelay`.
78-
- Bump minimal supported Rust version (MSRV) to 1.63
64+
- Changed the eh1 SPI implementation to be generic over word size
65+
- Updated `nb` dependency from 0.1 to 1.1 (#107)
66+
- Bump minimal supported Rust version (MSRV) to 1.63 (or 1.75 if you use
67+
embedded-hal 1.0)
7968
- The minimal supported Rust version (MSRV) is specified in the `Cargo.toml` to
8069
offer clearer error messages to consumers with outdated Rust versions
8170

LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (C) 2018-2023 Danilo Bargen and contributors
1+
Copyright (C) 2018-2024 Danilo Bargen and contributors
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of
44
this software and associated documentation files (the "Software"), to deal in

rustfmt.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
# Empty file, use defaults and disregard global settings
1+
imports_granularity = "Crate"
2+
group_imports = "StdExternalCrate"

src/eh0/adc.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
//! ```
66
//! # use eh0 as embedded_hal;
77
//! use embedded_hal::adc::OneShot;
8-
//! use embedded_hal_mock::eh0::adc::Mock;
9-
//! use embedded_hal_mock::eh0::adc::Transaction;
10-
//! use embedded_hal_mock::eh0::adc::{MockChan0, MockChan1};
8+
//! use embedded_hal_mock::eh0::adc::{Mock, MockChan0, MockChan1, Transaction};
119
//!
1210
//! // Configure expectations: expected input channel numbers and values returned by read operations
1311
//! let expectations = [
@@ -30,13 +28,13 @@
3028
//!
3129
//! ```
3230
//! # use eh0 as embedded_hal;
33-
//! use embedded_hal::adc::OneShot;
34-
//! use embedded_hal_mock::eh0::adc::Mock;
35-
//! use embedded_hal_mock::eh0::adc::Transaction;
36-
//! use embedded_hal_mock::eh0::adc::MockChan1;
37-
//! use embedded_hal_mock::eh0::MockError;
3831
//! use std::io::ErrorKind;
3932
//!
33+
//! use embedded_hal::adc::OneShot;
34+
//! use embedded_hal_mock::eh0::{
35+
//! adc::{Mock, MockChan1, Transaction},
36+
//! MockError,
37+
//! };
4038
//!
4139
//! // Configure expectations
4240
//! let expectations = [
@@ -45,17 +43,18 @@
4543
//! let mut adc = Mock::new(&expectations);
4644
//!
4745
//! // Reading returns an error
48-
//! adc.read(&mut MockChan1 {}).expect_err("expected error return");
46+
//! adc.read(&mut MockChan1 {})
47+
//! .expect_err("expected error return");
4948
//!
5049
//! // Finalise expectations
5150
//! adc.done();
5251
//! ```
5352
53+
use std::fmt::Debug;
54+
5455
use eh0 as embedded_hal;
55-
use embedded_hal::adc::Channel;
56-
use embedded_hal::adc::OneShot;
56+
use embedded_hal::adc::{Channel, OneShot};
5757
use nb;
58-
use std::fmt::Debug;
5958

6059
use super::error::MockError;
6160
use crate::common::Generic;
@@ -141,13 +140,12 @@ where
141140

142141
#[cfg(test)]
143142
mod test {
144-
use super::super::error::MockError;
145-
use super::*;
143+
use std::io::ErrorKind;
146144

147145
use eh0 as embedded_hal;
148146
use embedded_hal::adc::OneShot;
149147

150-
use std::io::ErrorKind;
148+
use super::{super::error::MockError, *};
151149

152150
#[test]
153151
fn test_adc_single_read16() {

src/eh0/delay.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
//! [`std::thread::sleep`](https://doc.rust-lang.org/std/thread/fn.sleep.html)
1313
//! to implement the delay.
1414
15-
use std::thread;
16-
use std::time::Duration;
15+
use std::{thread, time::Duration};
1716

1817
use eh0 as embedded_hal;
1918
use embedded_hal::blocking::delay;

src/eh0/i2c.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
//!
55
//! ```
66
//! # use eh0 as embedded_hal;
7-
//! use embedded_hal::prelude::*;
8-
//! use embedded_hal::blocking::i2c::{Read, Write, WriteRead};
7+
//! use embedded_hal::{
8+
//! blocking::i2c::{Read, Write, WriteRead},
9+
//! prelude::*,
10+
//! };
911
//! use embedded_hal_mock::eh0::i2c::{Mock as I2cMock, Transaction as I2cTransaction};
1012
//!
1113
//! // Configure expectations
@@ -47,6 +49,7 @@
4749
//! # use embedded_hal::blocking::i2c::{Read, Write, WriteRead};
4850
//! # use embedded_hal_mock::eh0::i2c::{Mock as I2cMock, Transaction as I2cTransaction};
4951
//! use std::io::ErrorKind;
52+
//!
5053
//! use embedded_hal_mock::eh0::MockError;
5154
//!
5255
//! // Configure expectations
@@ -277,14 +280,13 @@ impl i2c::WriteIter for Mock {
277280

278281
#[cfg(test)]
279282
mod test {
280-
use super::super::error::MockError;
281-
use super::*;
282-
283283
use std::{io::ErrorKind as IoErrorKind, time::SystemTime};
284284

285285
use eh0 as embedded_hal;
286286
use embedded_hal::blocking::i2c::{Read, Write, WriteRead};
287287

288+
use super::{super::error::MockError, *};
289+
288290
#[test]
289291
fn write() {
290292
let expectations = [Transaction::write(0xaa, vec![10, 12])];

src/eh0/pin.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
//! # use eh0 as embedded_hal;
88
//! use std::io::ErrorKind;
99
//!
10-
//! use embedded_hal_mock::eh0::MockError;
11-
//! use embedded_hal_mock::eh0::pin::{Transaction as PinTransaction, Mock as PinMock, State as PinState};
1210
//! use embedded_hal::digital::v2::{InputPin, OutputPin};
11+
//! use embedded_hal_mock::eh0::{
12+
//! pin::{Mock as PinMock, State as PinState, Transaction as PinTransaction},
13+
//! MockError,
14+
//! };
1315
//!
1416
//! let err = MockError::Io(ErrorKind::NotConnected);
1517
//!
@@ -37,16 +39,17 @@
3739
//! pin.update_expectations(&[]);
3840
//! // ...
3941
//! pin.done();
40-
//!
4142
//! ```
4243
44+
use eh0 as embedded_hal;
45+
use embedded_hal::{
46+
digital::v2::{InputPin, OutputPin},
47+
PwmPin,
48+
};
49+
4350
use super::error::MockError;
4451
use crate::common::Generic;
4552

46-
use eh0 as embedded_hal;
47-
use embedded_hal::digital::v2::{InputPin, OutputPin};
48-
use embedded_hal::PwmPin;
49-
5053
/// The type used for the duty of the [`PwmPin`] mock.
5154
pub type PwmDuty = u16;
5255

@@ -300,15 +303,15 @@ impl PwmPin for Mock {
300303

301304
#[cfg(test)]
302305
mod test {
303-
use super::super::error::MockError;
304-
use super::TransactionKind::*;
305-
use super::*;
306-
307306
use std::io::ErrorKind;
308307

309308
use eh0 as embedded_hal;
310-
use embedded_hal::digital::v2::{InputPin, OutputPin};
311-
use embedded_hal::PwmPin;
309+
use embedded_hal::{
310+
digital::v2::{InputPin, OutputPin},
311+
PwmPin,
312+
};
313+
314+
use super::{super::error::MockError, TransactionKind::*, *};
312315

313316
#[test]
314317
fn test_input_pin() {

src/eh0/serial.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
//! # use eh0 as embedded_hal;
1313
//! // Note that we're using the non-blocking serial traits
1414
//! use embedded_hal::serial::{Read, Write};
15-
//! use embedded_hal_mock::eh0::serial::{
16-
//! Mock as SerialMock,
17-
//! Transaction as SerialTransaction,
18-
//! };
15+
//! use embedded_hal_mock::eh0::serial::{Mock as SerialMock, Transaction as SerialTransaction};
1916
//!
2017
//! // Configure expectations
2118
//! let expectations = [
@@ -51,12 +48,8 @@
5148
//! ```
5249
//! # use eh0 as embedded_hal;
5350
//! // Note that we're using the blocking serial write trait
54-
//! use embedded_hal::blocking::serial::Write;
55-
//! use embedded_hal::serial::Read;
56-
//! use embedded_hal_mock::eh0::serial::{
57-
//! Mock as SerialMock,
58-
//! Transaction as SerialTransaction,
59-
//! };
51+
//! use embedded_hal::{blocking::serial::Write, serial::Read};
52+
//! use embedded_hal_mock::eh0::serial::{Mock as SerialMock, Transaction as SerialTransaction};
6053
//!
6154
//! // Configure expectations
6255
//! let expectations = [
@@ -99,6 +92,7 @@
9992
//! # Transaction as SerialTransaction,
10093
//! # };
10194
//! use std::io::ErrorKind;
95+
//!
10296
//! use embedded_hal_mock::eh0::MockError;
10397
//!
10498
//! // Configure expectations
@@ -192,8 +186,7 @@ enum Mode<Word> {
192186
/// # Example
193187
///
194188
/// ```no_run
195-
/// use embedded_hal_mock::eh0::serial::Transaction;
196-
/// use embedded_hal_mock::eh0::serial::Mock;
189+
/// use embedded_hal_mock::eh0::serial::{Mock, Transaction};
197190
///
198191
/// // We expect, in order,
199192
/// // 1. A read that returns 0x23,
@@ -202,7 +195,7 @@ enum Mode<Word> {
202195
/// let transactions = [
203196
/// Transaction::read(0x23),
204197
/// Transaction::write_many([0x55, 0xAA]),
205-
/// Transaction::flush()
198+
/// Transaction::flush(),
206199
/// ];
207200
///
208201
/// let mut serial = Mock::new(&transactions);
@@ -463,9 +456,6 @@ impl<Word> write::Default<Word> for Mock<Word> where Word: PartialEq + std::fmt:
463456

464457
#[cfg(test)]
465458
mod test {
466-
use super::super::error::MockError;
467-
use super::*;
468-
469459
use std::io;
470460

471461
use eh0 as embedded_hal;
@@ -474,6 +464,8 @@ mod test {
474464
serial::{Read, Write},
475465
};
476466

467+
use super::{super::error::MockError, *};
468+
477469
#[test]
478470
fn test_serial_mock_read() {
479471
let ts = [Transaction::read(0x54)];

0 commit comments

Comments
 (0)