@@ -4,7 +4,6 @@ use std::{
6use helix_core::diagnostic::Severity;
6use helix_core::diagnostic::Severity;
7−use helix_term::application::Application;
8use helix_view::doc;
7use helix_view::doc;
10use super::*;
9use super::*;
@@ -12,9 +11,12 @@ use super::*;
12#[tokio::test]
11#[tokio::test]
13async fn test_write() -> anyhow::Result<()> {
12async fn test_write() -> anyhow::Result<()> {
14 let mut file = tempfile::NamedTempFile::new()?;
13 let mut file = tempfile::NamedTempFile::new()?;
14+ let mut app = helpers::AppBuilder::new()
15+ .with_file(file.path(), None)
16 test_key_sequence(
18 test_key_sequence(
17− &mut helpers::app_with_file(file.path())?,
19+ &mut app,
18 Some("ithe gostak distims the doshes<ret><esc>:w<ret>"),
20 Some("ithe gostak distims the doshes<ret><esc>:w<ret>"),
@@ -38,9 +40,12 @@ async fn test_write() -> anyhow::Result<()> {
38#[tokio::test(flavor = "multi_thread")]
40#[tokio::test(flavor = "multi_thread")]
39async fn test_write_quit() -> anyhow::Result<()> {
41async fn test_write_quit() -> anyhow::Result<()> {
40 let mut file = tempfile::NamedTempFile::new()?;
42 let mut file = tempfile::NamedTempFile::new()?;
43+ let mut app = helpers::AppBuilder::new()
44+ .with_file(file.path(), None)
42 test_key_sequence(
47 test_key_sequence(
43− &mut helpers::app_with_file(file.path())?,
48+ &mut app,
44 Some("ithe gostak distims the doshes<ret><esc>:wq<ret>"),
49 Some("ithe gostak distims the doshes<ret><esc>:wq<ret>"),
@@ -66,19 +71,16 @@ async fn test_write_concurrent() -> anyhow::Result<()> {
66 let mut file = tempfile::NamedTempFile::new()?;
71 let mut file = tempfile::NamedTempFile::new()?;
67 let mut command = String::new();
72 let mut command = String::new();
68 const RANGE: RangeInclusive<i32> = 1..=5000;
73 const RANGE: RangeInclusive<i32> = 1..=5000;
74+ let mut app = helpers::AppBuilder::new()
75+ .with_file(file.path(), None)
70 for i in RANGE {
78 for i in RANGE {
71 let cmd = format!("%c{}<esc>:w<ret>", i);
79 let cmd = format!("%c{}<esc>:w<ret>", i);
72 command.push_str(&cmd);
80 command.push_str(&cmd);
75− test_key_sequence(
83+ test_key_sequence(&mut app, Some(&command), None, false).await?;
76− &mut helpers::app_with_file(file.path())?,
83 file.as_file_mut().flush()?;
85 file.as_file_mut().flush()?;
84 file.as_file_mut().sync_all()?;
86 file.as_file_mut().sync_all()?;
@@ -93,9 +95,12 @@ async fn test_write_concurrent() -> anyhow::Result<()> {
93#[tokio::test]
95#[tokio::test]
94async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
96async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
95 let file = helpers::new_readonly_tempfile()?;
97 let file = helpers::new_readonly_tempfile()?;
98+ let mut app = helpers::AppBuilder::new()
99+ .with_file(file.path(), None)
97 test_key_sequences(
102 test_key_sequences(
98− &mut helpers::app_with_file(file.path())?,
103+ &mut app,
@@ -133,7 +138,7 @@ async fn test_write_scratch_to_new_path() -> anyhow::Result<()> {
133 let mut file = tempfile::NamedTempFile::new()?;
138 let mut file = tempfile::NamedTempFile::new()?;
135 test_key_sequence(
140 test_key_sequence(
136− &mut Application::new(Args::default(), Config::default())?,
141+ &mut AppBuilder::new().build()?,
137 Some(format!("ihello<esc>:w {}<ret>", file.path().to_string_lossy()).as_ref()),
142 Some(format!("ihello<esc>:w {}<ret>", file.path().to_string_lossy()).as_ref()),
138 Some(&|app| {
143 Some(&|app| {
139 assert!(!app.editor.is_err());
144 assert!(!app.editor.is_err());
@@ -174,19 +179,40 @@ async fn test_write_scratch_no_path_fails() -> anyhow::Result<()> {
183+async fn test_write_auto_format_fails_still_writes() -> anyhow::Result<()> {
184+ let mut file = tempfile::Builder::new().suffix(".rs").tempfile()?;
186+ let lang_conf = indoc! {r#"
189+ formatter = { command = "bash", args = [ "-c", "exit 1" ] }
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())))
198+ test_key_sequences(&mut app, vec![(Some(":w<ret>"), None)], false).await?;
201+ helpers::assert_file_has_content(file.as_file_mut(), "let foo = 0;\n")?;
177#[tokio::test]
206#[tokio::test]
178async fn test_write_new_path() -> anyhow::Result<()> {
207async fn test_write_new_path() -> anyhow::Result<()> {
179 let mut file1 = tempfile::NamedTempFile::new().unwrap();
208 let mut file1 = tempfile::NamedTempFile::new().unwrap();
180 let mut file2 = tempfile::NamedTempFile::new().unwrap();
209 let mut file2 = tempfile::NamedTempFile::new().unwrap();
210+ let mut app = helpers::AppBuilder::new()
211+ .with_file(file1.path(), None)
182 test_key_sequences(
214 test_key_sequences(
183− &mut Application::new(
215+ &mut app,
185− files: vec![(file1.path().to_path_buf(), Position::default())],
186− ..Default::default()
192 Some("ii can eat glass, it will not hurt me<ret><esc>:w<ret>"),
218 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<()> {
228 let file = helpers::new_readonly_tempfile()?;
254 let file = helpers::new_readonly_tempfile()?;
230 test_key_sequences(
256 test_key_sequences(
231− &mut Application::new(Args::default(), Config::default())?,
257+ &mut AppBuilder::new().build()?,