Skip to content

Commit

Permalink
embedded-hal: 1.0.0-alpha.10 -> 1.0.0-rc.1
Browse files Browse the repository at this point in the history
  • Loading branch information
newAM authored and cdunster committed Sep 18, 2023
1 parent 8a549df commit 7c9373d
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 297 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ default = ["eh0", "embedded-time"]

[dependencies]
eh0 = { package = "embedded-hal", version = "0.2.7", features = ["unproven"], optional = true }
eh1 = { package = "embedded-hal", version = "=1.0.0-alpha.10", optional = true }
embedded-hal-nb = { version = "=1.0.0-alpha.2", optional = true }
embedded-hal-async = { version = "=0.2.0-alpha.1", optional = true }
eh1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true }
embedded-hal-nb = { version = "=1.0.0-rc.1", optional = true }
embedded-hal-async = { version = "=1.0.0-rc.1", optional = true }
embedded-time = { version = "0.12", optional = true }
nb = { version = "0.1.1", optional = true}
void = { version = "^1.0", optional = true }
Expand Down
117 changes: 4 additions & 113 deletions src/eh1/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,46 +46,6 @@
//! serial.done();
//! ```
//!
//! ## Usage: Blocking serial trait
//!
//! ```
//! # use eh1 as embedded_hal;
//! // Note that we're using the blocking serial write trait
//! use embedded_hal::serial::Write;
//! use embedded_hal_nb::serial::Read;
//! use embedded_hal_mock::eh1::serial::{
//! Mock as SerialMock,
//! Transaction as SerialTransaction,
//! };
//!
//! // Configure expectations
//! let expectations = [
//! SerialTransaction::read(0x0A),
//! SerialTransaction::read_many(b"xy"),
//! SerialTransaction::write_many([1, 2]), // (2)
//! SerialTransaction::flush(),
//! ];
//!
//! let mut serial = SerialMock::new(&expectations);
//!
//! // Expect three reads
//! assert_eq!(serial.read().unwrap(), 0x0A);
//! assert_eq!(serial.read().unwrap(), b'x');
//! assert_eq!(serial.read().unwrap(), b'y');
//!
//! // We use the blocking write here, and we assert that
//! // two words are written. See (2) above.
//! Write::write(&mut serial, &[1, 2]).unwrap();
//!
//! // Finally, we expect a flush. Note that this is
//! // a *blocking* flush from the blocking serial trait.
//! Write::flush(&mut serial).unwrap();
//!
//! // When you believe there are no more calls on the mock,
//! // call done() to assert there are no pending transactions.
//! serial.done();
//! ```
//!
//! ## Testing Error Handling
//!
//! If you want to test error handling of your code, you can also add error
Expand All @@ -98,8 +58,7 @@
//! # Transaction as SerialTransaction,
//! # };
//! use embedded_hal_nb::nb;
//! use embedded_hal_nb::serial::{Read, Write};
//! use embedded_hal::serial::ErrorKind;
//! use embedded_hal_nb::serial::{Read, Write, ErrorKind};
//!
//! // Configure expectations
//! let expectations = [
Expand Down Expand Up @@ -151,11 +110,10 @@ use std::{
sync::{Arc, Mutex},
};

use eh1 as embedded_hal;
use embedded_hal::serial::ErrorKind;
use embedded_hal::serial::ErrorType;
use embedded_hal_nb::nb;
use embedded_hal_nb::serial;
use embedded_hal_nb::serial::ErrorKind;
use embedded_hal_nb::serial::ErrorType;

use crate::common::DoneCallDetector;

Expand Down Expand Up @@ -436,29 +394,11 @@ where
}
}

impl<Word> embedded_hal::serial::Write<Word> for Mock<Word>
where
Word: PartialEq + std::fmt::Debug + Clone + Copy,
{
fn write(&mut self, buffer: &[Word]) -> Result<(), Self::Error> {
for word in buffer {
nb::block!(serial::Write::write(self, word.clone()))?;
}
Ok(())
}

fn flush(&mut self) -> Result<(), Self::Error> {
nb::block!(serial::Write::flush(self))
}
}

#[cfg(test)]
mod test {
use super::*;

use eh1 as embedded_hal;
use embedded_hal::serial::ErrorKind;
use embedded_hal_nb::serial::{Read, Write};
use embedded_hal_nb::serial::{ErrorKind, Read, Write};

#[test]
fn test_serial_mock_read() {
Expand Down Expand Up @@ -497,35 +437,6 @@ mod test {
ser.done();
}

#[test]
fn test_serial_mock_blocking_write() {
use embedded_hal::serial::Write as BWrite;
let ts = [Transaction::write_many([0xAB, 0xCD, 0xEF])];
let mut ser = Mock::new(&ts);
BWrite::write(&mut ser, &[0xAB, 0xCD, 0xEF]).unwrap();
ser.done();
}

#[test]
#[should_panic(expected = "called serial::write with no expectation")]
fn test_serial_mock_blocking_write_more_than_expected() {
use embedded_hal::serial::Write as BWrite;
let ts = [Transaction::write_many([0xAB, 0xCD])];
let mut ser = Mock::new(&ts);
BWrite::write(&mut ser, &[0xAB, 0xCD, 0xEF]).unwrap();
ser.done();
}

#[test]
#[should_panic(expected = "serial mock has unsatisfied expectations after call to done")]
fn test_serial_mock_blocking_write_not_enough() {
use embedded_hal::serial::Write as BWrite;
let ts = [Transaction::write_many([0xAB, 0xCD, 0xEF, 0x00])];
let mut ser = Mock::new(&ts);
BWrite::write(&mut ser, &[0xAB, 0xCD, 0xEF]).unwrap();
ser.done();
}

#[test]
#[should_panic(expected = "serial::write expected to write 18 but actually wrote 20")]
fn test_serial_mock_wrong_write() {
Expand All @@ -542,15 +453,6 @@ mod test {
ser.done();
}

#[test]
fn test_serial_mock_blocking_flush() {
use embedded_hal::serial::Write as BWrite;
let ts = [Transaction::flush()];
let mut ser: Mock<u8> = Mock::new(&ts);
BWrite::flush(&mut ser).unwrap();
ser.done();
}

#[test]
#[should_panic(expected = "serial mock has unsatisfied expectations after call to done")]
fn test_serial_mock_pending_transactions() {
Expand All @@ -571,17 +473,6 @@ mod test {
ser.done();
}

#[test]
#[should_panic(
expected = "expected to perform a serial transaction 'Read(84)' but instead did a write of 119"
)]
fn test_serial_mock_expected_read() {
use embedded_hal::serial::Write as BWrite;
let ts = [Transaction::read(0x54)];
let mut ser = Mock::new(&ts);
BWrite::write(&mut ser, &[0x77]).unwrap();
}

#[test]
#[should_panic(
expected = "expected to perform a serial transaction 'Write(84)' but instead did a flush"
Expand Down
Loading

0 comments on commit 7c9373d

Please sign in to comment.