@@ -36,17 +36,15 @@ pub async fn test_key_sequence(
36 app: &mut Application,
36 app: &mut Application,
37 in_keys: Option<&str>,
37 in_keys: Option<&str>,
38 test_fn: Option<&dyn Fn(&Application)>,
38 test_fn: Option<&dyn Fn(&Application)>,
39− timeout: Option<Duration>,
40) -> anyhow::Result<()> {
39) -> anyhow::Result<()> {
41− test_key_sequences(app, vec![(in_keys, test_fn)], timeout).await
40+ test_key_sequences(app, vec![(in_keys, test_fn)]).await
44pub async fn test_key_sequences(
43pub async fn test_key_sequences(
45 app: &mut Application,
44 app: &mut Application,
46 inputs: Vec<(Option<&str>, Option<&dyn Fn(&Application)>)>,
45 inputs: Vec<(Option<&str>, Option<&dyn Fn(&Application)>)>,
47− timeout: Option<Duration>,
48) -> anyhow::Result<()> {
46) -> anyhow::Result<()> {
49− let timeout = timeout.unwrap_or(Duration::from_millis(500));
47+ const TIMEOUT: Duration = Duration::from_millis(500);
50 let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
48 let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
51 let mut rx_stream = UnboundedReceiverStream::new(rx);
49 let mut rx_stream = UnboundedReceiverStream::new(rx);
@@ -57,10 +55,7 @@ pub async fn test_key_sequences(
60− let event_loop = app.event_loop(&mut rx_stream);
58+ if !app.event_loop_until_idle(&mut rx_stream).await {
61− let result = tokio::time::timeout(timeout, event_loop).await;
64 bail!("application exited before test function could run");
59 bail!("application exited before test function could run");
@@ -74,7 +69,7 @@ pub async fn test_key_sequences(
76 let event_loop = app.event_loop(&mut rx_stream);
71 let event_loop = app.event_loop(&mut rx_stream);
77− tokio::time::timeout(timeout, event_loop).await?;
72+ tokio::time::timeout(TIMEOUT, event_loop).await?;
78 app.close().await?;
73 app.close().await?;
@@ -84,7 +79,6 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>(
84 app: Option<Application>,
79 app: Option<Application>,
85 test_case: T,
80 test_case: T,
86 test_fn: &dyn Fn(&Application),
81 test_fn: &dyn Fn(&Application),
87− timeout: Option<Duration>,
88) -> anyhow::Result<()> {
82) -> anyhow::Result<()> {
89 let test_case = test_case.into();
83 let test_case = test_case.into();
90 let mut app =
84 let mut app =
@@ -102,7 +96,7 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>(
105− test_key_sequence(&mut app, Some(&test_case.in_keys), Some(test_fn), timeout).await
99+ test_key_sequence(&mut app, Some(&test_case.in_keys), Some(test_fn)).await
108/// Use this for very simple test cases where there is one input
102/// 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>>(
112 args: Args,
106 args: Args,
113 config: Config,
107 config: Config,
114 test_case: T,
108 test_case: T,
115− timeout: Option<Duration>,
116) -> anyhow::Result<()> {
109) -> anyhow::Result<()> {
117 let test_case = test_case.into();
110 let test_case = test_case.into();
118 let app = Application::new(args, config).unwrap();
111 let app = Application::new(args, config).unwrap();
120− test_key_sequence_with_input_text(
113+ test_key_sequence_with_input_text(Some(app), test_case.clone(), &|app| {
124− let doc = doc!(app.editor);
114+ let doc = doc!(app.editor);
125− assert_eq!(&test_case.out_text, doc.text());
115+ assert_eq!(&test_case.out_text, doc.text());
127− let mut selections: Vec<_> = doc.selections().values().cloned().collect();
117+ let mut selections: Vec<_> = doc.selections().values().cloned().collect();
128− assert_eq!(1, selections.len());
118+ assert_eq!(1, selections.len());
130− let sel = selections.pop().unwrap();
120+ let sel = selections.pop().unwrap();
131− assert_eq!(test_case.out_selection, sel);
121+ assert_eq!(test_case.out_selection, sel);