Skip to content

Commit

Permalink
add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed Apr 11, 2024
1 parent 6e0b4d3 commit 0adc9a8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
38 changes: 38 additions & 0 deletions helix-term/tests/test/commands/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,44 @@ async fn test_write_all_insert_final_newline_do_not_add_if_unmodified() -> anyho
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn test_symlink_write() -> anyhow::Result<()> {
#[cfg(unix)]
use std::os::unix::fs::symlink;
#[cfg(not(unix))]
use std::os::windows::fs::symlink_file as symlink;

let dir = tempfile::tempdir()?;

let mut file = tempfile::NamedTempFile::new_in(&dir)?;
let symlink_path = dir.path().join("linked");
symlink(file.path(), &symlink_path)?;

let mut app = helpers::AppBuilder::new()
.with_file(&symlink_path, None)
.build()?;

test_key_sequence(
&mut app,
Some("ithe gostak distims the doshes<ret><esc>:w<ret>"),
None,
false,
)
.await?;

reload_file(&mut file).unwrap();
let mut file_content = String::new();
file.as_file_mut().read_to_string(&mut file_content)?;

assert_eq!(
LineFeedHandling::Native.apply("the gostak distims the doshes"),
file_content
);
assert!(symlink_path.is_symlink());

Ok(())
}

async fn edit_file_with_content(file_content: &[u8]) -> anyhow::Result<()> {
let mut file = tempfile::NamedTempFile::new()?;

Expand Down
4 changes: 3 additions & 1 deletion helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,9 @@ impl Document {
"Path is read only"
));
}
let write_path = tokio::fs::read_link(&path).await.unwrap_or_else(|_| path.clone());
let write_path = tokio::fs::read_link(&path)
.await
.unwrap_or_else(|_| path.clone());
let backup = if path.exists() {
let path_ = write_path.clone();
// hacks: we use tempfile to handle the complex task of creating
Expand Down

0 comments on commit 0adc9a8

Please sign in to comment.