aboutsummaryrefslogtreecommitdiffstats
path: root/tests/input.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-03-13 14:14:58 -0500
committerJesse Luehrs <doy@tozt.net>2021-03-13 14:14:58 -0500
commit88cce3303b5b0e0c69604c6d6d9ac603f083a540 (patch)
tree11aae750398d8c44335776cbfdc5797eb94f2dba /tests/input.rs
parentf5fde7583fcc7dba450615a68828851a2e6675d3 (diff)
downloadtextmode-88cce3303b5b0e0c69604c6d6d9ac603f083a540.tar.gz
textmode-88cce3303b5b0e0c69604c6d6d9ac603f083a540.zip
better test error messages
Diffstat (limited to 'tests/input.rs')
-rw-r--r--tests/input.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/input.rs b/tests/input.rs
index b2a8b28..033499f 100644
--- a/tests/input.rs
+++ b/tests/input.rs
@@ -198,14 +198,17 @@ fn run_input_test(
});
}
+#[track_caller]
fn write(f: &mut std::fs::File, key: textmode::Key) {
f.write_all(&key.into_bytes()).unwrap();
}
+#[track_caller]
fn read(f: &mut std::io::BufReader<&mut std::fs::File>) -> String {
std::string::String::from_utf8(fixtures::read_line(f)).unwrap()
}
+#[track_caller]
fn assert_line(
f: &mut std::io::BufReader<&mut std::fs::File>,
expected: &str,
@@ -213,7 +216,18 @@ fn assert_line(
assert_eq!(read(f), format!("{}\r\n", expected));
}
+#[track_caller]
fn assert_no_more_lines(f: &mut std::io::BufReader<&mut std::fs::File>) {
- assert!(!fixtures::read_ready(f.get_ref().as_raw_fd()));
- assert!(f.buffer().is_empty());
+ if fixtures::read_ready(f.get_ref().as_raw_fd()) || !f.buffer().is_empty()
+ {
+ use std::io::Read as _;
+ let mut buf = vec![0; 4096];
+ let bytes = f.read(&mut buf).unwrap();
+ buf.truncate(bytes);
+ panic!(
+ "got bytes: \"{}\"({:?})",
+ std::string::String::from_utf8_lossy(&buf),
+ buf
+ );
+ }
}