From 109fd55a479d75707df9d4f7d5a8ca6cc5890e9b Mon Sep 17 00:00:00 2001 From: Ibrahim Dursun Date: Tue, 4 Oct 2022 15:30:58 +0100 Subject: [PATCH] Add integration test --- helix-term/tests/test/commands.rs | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index f7ce9af081710..699e90c289c3b 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -25,6 +25,38 @@ async fn test_write_quit_fail() -> anyhow::Result<()> { Ok(()) } +#[tokio::test] +async fn test_read_file() -> anyhow::Result<()> { + let mut file = tempfile::NamedTempFile::new()?; + let expected_content = String::from("some contents"); + let output_file = helpers::temp_file_with_contents(&expected_content)?; + let mut command = String::new(); + let cmd = format!( + ":r {:?}:w", + std::fs::canonicalize(output_file.path()).unwrap() + ); + command.push_str(&cmd); + + test_key_sequence( + &mut helpers::app_with_file(file.path())?, + Some(&command), + Some(&|app| { + assert!(!app.editor.is_err(), "error: {:?}", app.editor.get_status()); + }), + false, + ) + .await?; + + file.as_file_mut().flush()?; + file.as_file_mut().sync_all()?; + + let mut file_content = String::new(); + file.as_file_mut().read_to_string(&mut file_content)?; + assert_eq!(expected_content, file_content); + + Ok(()) +} + #[tokio::test] #[ignore] async fn test_buffer_close_concurrent() -> anyhow::Result<()> {