patch 9.1.1090: tests: test_terminwscroll_topline2 unreliable

Commit: 
https://github.com/vim/vim/commit/aae1bfbdb96ccbbf5314321849b5f384a3d7c6a0
Author: Christian Brabandt <c...@256bit.org>
Date:   Sun Feb 9 17:10:30 2025 +0100

    patch 9.1.1090: tests: test_terminwscroll_topline2 unreliable
    
    Problem:  tests: test_terminwscroll_topline2 unreliable
              (Yee Cheng Chin)
    Solution: instead of using term_wait() with a specific time, use
              terminal-api and to wait until the terminal is finished
    
    call a terminal callback function when finished printing, instead of
    using term_wait(), with a defined time, which caused timeouts on CI
    with the macos runners
    
    Unfortunately I couldn't figure out how to call the terminal-api on Windows,
    so skip the test on Windows. cmd.com echo didn's seem to work and
    neither did trying to use python, but perhaps it was just me fighting
    with the terminal quoting rules :shrug:
    
    related: #16599
    related: #16552
    
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/testdir/test_terminal2.vim b/src/testdir/test_terminal2.vim
index c6edea99a..5c4563ccf 100644
--- a/src/testdir/test_terminal2.vim
+++ b/src/testdir/test_terminal2.vim
@@ -290,11 +290,16 @@ func Test_termwinscroll_topline()
 endfunc
 
 func Test_termwinscroll_topline2()
+  " calling the terminal API doesn't work on Windows
+  CheckNotMSWindows
   let g:test_is_flaky = 1
+  let g:print_complete = 0
+  func! Tapi_print_complete(bufnum, arglist)
+    let g:print_complete = 1
+  endfunc
+
   set termwinscroll=50000 mouse=a
-  if !has('win32')
-    set shell=sh
-  endif
+  set shell=sh
   let norm_winid = win_getid()
   terminal
   call assert_equal(2, winnr('$'))
@@ -304,26 +309,26 @@ func Test_termwinscroll_topline2()
 
   let num1 = &termwinscroll / 1000 * 999
   call writefile(range(num1), 'Xtext', 'D')
-  if has('win32')
-    call term_sendkeys(buf, "type Xtext\<CR>")
-  else
-    call term_sendkeys(buf, "cat Xtext\<CR>")
-  endif
+  call term_sendkeys(buf, "cat Xtext\<CR>")
+  call term_sendkeys(buf, 'printf '' ]51;["call", "Tapi_print_complete", []] 
''' .. "\<cr>")
   let rows = term_getsize(buf)[0]
-  " It may take a while to finish on a slow system
-  call term_wait(buf, 2000 * g:run_nr)
-  " On MS-Windows there is an empty line, check both last line and above it.
+  let cnt = 0
+  while !g:print_complete && cnt <= 1000
+    " max number of runs
+    let cnt += 1
+    " sleep a bit, to give the the terminal some time to finish
+
+    " It may take a while to finish on a slow system
+    " so wait a bit and handle the callback
+    call term_wait(buf)
+  endwhile
   call WaitForAssert({-> assert_match(string(num1 - 1), term_getline(buf, rows 
- 1) .. '\|' .. term_getline(buf, rows - 2))})
   call feedkeys("\<C-W>N", 'xt')
   call feedkeys("i", 'xt')
 
   let num2 = &termwinscroll / 1000 * 8
   call writefile(range(num2), 'Xtext', 'D')
-  if has('win32')
-    call term_sendkeys(buf, "timeout /t 2 && type Xtext\<CR>")
-  else
-    call term_sendkeys(buf, "sleep 2; cat Xtext\<CR>")
-  endif
+  call term_sendkeys(buf, "sleep 2; cat Xtext\<CR>")
   let winrow = get(get(filter(getwininfo(), 'v:val.winid == norm_winid'), 0, 
{}), 'winrow', -1)
 
   call test_setmouse(winrow, 1)
@@ -342,6 +347,8 @@ func Test_termwinscroll_topline2()
 
   exe buf . 'bwipe!'
   set termwinscroll& mouse& sh&
+  delfunc Tapi_print_complete
+  unlet! g:print_complete
 endfunc
 
 " Resizing the terminal window caused an ml_get error.
diff --git a/src/version.c b/src/version.c
index 28234de1a..580f82a0b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1090,
 /**/
     1089,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1thAC6-00Gcjr-81%40256bit.org.

Raspunde prin e-mail lui