Skip to content

Commit

Permalink
Test panics in reader/writer initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Schlegel committed Sep 14, 2020
1 parent 4f3e16a commit c27f7bb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
11 changes: 11 additions & 0 deletions tests/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,14 @@ fn reader_init_fail() {
panic!("init should fail");
}
}

#[test]
#[should_panic(expected = "init panic")]
fn reader_init_panic() {
reader_init::<&[u8], _, _, _, _>(
5,
2,
|| panic!("init panic"),
|_| Ok::<_, ()>(()),
).unwrap();
}
17 changes: 13 additions & 4 deletions tests/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ fn writer_init_fail() {
5,
2,
|| Err::<&mut [u8], _>(e),
|writer| {
writer.write(b"let the cows come home")?;
Ok(())
},
|writer| writer.write(b"let the cows come home"),
);
if let Err(e) = res {
assert_eq!(&format!("{}", e), "init err");
Expand All @@ -122,6 +119,18 @@ fn writer_init_fail() {
}
}

#[test]
#[should_panic(expected = "init panic")]
fn writer_init_panic() {
writer_init::<&mut Vec<u8>, _, _, _, _>(
5,
2,
|| panic!("init panic"),
|writer| writer.write(b"let the cows come home"),
).unwrap();
}


#[test]
fn write_fail() {
let text = b"The quick brown fox jumps over the lazy dog";
Expand Down

0 comments on commit c27f7bb

Please sign in to comment.