on master help sign in
use Results in integration tests for more error context
commit1533f489340fb63eee31c12122d6233cb5f6abaf authorSkyler Hawthorne <skyler@dead10ck.com> dateMon 25 Apr 2022, 20:25 (5 years ago) parent2fbf833
4 files changed+26−21
helix-term/tests/integration/commands.rs+1−1 helix-term/tests/integration/helpers.rs+15−10 helix-term/tests/integration/movement.rs+8−7 helix-term/tests/integration/write.rs+2−3
helix-term/tests/integration/commands.rs+1−1
@@ -59,7 +59,7 @@ async fn test_buffer_close() -> anyhow::Result<()> {
5959 .await?;
6060
6161 // verify if writes are queued up, it finishes them before closing the buffer
62− let mut file = tempfile::NamedTempFile::new().unwrap();
62+ let mut file = tempfile::NamedTempFile::new()?;
6363 let mut command = String::new();
6464 const RANGE: RangeInclusive<i32> = 1..=10;
6565
helix-term/tests/integration/helpers.rs+15−10
@@ -81,8 +81,10 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>(
8181 test_fn: &dyn Fn(&Application),
8282) -> anyhow::Result<()> {
8383 let test_case = test_case.into();
84− let mut app =
85− app.unwrap_or_else(|| Application::new(Args::default(), Config::default()).unwrap());
84+ let mut app = match app {
85+ Some(app) => app,
86+ None => Application::new(Args::default(), Config::default())?,
87+ };
8688
8789 let (view, doc) = helix_view::current!(app.editor);
8890 let sel = doc.selection(view.id).clone();
@@ -108,7 +110,7 @@ pub async fn test_key_sequence_text_result<T: Into<TestCase>>(
108110 test_case: T,
109111) -> anyhow::Result<()> {
110112 let test_case = test_case.into();
111− let app = Application::new(args, config).unwrap();
113+ let app = Application::new(args, config)?;
112114
113115 test_key_sequence_with_input_text(Some(app), test_case.clone(), &|app| {
114116 let doc = doc!(app.editor);
@@ -123,13 +125,16 @@ pub async fn test_key_sequence_text_result<T: Into<TestCase>>(
123125 .await
124126}
125127
126−pub fn temp_file_with_contents<S: AsRef<str>>(content: S) -> tempfile::NamedTempFile {
127− let mut temp_file = tempfile::NamedTempFile::new().unwrap();
128+pub fn temp_file_with_contents<S: AsRef<str>>(
129+ content: S,
130+) -> anyhow::Result<tempfile::NamedTempFile> {
131+ let mut temp_file = tempfile::NamedTempFile::new()?;
132+
128133 temp_file
129134 .as_file_mut()
130− .write_all(content.as_ref().as_bytes())
131− .unwrap();
132− temp_file.flush().unwrap();
133− temp_file.as_file_mut().sync_all().unwrap();
134− temp_file
135+ .write_all(content.as_ref().as_bytes())?;
136+
137+ temp_file.flush()?;
138+ temp_file.as_file_mut().sync_all()?;
139+ Ok(temp_file)
135140}
helix-term/tests/integration/movement.rs+8−7
@@ -109,8 +109,8 @@ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> {
109109/// the first grapheme
110110#[tokio::test]
111111async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
112− let test = |content: &str, expected_sel: Selection| {
113− let file = helpers::temp_file_with_contents(content);
112+ let test = |content: &str, expected_sel: Selection| -> anyhow::Result<()> {
113+ let file = helpers::temp_file_with_contents(content)?;
114114
115115 let mut app = Application::new(
116116 Args {
@@ -118,17 +118,18 @@ async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
118118 ..Default::default()
119119 },
120120 Config::default(),
121− )
122− .unwrap();
121+ )?;
123122
124123 let (view, doc) = helix_view::current!(app.editor);
125124 let sel = doc.selection(view.id).clone();
126125 assert_eq!(expected_sel, sel);
126+
127+ Ok(())
127128 };
128129
129− test("foo", Selection::single(0, 1));
130− test("👨‍👩‍👧‍👦 foo", Selection::single(0, 7));
131− test("", Selection::single(0, 0));
130+ test("foo", Selection::single(0, 1))?;
131+ test("👨‍👩‍👧‍👦 foo", Selection::single(0, 7))?;
132+ test("", Selection::single(0, 0))?;
132133
133134 Ok(())
134135}
helix-term/tests/integration/write.rs+2−3
@@ -11,7 +11,7 @@ use super::*;
1111
1212#[tokio::test]
1313async fn test_write() -> anyhow::Result<()> {
14− let mut file = tempfile::NamedTempFile::new().unwrap();
14+ let mut file = tempfile::NamedTempFile::new()?;
1515
1616 test_key_sequence(
1717 &mut Application::new(
@@ -38,7 +38,7 @@ async fn test_write() -> anyhow::Result<()> {
3838
3939#[tokio::test]
4040async fn test_write_concurrent() -> anyhow::Result<()> {
41− let mut file = tempfile::NamedTempFile::new().unwrap();
41+ let mut file = tempfile::NamedTempFile::new()?;
4242 let mut command = String::new();
4343 const RANGE: RangeInclusive<i32> = 1..=5000;
4444
@@ -112,7 +112,6 @@ async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
112112}
113113
114114#[tokio::test]
115−#[ignore]
116115async fn test_write_fail_new_path() -> anyhow::Result<()> {
117116 test_key_sequences(
118117 &mut Application::new(Args::default(), Config::default())?,