diff src/testdir/test_terminal3.vim @ 31037:ac16c9a934ad v9.0.0853

patch 9.0.0853: terminal mouse test is still flaky on MacOS M1 Commit: https://github.com/vim/vim/commit/98aebcc2c6f4b131d2098ebc60c4a552a5163aec Author: Bram Moolenaar <Bram@vim.org> Date: Thu Nov 10 12:38:16 2022 +0000 patch 9.0.0853: terminal mouse test is still flaky on MacOS M1 Problem: Terminal mouse test is still flaky on MacOS M1. Solution: Also wait for the file to have some contents.
author Bram Moolenaar <Bram@vim.org>
date Thu, 10 Nov 2022 13:45:08 +0100
parents 3ad8db9a1e03
children 8f15c56ff2fb
line wrap: on
line diff
--- a/src/testdir/test_terminal3.vim
+++ b/src/testdir/test_terminal3.vim
@@ -686,7 +686,10 @@ func Test_term_mouse()
   call TermWait(buf)
   redraw!
 
-  let XbufExists = {-> filereadable('Xbuf')}
+  " Funcref used in WaitFor() to check that the "Xbuf" file is readable and
+  " has some contents.  This avoids a "List index out of range" error when the
+  " file hasn't been written yet.
+  let XbufNotEmpty = {-> filereadable('Xbuf') && len(readfile('Xbuf')) > 0}
 
   " Use the mouse to enter the terminal window
   call win_gotoid(prev_win)
@@ -703,7 +706,7 @@ func Test_term_mouse()
   call delete('Xbuf')
   call term_sendkeys(buf, ":call writefile([json_encode(getpos('.'))], 'Xbuf')\<CR>")
   call TermWait(buf, 50)
-  call WaitFor(XbufExists)
+  call WaitFor(XbufNotEmpty)
   let pos = json_decode(readfile('Xbuf')[0])
   call assert_equal([3, 8], pos[1:2])
   call delete('Xbuf')
@@ -715,7 +718,7 @@ func Test_term_mouse()
   call term_sendkeys(buf, "\<LeftRelease>y")
   call TermWait(buf, 50)
   call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
-  call WaitFor(XbufExists)
+  call WaitFor(XbufNotEmpty)
   call WaitForAssert({-> assert_equal('yellow', readfile('Xbuf')[0])})
   call delete('Xbuf')
 
@@ -726,7 +729,7 @@ func Test_term_mouse()
   call term_sendkeys(buf, "\<LeftRelease>y")
   call TermWait(buf, 50)
   call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
-  call WaitFor(XbufExists)
+  call WaitFor(XbufNotEmpty)
   call assert_equal('three four', readfile('Xbuf')[0])
   call delete('Xbuf')
 
@@ -735,7 +738,7 @@ func Test_term_mouse()
   call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>y")
   call TermWait(buf, 50)
   call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
-  call WaitFor(XbufExists)
+  call WaitFor(XbufNotEmpty)
   call assert_equal("vim emacs sublime nano\n", readfile('Xbuf')[0])
   call delete('Xbuf')
 
@@ -746,7 +749,7 @@ func Test_term_mouse()
   call term_sendkeys(buf, "\<LeftRelease>y")
   call TermWait(buf, 50)
   call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
-  call WaitFor(XbufExists)
+  call WaitFor(XbufNotEmpty)
   call assert_equal("ree\nyel\nsub", readfile('Xbuf')[0])
   call delete('Xbuf')
 
@@ -757,7 +760,7 @@ func Test_term_mouse()
   call term_sendkeys(buf, "\<RightMouse>\<RightRelease>y")
   call TermWait(buf, 50)
   call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
-  call WaitFor(XbufExists)
+  call WaitFor(XbufNotEmpty)
   call assert_equal("n yellow", readfile('Xbuf')[0])
   call delete('Xbuf')
 
@@ -767,7 +770,7 @@ func Test_term_mouse()
   call term_sendkeys(buf, "\"r\<MiddleMouse>\<MiddleRelease>")
   call TermWait(buf, 50)
   call term_sendkeys(buf, ":call writefile([getline(2)], 'Xbuf')\<CR>")
-  call WaitFor(XbufExists)
+  call WaitFor(XbufNotEmpty)
   call assert_equal("red bright blue", readfile('Xbuf')[0][-15:])
   call delete('Xbuf')