@@ -1,5 +1,5 @@
2− io::{Read, Seek, SeekFrom, Write},
2+ io::{Read, Seek, Write},
3 ops::RangeInclusive,
3 ops::RangeInclusive,
@@ -8,6 +8,96 @@ use helix_view::doc;
9use super::*;
9use super::*;
11+#[tokio::test(flavor = "multi_thread")]
12+async fn test_write_quit_fail() -> anyhow::Result<()> {
13+ let file = helpers::new_readonly_tempfile()?;
14+ let mut app = helpers::AppBuilder::new()
15+ .with_file(file.path(), None)
20+ Some("ihello<esc>:wq<ret>"),
22+ let mut docs: Vec<_> = app.editor.documents().collect();
23+ assert_eq!(1, docs.len());
25+ let doc = docs.pop().unwrap();
26+ assert_eq!(Some(file.path()), doc.path().map(PathBuf::as_path));
27+ assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
36+#[tokio::test(flavor = "multi_thread")]
37+async fn test_buffer_close_concurrent() -> anyhow::Result<()> {
39+ &mut helpers::AppBuilder::new().build()?,
44+ assert_eq!(1, app.editor.documents().count());
45+ assert!(!app.editor.is_err());
49+ Some("ihello<esc>:new<ret>"),
51+ assert_eq!(2, app.editor.documents().count());
52+ assert!(!app.editor.is_err());
56+ Some(":buffer<minus>close<ret>"),
58+ assert_eq!(1, app.editor.documents().count());
59+ assert!(!app.editor.is_err());
67+ // verify if writes are queued up, it finishes them before closing the buffer
68+ let mut file = tempfile::NamedTempFile::new()?;
69+ let mut command = String::new();
70+ const RANGE: RangeInclusive<i32> = 1..=1000;
73+ let cmd = format!("%c{}<esc>:w!<ret>", i);
74+ command.push_str(&cmd);
77+ command.push_str(":buffer<minus>close<ret>");
79+ let mut app = helpers::AppBuilder::new()
80+ .with_file(file.path(), None)
87+ assert!(!app.editor.is_err(), "error: {:?}", app.editor.get_status());
89+ let doc = app.editor.document_by_path(file.path());
90+ assert!(doc.is_none(), "found doc: {:?}", doc);
96+ helpers::assert_file_has_content(file.as_file_mut(), &RANGE.end().to_string())?;
11#[tokio::test(flavor = "multi_thread")]
101#[tokio::test(flavor = "multi_thread")]
12async fn test_write() -> anyhow::Result<()> {
102async fn test_write() -> anyhow::Result<()> {
13 let mut file = tempfile::NamedTempFile::new()?;
103 let mut file = tempfile::NamedTempFile::new()?;
@@ -57,7 +147,7 @@ async fn test_overwrite_protection() -> anyhow::Result<()> {
57 file.as_file_mut().flush()?;
147 file.as_file_mut().flush()?;
58 file.as_file_mut().sync_all()?;
148 file.as_file_mut().sync_all()?;
60− file.seek(SeekFrom::Start(0))?;
150+ file.rewind()?;
61 let mut file_content = String::new();
151 let mut file_content = String::new();
62 file.as_file_mut().read_to_string(&mut file_content)?;
152 file.as_file_mut().read_to_string(&mut file_content)?;