comparison src/testdir/test_terminal.vim @ 13462:568dcfac9daf v8.0.1605

patch 8.0.1605: terminal test is a bit flaky commit https://github.com/vim/vim/commit/012eb6629337fdf8afca78a24faa132e9b42e7b4 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Mar 13 17:55:27 2018 +0100 patch 8.0.1605: terminal test is a bit flaky Problem: Terminal test is a bit flaky. Solution: Check for the shell prompt. Use more lambda functions.
author Christian Brabandt <cb@256bit.org>
date Tue, 13 Mar 2018 18:00:06 +0100
parents 9f06f7aca74c
children d130044d4f1f
comparison
equal deleted inserted replaced
13461:da182163b61d 13462:568dcfac9daf
430 430
431 func Test_terminal_servername() 431 func Test_terminal_servername()
432 if !has('clientserver') 432 if !has('clientserver')
433 return 433 return
434 endif 434 endif
435 let g:buf = Run_shell_in_terminal({}) 435 let buf = Run_shell_in_terminal({})
436 " Wait for the shell to display a prompt 436 " Wait for the shell to display a prompt
437 call WaitFor('term_getline(g:buf, 1) != ""') 437 call WaitFor({-> term_getline(buf, 1) != ""})
438 if has('win32') 438 if has('win32')
439 call term_sendkeys(g:buf, "echo %VIM_SERVERNAME%\r") 439 call term_sendkeys(buf, "echo %VIM_SERVERNAME%\r")
440 else 440 else
441 call term_sendkeys(g:buf, "echo $VIM_SERVERNAME\r") 441 call term_sendkeys(buf, "echo $VIM_SERVERNAME\r")
442 endif 442 endif
443 call term_wait(g:buf) 443 call term_wait(buf)
444 call Stop_shell_in_terminal(g:buf) 444 call Stop_shell_in_terminal(buf)
445 call WaitFor('getline(2) == v:servername') 445 call WaitFor('getline(2) == v:servername')
446 call assert_equal(v:servername, getline(2)) 446 call assert_equal(v:servername, getline(2))
447 447
448 exe g:buf . 'bwipe' 448 exe buf . 'bwipe'
449 unlet g:buf 449 unlet buf
450 endfunc 450 endfunc
451 451
452 func Test_terminal_env() 452 func Test_terminal_env()
453 let g:buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}}) 453 let buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}})
454 " Wait for the shell to display a prompt 454 " Wait for the shell to display a prompt
455 call WaitFor('term_getline(g:buf, 1) != ""') 455 call WaitFor({-> term_getline(buf, 1) != ""})
456 if has('win32') 456 if has('win32')
457 call term_sendkeys(g:buf, "echo %TESTENV%\r") 457 call term_sendkeys(buf, "echo %TESTENV%\r")
458 else 458 else
459 call term_sendkeys(g:buf, "echo $TESTENV\r") 459 call term_sendkeys(buf, "echo $TESTENV\r")
460 endif 460 endif
461 call term_wait(g:buf) 461 call term_wait(buf)
462 call Stop_shell_in_terminal(g:buf) 462 call Stop_shell_in_terminal(buf)
463 call WaitFor('getline(2) == "correct"') 463 call WaitFor('getline(2) == "correct"')
464 call assert_equal('correct', getline(2)) 464 call assert_equal('correct', getline(2))
465 465
466 exe g:buf . 'bwipe' 466 exe buf . 'bwipe'
467 unlet g:buf
468 endfunc 467 endfunc
469 468
470 " must be last, we can't go back from GUI to terminal 469 " must be last, we can't go back from GUI to terminal
471 func Test_zz_terminal_in_gui() 470 func Test_zz_terminal_in_gui()
472 if !CanRunGui() 471 if !CanRunGui()
589 if has('win32') 588 if has('win32')
590 silent exe '!start cmd /c "echo look here > ' . pty . '"' 589 silent exe '!start cmd /c "echo look here > ' . pty . '"'
591 else 590 else
592 call system('echo "look here" > ' . pty) 591 call system('echo "look here" > ' . pty)
593 endif 592 endif
594 let g:buf = buf 593 call WaitFor({-> term_getline(buf, 1) =~ "look here"})
595 call WaitFor('term_getline(g:buf, 1) =~ "look here"')
596 594
597 call assert_match('look here', term_getline(buf, 1)) 595 call assert_match('look here', term_getline(buf, 1))
598 bwipe! 596 bwipe!
599 endfunc 597 endfunc
600 598
670 " don't use abcde, it's an existing command 668 " don't use abcde, it's an existing command
671 tmap 456 abxde 669 tmap 456 abxde
672 call assert_equal('456', maparg('123', 't')) 670 call assert_equal('456', maparg('123', 't'))
673 call assert_equal('abxde', maparg('456', 't')) 671 call assert_equal('abxde', maparg('456', 't'))
674 call feedkeys("123", 'tx') 672 call feedkeys("123", 'tx')
675 let g:buf = buf 673 call WaitFor({-> term_getline(buf, term_getcursor(buf)[0]) =~ 'abxde\|456'})
676 call WaitFor("term_getline(g:buf,term_getcursor(g:buf)[0]) =~ 'abxde\\|456'")
677 let lnum = term_getcursor(buf)[0] 674 let lnum = term_getcursor(buf)[0]
678 if a:remap 675 if a:remap
679 call assert_match('abxde', term_getline(buf, lnum)) 676 call assert_match('abxde', term_getline(buf, lnum))
680 else 677 else
681 call assert_match('456', term_getline(buf, lnum)) 678 call assert_match('456', term_getline(buf, lnum))
814 if !has('unix') 811 if !has('unix')
815 return 812 return
816 endif 813 endif
817 814
818 let buf = Run_shell_in_terminal({}) 815 let buf = Run_shell_in_terminal({})
819 call term_wait(buf) 816 call WaitFor({-> term_getline(buf, 1) != ""})
820 817
821 new 818 call writefile(["\x1b[6n"], 'Xescape')
822 call setline(1, "\x1b[6n")
823 write! Xescape
824 bwipe
825 call term_sendkeys(buf, "cat Xescape\<cr>") 819 call term_sendkeys(buf, "cat Xescape\<cr>")
826 820
827 " wait for the response of control sequence from libvterm (and send it to tty) 821 " wait for the response of control sequence from libvterm (and send it to tty)
828 sleep 200m 822 sleep 200m
829 call term_wait(buf) 823 call term_wait(buf)
907 901
908 " close the terminal window where Vim was running 902 " close the terminal window where Vim was running
909 quit 903 quit
910 endfunc 904 endfunc
911 905
912 func Test_terminalopen_autocmd() 906 func Test_terminal_open_autocmd()
913 augroup repro 907 augroup repro
914 au! 908 au!
915 au TerminalOpen * let s:called += 1 909 au TerminalOpen * let s:called += 1
916 augroup END 910 augroup END
917 911