diff options
author | Skyler Hawthorne | 2022-04-24 01:49:31 +0000 |
---|---|---|
committer | Skyler Hawthorne | 2022-06-19 03:54:03 +0000 |
commit | 2386c81ebc118860107094591b76ef3864e120a8 (patch) | |
tree | eac56099ade96e0722ac13d92197f27db14c65b9 /helix-term/tests | |
parent | 40120967e9ba48d2e8b5fb4976a6ca1ce8993704 (diff) |
use idle timer instead of fixed timeout
Diffstat (limited to 'helix-term/tests')
-rw-r--r-- | helix-term/tests/integration.rs | 1 | ||||
-rw-r--r-- | helix-term/tests/integration/auto_indent.rs | 1 | ||||
-rw-r--r-- | helix-term/tests/integration/auto_pairs.rs | 2 | ||||
-rw-r--r-- | helix-term/tests/integration/commands.rs | 4 | ||||
-rw-r--r-- | helix-term/tests/integration/helpers.rs | 42 | ||||
-rw-r--r-- | helix-term/tests/integration/movement.rs | 8 | ||||
-rw-r--r-- | helix-term/tests/integration/write.rs | 5 |
7 files changed, 15 insertions, 48 deletions
diff --git a/helix-term/tests/integration.rs b/helix-term/tests/integration.rs index 54364e12..061bd8ff 100644 --- a/helix-term/tests/integration.rs +++ b/helix-term/tests/integration.rs @@ -17,7 +17,6 @@ mod integration { Args::default(), Config::default(), ("#[\n|]#", "ihello world<esc>", "hello world#[|\n]#"), - None, ) .await?; diff --git a/helix-term/tests/integration/auto_indent.rs b/helix-term/tests/integration/auto_indent.rs index fdfc7dfb..74d1ac58 100644 --- a/helix-term/tests/integration/auto_indent.rs +++ b/helix-term/tests/integration/auto_indent.rs @@ -18,7 +18,6 @@ async fn auto_indent_c() -> anyhow::Result<()> { } "}, ), - None, ) .await?; diff --git a/helix-term/tests/integration/auto_pairs.rs b/helix-term/tests/integration/auto_pairs.rs index d34cd0fd..52fee55e 100644 --- a/helix-term/tests/integration/auto_pairs.rs +++ b/helix-term/tests/integration/auto_pairs.rs @@ -6,7 +6,6 @@ async fn auto_pairs_basic() -> anyhow::Result<()> { Args::default(), Config::default(), ("#[\n|]#", "i(<esc>", "(#[|)]#\n"), - None, ) .await?; @@ -20,7 +19,6 @@ async fn auto_pairs_basic() -> anyhow::Result<()> { ..Default::default() }, ("#[\n|]#", "i(<esc>", "(#[|\n]#"), - None, ) .await?; diff --git a/helix-term/tests/integration/commands.rs b/helix-term/tests/integration/commands.rs index 7da180b9..4ab87b9b 100644 --- a/helix-term/tests/integration/commands.rs +++ b/helix-term/tests/integration/commands.rs @@ -1,7 +1,6 @@ use std::{ io::{Read, Write}, ops::RangeInclusive, - time::Duration, }; use helix_core::diagnostic::Severity; @@ -23,7 +22,6 @@ async fn test_write_quit_fail() -> anyhow::Result<()> { Some(&|app| { assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1); }), - None, ) .await?; @@ -57,7 +55,6 @@ async fn test_buffer_close() -> anyhow::Result<()> { }), ), ], - None, ) .await?; @@ -88,7 +85,6 @@ async fn test_buffer_close() -> anyhow::Result<()> { let doc = app.editor.document_by_path(file.path()); assert!(doc.is_none(), "found doc: {:?}", doc); }), - Some(Duration::from_millis(5000)), ) .await?; diff --git a/helix-term/tests/integration/helpers.rs b/helix-term/tests/integration/helpers.rs index 18a3517c..29cb8cd8 100644 --- a/helix-term/tests/integration/helpers.rs +++ b/helix-term/tests/integration/helpers.rs @@ -36,17 +36,15 @@ pub async fn test_key_sequence( app: &mut Application, in_keys: Option<&str>, test_fn: Option<&dyn Fn(&Application)>, - timeout: Option<Duration>, ) -> anyhow::Result<()> { - test_key_sequences(app, vec![(in_keys, test_fn)], timeout).await + test_key_sequences(app, vec![(in_keys, test_fn)]).await } pub async fn test_key_sequences( app: &mut Application, inputs: Vec<(Option<&str>, Option<&dyn Fn(&Application)>)>, - timeout: Option<Duration>, ) -> anyhow::Result<()> { - let timeout = timeout.unwrap_or(Duration::from_millis(500)); + const TIMEOUT: Duration = Duration::from_millis(500); let (tx, rx) = tokio::sync::mpsc::unbounded_channel(); let mut rx_stream = UnboundedReceiverStream::new(rx); @@ -57,10 +55,7 @@ pub async fn test_key_sequences( } } - let event_loop = app.event_loop(&mut rx_stream); - let result = tokio::time::timeout(timeout, event_loop).await; - - if result.is_ok() { + if !app.event_loop_until_idle(&mut rx_stream).await { bail!("application exited before test function could run"); } @@ -74,7 +69,7 @@ pub async fn test_key_sequences( } let event_loop = app.event_loop(&mut rx_stream); - tokio::time::timeout(timeout, event_loop).await?; + tokio::time::timeout(TIMEOUT, event_loop).await?; app.close().await?; Ok(()) @@ -84,7 +79,6 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>( app: Option<Application>, test_case: T, test_fn: &dyn Fn(&Application), - timeout: Option<Duration>, ) -> anyhow::Result<()> { let test_case = test_case.into(); let mut app = @@ -102,7 +96,7 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>( view.id, ); - test_key_sequence(&mut app, Some(&test_case.in_keys), Some(test_fn), timeout).await + test_key_sequence(&mut app, Some(&test_case.in_keys), Some(test_fn)).await } /// Use this for very simple test cases where there is one input @@ -112,26 +106,20 @@ pub async fn test_key_sequence_text_result<T: Into<TestCase>>( args: Args, config: Config, test_case: T, - timeout: Option<Duration>, ) -> anyhow::Result<()> { let test_case = test_case.into(); let app = Application::new(args, config).unwrap(); - test_key_sequence_with_input_text( - Some(app), - test_case.clone(), - &|app| { - let doc = doc!(app.editor); - assert_eq!(&test_case.out_text, doc.text()); - - let mut selections: Vec<_> = doc.selections().values().cloned().collect(); - assert_eq!(1, selections.len()); - - let sel = selections.pop().unwrap(); - assert_eq!(test_case.out_selection, sel); - }, - timeout, - ) + test_key_sequence_with_input_text(Some(app), test_case.clone(), &|app| { + let doc = doc!(app.editor); + assert_eq!(&test_case.out_text, doc.text()); + + let mut selections: Vec<_> = doc.selections().values().cloned().collect(); + assert_eq!(1, selections.len()); + + let sel = selections.pop().unwrap(); + assert_eq!(test_case.out_selection, sel); + }) .await } diff --git a/helix-term/tests/integration/movement.rs b/helix-term/tests/integration/movement.rs index a1d294c6..cac10852 100644 --- a/helix-term/tests/integration/movement.rs +++ b/helix-term/tests/integration/movement.rs @@ -14,7 +14,6 @@ async fn insert_mode_cursor_position() -> anyhow::Result<()> { out_text: String::new(), out_selection: Selection::single(0, 0), }, - None, ) .await?; @@ -22,7 +21,6 @@ async fn insert_mode_cursor_position() -> anyhow::Result<()> { Args::default(), Config::default(), ("#[\n|]#", "i", "#[|\n]#"), - None, ) .await?; @@ -30,7 +28,6 @@ async fn insert_mode_cursor_position() -> anyhow::Result<()> { Args::default(), Config::default(), ("#[\n|]#", "i<esc>", "#[|\n]#"), - None, ) .await?; @@ -38,7 +35,6 @@ async fn insert_mode_cursor_position() -> anyhow::Result<()> { Args::default(), Config::default(), ("#[\n|]#", "i<esc>i", "#[|\n]#"), - None, ) .await?; @@ -52,7 +48,6 @@ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> { Args::default(), Config::default(), ("#[f|]#oo\n", "vll<A-;><esc>", "#[|foo]#\n"), - None, ) .await?; @@ -70,7 +65,6 @@ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> { #(|bar)#" }, ), - None, ) .await?; @@ -88,7 +82,6 @@ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> { #(ba|)#r" }, ), - None, ) .await?; @@ -106,7 +99,6 @@ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> { #(b|)#ar" }, ), - None, ) .await?; diff --git a/helix-term/tests/integration/write.rs b/helix-term/tests/integration/write.rs index 365e6b8d..0cc41dbc 100644 --- a/helix-term/tests/integration/write.rs +++ b/helix-term/tests/integration/write.rs @@ -1,7 +1,6 @@ use std::{ io::{Read, Write}, ops::RangeInclusive, - time::Duration, }; use helix_core::diagnostic::Severity; @@ -24,7 +23,6 @@ async fn test_write() -> anyhow::Result<()> { )?, Some("ii can eat glass, it will not hurt me<ret><esc>:w<ret>"), None, - Some(Duration::from_millis(1000)), ) .await?; @@ -59,7 +57,6 @@ async fn test_write_concurrent() -> anyhow::Result<()> { )?, Some(&command), None, - Some(Duration::from_millis(10000)), ) .await?; @@ -108,7 +105,6 @@ async fn test_write_fail_mod_flag() -> anyhow::Result<()> { }), ), ], - None, ) .await?; @@ -138,7 +134,6 @@ async fn test_write_fail_new_path() -> anyhow::Result<()> { }), ), ], - Some(Duration::from_millis(1000)), ) .await?; |