Skip to content

Commit

Permalink
Merge pull request dbrgn#90 from dbrgn/fix-tests-nightly
Browse files Browse the repository at this point in the history
Fix tests in nightly, bump MSRV to 1.63
  • Loading branch information
dbrgn authored Sep 14, 2023
2 parents 04f0ef5 + 25fdfe0 commit d098cf2
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 223 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
matrix:
toolchain:
- "1.60"
- "1.63"
- "nightly"
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `Generic` mock: Fix a bug that caused the call to `.done()` to fail if
`.next()` was called on the mock after all expectations have already been
consumed (#58)
- Fix assertion error message for SPI `transfer` and ` transfer_in_place` (#90)

### Changed

- Bump minimal supported Rust version (MSRV) to 1.63
- The minimal supported Rust version (MSRV) is specified in the `Cargo.toml` to
offer clearer error messages to consumers with outdated Rust versions
- Renamed `delay::MockNoop` to `delay::NoopDelay`.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include = [
"LICENSE-APACHE",
]
edition = "2021"
rust-version = "1.60"
rust-version = "1.63"

[features]
eh0 = ["dep:eh0", "dep:nb"]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Pull requests for more mock implementations are welcome! :)

## Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.60 and up. It *might*
This crate is guaranteed to compile on stable Rust 1.63 and up. It *might*
compile with older versions but that may change in any new patch release.

## Development Version of `embedded-hal`
Expand Down Expand Up @@ -86,6 +86,6 @@ be dual licensed as above, without any additional terms or conditions.
<!-- Badges -->
[github-actions]: https://github.com/dbrgn/embedded-hal-mock/actions/workflows/ci.yml
[github-actions-badge]: https://github.com/dbrgn/embedded-hal-mock/actions/workflows/ci.yml/badge.svg
[min-rust-badge]: https://img.shields.io/badge/rustc-1.60+-blue.svg
[min-rust-badge]: https://img.shields.io/badge/rustc-1.63+-blue.svg
[crates-io]: https://crates.io/crates/embedded-hal-mock
[version-badge]: https://img.shields.io/crates/v/embedded-hal-mock.svg
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.60"
msrv = "1.63"
20 changes: 5 additions & 15 deletions src/eh0/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,7 @@ mod test {
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `[1, 2]`,\n right: `[1, 3]`: i2c::write data does not match expectation"
)]
#[should_panic(expected = "i2c::write data does not match expectation")]
fn write_data_mismatch() {
let expectations = [Transaction::write(0xaa, vec![1, 2])];
let mut i2c = Mock::new(&expectations);
Expand All @@ -349,9 +347,7 @@ mod test {
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `Read`,\n right: `Write`: i2c::write unexpected mode"
)]
#[should_panic(expected = "i2c::write unexpected mode")]
fn transaction_type_mismatch() {
let expectations = [Transaction::read(0xaa, vec![10, 12])];
let mut i2c = Mock::new(&expectations);
Expand Down Expand Up @@ -432,9 +428,7 @@ mod test {

/// The transaction mode should still be validated.
#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `Write`,\n right: `Read`: i2c::read unexpected mode"
)]
#[should_panic(expected = "i2c::read unexpected mode")]
fn write_wrong_mode() {
let mut i2c = Mock::new(&[Transaction::write(0xaa, vec![10, 12])
.with_error(MockError::Io(IoErrorKind::Other))]);
Expand All @@ -444,9 +438,7 @@ mod test {

/// The transaction bytes should still be validated.
#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `[10, 12]`,\n right: `[10, 13]`: i2c::write data does not match expectation"
)]
#[should_panic(expected = "i2c::write data does not match expectation")]
fn write_wrong_data() {
let mut i2c = Mock::new(&[Transaction::write(0xaa, vec![10, 12])
.with_error(MockError::Io(IoErrorKind::Other))]);
Expand Down Expand Up @@ -479,9 +471,7 @@ mod test {

/// The transaction bytes should still be validated.
#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `[10, 12]`,\n right: `[10, 13]`: i2c::write_read write data does not match expectation"
)]
#[should_panic(expected = "i2c::write_read write data does not match expectation")]
fn write_read_wrong_data() {
let mut i2c = Mock::new(&[Transaction::write_read(0xaa, vec![10, 12], vec![13, 14])
.with_error(MockError::Io(IoErrorKind::Other))]);
Expand Down
8 changes: 2 additions & 6 deletions src/eh0/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,7 @@ mod test {
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `18`,\n right: `20`: serial::write expected to write 18 but actually wrote 20"
)]
#[should_panic(expected = "serial::write expected to write 18 but actually wrote 20")]
fn test_serial_mock_wrong_write() {
let ts = [Transaction::write(0x12)];
let mut ser = Mock::new(&ts);
Expand Down Expand Up @@ -618,9 +616,7 @@ mod test {
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `42`,\n right: `23`: serial::write expected to write 42 but actually wrote 23"
)]
#[should_panic(expected = "serial::write expected to write 42 but actually wrote 23")]
fn test_serial_mock_write_error_wrong_data() {
let error = nb::Error::Other(MockError::Io(io::ErrorKind::NotConnected));
let ts = [Transaction::write_error(42, error.clone())];
Expand Down
71 changes: 14 additions & 57 deletions src/eh0/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl spi::Transfer<u8> for Mock {
);
assert_eq!(
&w.expected_data, &buffer,
"spi::write data does not match expectation"
"spi::transfer write data does not match expectation"
);
assert_eq!(
buffer.len(),
Expand Down Expand Up @@ -323,89 +323,46 @@ mod test {
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `[10, 12]`,\n right: `[10, 12, 12]`: spi::write data does not match expectation"
)]
#[should_panic(expected = "spi::write data does not match expectation")]
fn test_spi_mock_write_err() {
let expectations = [Transaction::write(vec![10, 12])];
let mut spi = Mock::new(&expectations);

spi.write(&vec![10, 12, 12]).unwrap();

spi.done();
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `[10, 12]`,\n right: `[10, 12, 12]`: spi::write_iter data does not match expectation"
)]
#[should_panic(expected = "spi::write_iter data does not match expectation")]
fn test_spi_mock_write_iter_err() {
let expectations = [Transaction::write(vec![10, 12])];
let mut spi = Mock::new(&expectations);

spi.write_iter(vec![10, 12, 12u8]).unwrap();

spi.done();
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `[12, 15]`,\n right: `[12, 13]`"
)]
#[should_panic(expected = "spi::transfer write data does not match expectation")]
fn test_spi_mock_transfer_err() {
let expectations = [Transaction::transfer(vec![10, 12], vec![12, 15])];
let mut spi = Mock::new(&expectations);

let mut v = vec![10, 12];
spi.transfer(&mut v).unwrap();

assert_eq!(v, vec![12, 13]);

spi.done();
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `[1, 2]`,\n right: `[10, 12]`: spi::write data does not match expectation"
)]
fn test_spi_mock_transfer_response_err() {
let expectations = [Transaction::transfer(vec![1, 2], vec![3, 4, 5])];
let mut spi = Mock::new(&expectations);

let mut v = vec![10, 12];
spi.transfer(&mut v).unwrap();

assert_eq!(v, vec![12, 13]);

spi.done();
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `Transfer`,\n right: `Write`: spi::write unexpected mode"
)]
fn test_spi_mock_mode_err() {
let expectations = [Transaction::transfer(vec![10, 12], vec![])];
let mut spi = Mock::new(&expectations);

spi.write(&vec![10, 12, 12]).unwrap();

spi.done();
spi.transfer(&mut vec![10, 13]).unwrap();
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `[10, 12]`,\n right: `[10, 12, 12]`: spi::write data does not match expectation"
)]
#[should_panic(expected = "spi::write data does not match expectation")]
fn test_spi_mock_multiple_transaction_err() {
let expectations = [
Transaction::write(vec![10, 12]),
Transaction::write(vec![10, 12]),
];
let mut spi = Mock::new(&expectations);
spi.write(&vec![10, 12, 10]).unwrap();
}

#[test]
#[should_panic(expected = "spi::write unexpected mode")]
fn test_spi_mock_mode_err() {
let expectations = [Transaction::transfer(vec![10, 12], vec![])];
let mut spi = Mock::new(&expectations);
// Write instead of transfer
spi.write(&vec![10, 12, 12]).unwrap();

spi.done();
}
}
36 changes: 9 additions & 27 deletions src/eh1/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,7 @@ mod test {
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `[1, 2]`,\n right: `[1, 3]`: i2c::write data does not match expectation"
)]
#[should_panic(expected = "i2c::write data does not match expectation")]
fn write_data_mismatch() {
let expectations = [Transaction::write(0xaa, vec![1, 2])];
let mut i2c = Mock::new(&expectations);
Expand All @@ -395,9 +393,7 @@ mod test {
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `Read`,\n right: `Write`: i2c::write unexpected mode"
)]
#[should_panic(expected = "i2c::write unexpected mode")]
fn transaction_type_mismatch() {
let expectations = [Transaction::read(0xaa, vec![10, 12])];
let mut i2c = Mock::new(&expectations);
Expand All @@ -407,9 +403,7 @@ mod test {
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `187`,\n right: `170`: i2c::write_read address mismatch"
)]
#[should_panic(expected = "i2c::write_read address mismatch")]
fn address_mismatch() {
let expectations = [Transaction::write_read(0xbb, vec![1, 2], vec![3, 4])];
let mut i2c = Mock::new(&expectations);
Expand All @@ -420,9 +414,7 @@ mod test {
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `Read`,\n right: `Write`: i2c::write unexpected mode"
)]
#[should_panic(expected = "i2c::write unexpected mode")]
fn test_i2c_mock_mode_err() {
let expectations = [Transaction::read(0xaa, vec![10, 12])];
let mut i2c = Mock::new(&expectations);
Expand Down Expand Up @@ -493,9 +485,7 @@ mod test {

/// The transaction mode should still be validated.
#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `Write`,\n right: `Read`: i2c::read unexpected mode"
)]
#[should_panic(expected = "i2c::read unexpected mode")]
fn write_wrong_mode() {
let mut i2c =
Mock::new(&[Transaction::write(0xaa, vec![10, 12]).with_error(ErrorKind::Other)]);
Expand All @@ -505,9 +495,7 @@ mod test {

/// The transaction bytes should still be validated.
#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `[10, 12]`,\n right: `[10, 13]`: i2c::write data does not match expectation"
)]
#[should_panic(expected = "i2c::write data does not match expectation")]
fn write_wrong_data() {
let mut i2c =
Mock::new(&[Transaction::write(0xaa, vec![10, 12]).with_error(ErrorKind::Other)]);
Expand All @@ -529,9 +517,7 @@ mod test {

/// The transaction mode should still be validated.
#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `Read`,\n right: `Write`: i2c::write unexpected mode"
)]
#[should_panic(expected = "i2c::write unexpected mode")]
fn read_wrong_mode() {
let mut i2c =
Mock::new(&[Transaction::read(0xaa, vec![10, 12]).with_error(ErrorKind::Other)]);
Expand All @@ -551,9 +537,7 @@ mod test {

/// The transaction mode should still be validated.
#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `WriteRead`,\n right: `Write`: i2c::write unexpected mode"
)]
#[should_panic(expected = "i2c::write unexpected mode")]
fn write_read_wrong_mode() {
let mut i2c = Mock::new(&[Transaction::write_read(0xaa, vec![10, 12], vec![13, 14])
.with_error(ErrorKind::Other)]);
Expand All @@ -562,9 +546,7 @@ mod test {

/// The transaction bytes should still be validated.
#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `[10, 12]`,\n right: `[10, 13]`: i2c::write_read write data does not match expectation"
)]
#[should_panic(expected = "i2c::write_read write data does not match expectation")]
fn write_read_wrong_data() {
let mut i2c = Mock::new(&[Transaction::write_read(0xaa, vec![10, 12], vec![13, 14])
.with_error(ErrorKind::Other)]);
Expand Down
8 changes: 2 additions & 6 deletions src/eh1/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,7 @@ mod test {
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `18`,\n right: `20`: serial::write expected to write 18 but actually wrote 20"
)]
#[should_panic(expected = "serial::write expected to write 18 but actually wrote 20")]
fn test_serial_mock_wrong_write() {
let ts = [Transaction::write(0x12)];
let mut ser = Mock::new(&ts);
Expand Down Expand Up @@ -623,9 +621,7 @@ mod test {
}

#[test]
#[should_panic(
expected = "assertion failed: `(left == right)`\n left: `42`,\n right: `23`: serial::write expected to write 42 but actually wrote 23"
)]
#[should_panic(expected = "serial::write expected to write 42 but actually wrote 23")]
fn test_serial_mock_write_error_wrong_data() {
let error = nb::Error::Other(ErrorKind::Parity);
let ts = [Transaction::write_error(42, error.clone())];
Expand Down
Loading

0 comments on commit d098cf2

Please sign in to comment.