aboutsummaryrefslogtreecommitdiff
path: root/helix-term/tests/integration/helpers.rs
diff options
context:
space:
mode:
authorSkyler Hawthorne2022-04-30 04:35:00 +0000
committerSkyler Hawthorne2022-06-19 03:57:47 +0000
commitacf931709a56e5af0ac101276fcfb3ba45f159f2 (patch)
tree5782cd8e5d4f2891c18c8e1039e2c5dc04851c76 /helix-term/tests/integration/helpers.rs
parentef8fe5a5ce536c65f34e479db79b94c8435aa3b2 (diff)
use a read only file to ensure write failure
Diffstat (limited to 'helix-term/tests/integration/helpers.rs')
-rw-r--r--helix-term/tests/integration/helpers.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/helix-term/tests/integration/helpers.rs b/helix-term/tests/integration/helpers.rs
index 706e1afb..3fe1934f 100644
--- a/helix-term/tests/integration/helpers.rs
+++ b/helix-term/tests/integration/helpers.rs
@@ -5,6 +5,7 @@ use crossterm::event::{Event, KeyEvent};
use helix_core::{test, Selection, Transaction};
use helix_term::{application::Application, args::Args, config::Config};
use helix_view::{doc, input::parse_macro};
+use tempfile::NamedTempFile;
use tokio_stream::wrappers::UnboundedReceiverStream;
#[derive(Clone, Debug)]
@@ -155,3 +156,14 @@ pub fn platform_line(input: &str) -> String {
output
}
+
+/// Creates a new temporary file that is set to read only. Useful for
+/// testing write failures.
+pub fn new_readonly_tempfile() -> anyhow::Result<NamedTempFile> {
+ let mut file = tempfile::NamedTempFile::new()?;
+ let metadata = file.as_file().metadata()?;
+ let mut perms = metadata.permissions();
+ perms.set_readonly(true);
+ file.as_file_mut().set_permissions(perms)?;
+ Ok(file)
+}