@@ -632,6 +632,39 @@ func Test_term_getcursor()
632632 call StopShellInTerminal (buf )
633633endfunc
634634
635+ func ! s: TermPollAndAssertMatchTitle (term , old_name, new_pattern) abort
636+ let new_name = ' '
637+ let next_part = ' '
638+ let prev_part = next_part
639+ let times = 2048
640+
641+ " Ignore any pending or old title (or its tail part).
642+ while (empty (new_name) ||
643+ \ a: old_name [max ([0 , strridx (a: old_name , new_name)]) :] == # new_name) &&
644+ \ times > 0
645+ let new_name = term_gettitle (a: term )
646+ let times -= 1
647+ sleep 1 m
648+ endwhile
649+
650+ " FIXME: Allow for occasional title "buffering" (on MacOS) and fetch either
651+ " the whole title or its parts.
652+ while new_name !~# a: new_pattern && times > 0
653+ let next_part = term_gettitle (a: term )
654+
655+ if next_part !=# prev_part
656+ let new_name .= next_part
657+ endif
658+
659+ let prev_part = next_part
660+ let times -= 1
661+ sleep 1 m
662+ endwhile
663+
664+ call assert_match (a: new_pattern , new_name)
665+ return new_name
666+ endfunc
667+
635668" Test for term_gettitle()
636669" Known to be flaky on Mac-OS X and the GH runners
637670func Test_term_gettitle ()
@@ -643,24 +676,16 @@ func Test_term_gettitle()
643676 if ! has (' title' ) || empty (&t_ts )
644677 throw " Skipped: can't get/set title"
645678 endif
646- if has (' osx' ) && ! empty ($CI ) && system (' uname -m' ) = ~# ' arm64'
647- " This test often fails with the following error message on Github runners
648- " MacOS-14
649- " '^\\[No Name\\] - VIM\\d*$' does not match 'e] - VIM'
650- " Why? Is the terminal that runs Vim too small?
651- throw ' Skipped: FIXME: Running this test on M1 Mac fails on GitHub Actions'
652- endif
653679
654680 let term = term_start ([GetVimProg (), ' --clean' , ' -c' , ' set noswapfile' , ' -c' , ' set title' ])
655681 call TermWait (term )
656682 " When Vim is running as a server then the title ends in VIM{number}, thus
657683 " optionally match a number after "VIM".
658- call WaitForAssert ({ - > assert_match ( ' ^\[No Name\] - VIM\d*$' , term_gettitle ( term )) } )
684+ let title = s: TermPollAndAssertMatchTitle ( term , ' ' , ' ^\[No Name\] - VIM\d*$' )
659685 call term_sendkeys (term , " :e Xfoo\r " )
660- call WaitForAssert ({- > assert_match (' ^Xfoo (.*[/\\]testdir) - VIM\d*$' , term_gettitle (term )) })
661-
686+ let title = s: TermPollAndAssertMatchTitle (term , title , ' ^Xfoo (.*[/\\]testdir) - VIM\d*$' )
662687 call term_sendkeys (term , " :set titlestring=foo\r " )
663- call WaitForAssert ({ - > assert_equal ( ' foo ' , term_gettitle (term )) } )
688+ let title = s: TermPollAndAssertMatchTitle (term , title , ' foo ' )
664689
665690 exe term . ' bwipe!'
666691endfunc
0 commit comments