on master help sign in
use Results in integration tests for more error context
1533f48Skyler Hawthorne
helix-term/tests/integration/commands.rs+1−1
@@ -59,7 +59,7 @@ async fn test_buffer_close() -> anyhow::Result<()> {
59 .await?;
59 .await?;
60
60
61 // verify if writes are queued up, it finishes them before closing the buffer
61 // 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()?;
63 let mut command = String::new();
63 let mut command = String::new();
64 const RANGE: RangeInclusive<i32> = 1..=10;
64 const RANGE: RangeInclusive<i32> = 1..=10;
65
65
helix-term/tests/integration/helpers.rs+15−10
@@ -81,8 +81,10 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>(
81 test_fn: &dyn Fn(&Application),
81 test_fn: &dyn Fn(&Application),
82) -> anyhow::Result<()> {
82) -> anyhow::Result<()> {
83 let test_case = test_case.into();
83 let test_case = test_case.into();
84− let mut app =
84+ let mut app = match app {
85+ Some(app) => app,
85− app.unwrap_or_else(|| Application::new(Args::default(), Config::default()).unwrap());
86+ None => Application::new(Args::default(), Config::default())?,
87+ };
86
88
87 let (view, doc) = helix_view::current!(app.editor);
89 let (view, doc) = helix_view::current!(app.editor);
88 let sel = doc.selection(view.id).clone();
90 let sel = doc.selection(view.id).clone();
@@ -108,7 +110,7 @@ pub async fn test_key_sequence_text_result<T: Into<TestCase>>(
108 test_case: T,
110 test_case: T,
109) -> anyhow::Result<()> {
111) -> anyhow::Result<()> {
110 let test_case = test_case.into();
112 let test_case = test_case.into();
111− let app = Application::new(args, config).unwrap();
113+ let app = Application::new(args, config)?;
112
114
113 test_key_sequence_with_input_text(Some(app), test_case.clone(), &|app| {
115 test_key_sequence_with_input_text(Some(app), test_case.clone(), &|app| {
114 let doc = doc!(app.editor);
116 let doc = doc!(app.editor);
@@ -123,13 +125,16 @@ pub async fn test_key_sequence_text_result<T: Into<TestCase>>(
123 .await
125 .await
124}
126}
125
127
126−pub fn temp_file_with_contents<S: AsRef<str>>(content: S) -> tempfile::NamedTempFile {
128+pub fn temp_file_with_contents<S: AsRef<str>>(
129+ content: S,
130+) -> anyhow::Result<tempfile::NamedTempFile> {
127− let mut temp_file = tempfile::NamedTempFile::new().unwrap();
131+ let mut temp_file = tempfile::NamedTempFile::new()?;
132+
128 temp_file
133 temp_file
129 .as_file_mut()
134 .as_file_mut()
130− .write_all(content.as_ref().as_bytes())
135+ .write_all(content.as_ref().as_bytes())?;
131− .unwrap();
136+
132− temp_file.flush().unwrap();
137+ temp_file.flush()?;
133− temp_file.as_file_mut().sync_all().unwrap();
138+ temp_file.as_file_mut().sync_all()?;
134− temp_file
139+ Ok(temp_file)
135}
140}
helix-term/tests/integration/movement.rs+8−7
@@ -109,8 +109,8 @@ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> {
109/// the first grapheme
109/// the first grapheme
110#[tokio::test]
110#[tokio::test]
111async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
111async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
112− let test = |content: &str, expected_sel: Selection| {
112+ let test = |content: &str, expected_sel: Selection| -> anyhow::Result<()> {
113− let file = helpers::temp_file_with_contents(content);
113+ let file = helpers::temp_file_with_contents(content)?;
114
114
115 let mut app = Application::new(
115 let mut app = Application::new(
116 Args {
116 Args {
@@ -118,17 +118,18 @@ async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
118 ..Default::default()
118 ..Default::default()
119 },
119 },
120 Config::default(),
120 Config::default(),
121− )
121+ )?;
122− .unwrap();
123
122
124 let (view, doc) = helix_view::current!(app.editor);
123 let (view, doc) = helix_view::current!(app.editor);
125 let sel = doc.selection(view.id).clone();
124 let sel = doc.selection(view.id).clone();
126 assert_eq!(expected_sel, sel);
125 assert_eq!(expected_sel, sel);
126+
127+ Ok(())
127 };
128 };
128
129
129− test("foo", Selection::single(0, 1));
130+ test("foo", Selection::single(0, 1))?;
130− test("👨‍👩‍👧‍👦 foo", Selection::single(0, 7));
131+ test("👨‍👩‍👧‍👦 foo", Selection::single(0, 7))?;
131− test("", Selection::single(0, 0));
132+ test("", Selection::single(0, 0))?;
132
133
133 Ok(())
134 Ok(())
134}
135}
helix-term/tests/integration/write.rs+2−3
@@ -11,7 +11,7 @@ use super::*;
11
11
12#[tokio::test]
12#[tokio::test]
13async fn test_write() -> anyhow::Result<()> {
13async fn test_write() -> anyhow::Result<()> {
14− let mut file = tempfile::NamedTempFile::new().unwrap();
14+ let mut file = tempfile::NamedTempFile::new()?;
15
15
16 test_key_sequence(
16 test_key_sequence(
17 &mut Application::new(
17 &mut Application::new(
@@ -38,7 +38,7 @@ async fn test_write() -> anyhow::Result<()> {
38
38
39#[tokio::test]
39#[tokio::test]
40async fn test_write_concurrent() -> anyhow::Result<()> {
40async fn test_write_concurrent() -> anyhow::Result<()> {
41− let mut file = tempfile::NamedTempFile::new().unwrap();
41+ let mut file = tempfile::NamedTempFile::new()?;
42 let mut command = String::new();
42 let mut command = String::new();
43 const RANGE: RangeInclusive<i32> = 1..=5000;
43 const RANGE: RangeInclusive<i32> = 1..=5000;
44
44
@@ -112,7 +112,6 @@ async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
112}
112}
113
113
114#[tokio::test]
114#[tokio::test]
115−#[ignore]
116async fn test_write_fail_new_path() -> anyhow::Result<()> {
115async fn test_write_fail_new_path() -> anyhow::Result<()> {
117 test_key_sequences(
116 test_key_sequences(
118 &mut Application::new(Args::default(), Config::default())?,
117 &mut Application::new(Args::default(), Config::default())?,