diff options
author | Skyler Hawthorne | 2022-04-26 00:25:16 +0000 |
---|---|---|
committer | Skyler Hawthorne | 2022-06-19 03:54:03 +0000 |
commit | 1533f489340fb63eee31c12122d6233cb5f6abaf (patch) | |
tree | 2b31c8ce7295ae45de55663a5fccbe551f9494a8 /helix-term/tests/integration/helpers.rs | |
parent | 2fbf83363028179fe8d3908b5d9911d8595163b1 (diff) |
use Results in integration tests for more error context
Diffstat (limited to 'helix-term/tests/integration/helpers.rs')
-rw-r--r-- | helix-term/tests/integration/helpers.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/helix-term/tests/integration/helpers.rs b/helix-term/tests/integration/helpers.rs index 29cb8cd8..2a542404 100644 --- a/helix-term/tests/integration/helpers.rs +++ b/helix-term/tests/integration/helpers.rs @@ -81,8 +81,10 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>( test_fn: &dyn Fn(&Application), ) -> anyhow::Result<()> { let test_case = test_case.into(); - let mut app = - app.unwrap_or_else(|| Application::new(Args::default(), Config::default()).unwrap()); + let mut app = match app { + Some(app) => app, + None => Application::new(Args::default(), Config::default())?, + }; let (view, doc) = helix_view::current!(app.editor); let sel = doc.selection(view.id).clone(); @@ -108,7 +110,7 @@ pub async fn test_key_sequence_text_result<T: Into<TestCase>>( test_case: T, ) -> anyhow::Result<()> { let test_case = test_case.into(); - let app = Application::new(args, config).unwrap(); + let app = Application::new(args, config)?; test_key_sequence_with_input_text(Some(app), test_case.clone(), &|app| { let doc = doc!(app.editor); @@ -123,13 +125,16 @@ pub async fn test_key_sequence_text_result<T: Into<TestCase>>( .await } -pub fn temp_file_with_contents<S: AsRef<str>>(content: S) -> tempfile::NamedTempFile { - let mut temp_file = tempfile::NamedTempFile::new().unwrap(); +pub fn temp_file_with_contents<S: AsRef<str>>( + content: S, +) -> anyhow::Result<tempfile::NamedTempFile> { + let mut temp_file = tempfile::NamedTempFile::new()?; + temp_file .as_file_mut() - .write_all(content.as_ref().as_bytes()) - .unwrap(); - temp_file.flush().unwrap(); - temp_file.as_file_mut().sync_all().unwrap(); - temp_file + .write_all(content.as_ref().as_bytes())?; + + temp_file.flush()?; + temp_file.as_file_mut().sync_all()?; + Ok(temp_file) } |