@@ -4,7 +4,6 @@ use std::{
44};
55
66use helix_core::diagnostic::Severity;
7−use helix_term::application::Application;
87use helix_view::doc;
98
109use super::*;
@@ -12,9 +11,12 @@ use super::*;
1211#[tokio::test]
1312async fn test_write() -> anyhow::Result<()> {
1413 let mut file = tempfile::NamedTempFile::new()?;
14+ let mut app = helpers::AppBuilder::new()
15+ .with_file(file.path(), None)
16+ .build()?;
1517
1618 test_key_sequence(
17− &mut helpers::app_with_file(file.path())?,
19+ &mut app,
1820 Some("ithe gostak distims the doshes<ret><esc>:w<ret>"),
1921 None,
2022 false,
@@ -38,9 +40,12 @@ async fn test_write() -> anyhow::Result<()> {
3840#[tokio::test(flavor = "multi_thread")]
3941async fn test_write_quit() -> anyhow::Result<()> {
4042 let mut file = tempfile::NamedTempFile::new()?;
43+ let mut app = helpers::AppBuilder::new()
44+ .with_file(file.path(), None)
45+ .build()?;
4146
4247 test_key_sequence(
43− &mut helpers::app_with_file(file.path())?,
48+ &mut app,
4449 Some("ithe gostak distims the doshes<ret><esc>:wq<ret>"),
4550 None,
4651 true,
@@ -66,19 +71,16 @@ async fn test_write_concurrent() -> anyhow::Result<()> {
6671 let mut file = tempfile::NamedTempFile::new()?;
6772 let mut command = String::new();
6873 const RANGE: RangeInclusive<i32> = 1..=5000;
74+ let mut app = helpers::AppBuilder::new()
75+ .with_file(file.path(), None)
76+ .build()?;
6977
7078 for i in RANGE {
7179 let cmd = format!("%c{}<esc>:w<ret>", i);
7280 command.push_str(&cmd);
7381 }
7482
75− test_key_sequence(
76− &mut helpers::app_with_file(file.path())?,
77− Some(&command),
78− None,
79− false,
80− )
81− .await?;
83+ test_key_sequence(&mut app, Some(&command), None, false).await?;
8284
8385 file.as_file_mut().flush()?;
8486 file.as_file_mut().sync_all()?;
@@ -93,9 +95,12 @@ async fn test_write_concurrent() -> anyhow::Result<()> {
9395#[tokio::test]
9496async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
9597 let file = helpers::new_readonly_tempfile()?;
98+ let mut app = helpers::AppBuilder::new()
99+ .with_file(file.path(), None)
100+ .build()?;
96101
97102 test_key_sequences(
98− &mut helpers::app_with_file(file.path())?,
103+ &mut app,
99104 vec![
100105 (
101106 None,
@@ -133,7 +138,7 @@ async fn test_write_scratch_to_new_path() -> anyhow::Result<()> {
133138 let mut file = tempfile::NamedTempFile::new()?;
134139
135140 test_key_sequence(
136− &mut Application::new(Args::default(), Config::default())?,
141+ &mut AppBuilder::new().build()?,
137142 Some(format!("ihello<esc>:w {}<ret>", file.path().to_string_lossy()).as_ref()),
138143 Some(&|app| {
139144 assert!(!app.editor.is_err());
@@ -174,19 +179,40 @@ async fn test_write_scratch_no_path_fails() -> anyhow::Result<()> {
174179 Ok(())
175180}
176181
182+#[tokio::test]
183+async fn test_write_auto_format_fails_still_writes() -> anyhow::Result<()> {
184+ let mut file = tempfile::Builder::new().suffix(".rs").tempfile()?;
185+
186+ let lang_conf = indoc! {r#"
187+ [[language]]
188+ name = "rust"
189+ formatter = { command = "bash", args = [ "-c", "exit 1" ] }
190+ "#};
191+
192+ let mut app = helpers::AppBuilder::new()
193+ .with_file(file.path(), None)
194+ .with_input_text("#[l|]#et foo = 0;\n")
195+ .with_lang_config(helpers::test_syntax_conf(Some(lang_conf.into())))
196+ .build()?;
197+
198+ test_key_sequences(&mut app, vec![(Some(":w<ret>"), None)], false).await?;
199+
200+ // file still saves
201+ helpers::assert_file_has_content(file.as_file_mut(), "let foo = 0;\n")?;
202+
203+ Ok(())
204+}
205+
177206#[tokio::test]
178207async fn test_write_new_path() -> anyhow::Result<()> {
179208 let mut file1 = tempfile::NamedTempFile::new().unwrap();
180209 let mut file2 = tempfile::NamedTempFile::new().unwrap();
210+ let mut app = helpers::AppBuilder::new()
211+ .with_file(file1.path(), None)
212+ .build()?;
181213
182214 test_key_sequences(
183− &mut Application::new(
184− Args {
185− files: vec![(file1.path().to_path_buf(), Position::default())],
186− ..Default::default()
187− },
188− Config::default(),
189− )?,
215+ &mut app,
190216 vec![
191217 (
192218 Some("ii can eat glass, it will not hurt me<ret><esc>:w<ret>"),
@@ -228,7 +254,7 @@ async fn test_write_fail_new_path() -> anyhow::Result<()> {
228254 let file = helpers::new_readonly_tempfile()?;
229255
230256 test_key_sequences(
231− &mut Application::new(Args::default(), Config::default())?,
257+ &mut AppBuilder::new().build()?,
232258 vec![
233259 (
234260 None,