Mercurial > vim
comparison src/testdir/test_search.vim @ 12763:7f27e9769f62 v8.0.1259
patch 8.0.1259: search test can be flaky
commit https://github.com/vim/vim/commit/13deab8d08145c1f6e2a3e82cb547bc7f87a3686
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Nov 4 18:48:43 2017 +0100
patch 8.0.1259: search test can be flaky
Problem: Search test can be flaky.
Solution: Use WaitFor() instead of a delay. Make it possible to pass a
funcref to WaitFor() to avoid the need for global variables.
(James McCoy, closes #2282)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 04 Nov 2017 19:00:05 +0100 |
parents | 528b227051f8 |
children | cb9b2774f21f |
comparison
equal
deleted
inserted
replaced
12762:50fd18c60c3d | 12763:7f27e9769f62 |
---|---|
480 return | 480 return |
481 endif | 481 endif |
482 " Prepare buffer text | 482 " Prepare buffer text |
483 let lines = ['abb vim vim vi', 'vimvivim'] | 483 let lines = ['abb vim vim vi', 'vimvivim'] |
484 call writefile(lines, 'Xsearch.txt') | 484 call writefile(lines, 'Xsearch.txt') |
485 let g:buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) | 485 let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) |
486 | 486 |
487 call term_wait(g:buf, 200) | 487 call WaitFor({-> lines == [term_getline(buf, 1), term_getline(buf, 2)] }) |
488 call assert_equal(lines[0], term_getline(g:buf, 1)) | 488 |
489 call assert_equal(lines[1], term_getline(g:buf, 2)) | 489 call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") |
490 | 490 call term_sendkeys(buf, ":14vsp\<cr>") |
491 call term_sendkeys(g:buf, ":set incsearch hlsearch\<cr>") | 491 call term_sendkeys(buf, "/vim\<cr>") |
492 call term_sendkeys(g:buf, ":14vsp\<cr>") | 492 call term_sendkeys(buf, "/b\<esc>") |
493 call term_sendkeys(g:buf, "/vim\<cr>") | 493 call term_sendkeys(buf, "gg0") |
494 call term_sendkeys(g:buf, "/b\<esc>") | 494 call term_wait(buf, 500) |
495 call term_sendkeys(g:buf, "gg0") | 495 let screen_line = term_scrape(buf, 1) |
496 call term_wait(g:buf, 500) | |
497 let screen_line = term_scrape(g:buf, 1) | |
498 let [a0,a1,a2,a3] = [screen_line[3].attr, screen_line[4].attr, | 496 let [a0,a1,a2,a3] = [screen_line[3].attr, screen_line[4].attr, |
499 \ screen_line[18].attr, screen_line[19].attr] | 497 \ screen_line[18].attr, screen_line[19].attr] |
500 call assert_notequal(a0, a1) | 498 call assert_notequal(a0, a1) |
501 call assert_notequal(a0, a3) | 499 call assert_notequal(a0, a3) |
502 call assert_notequal(a1, a2) | 500 call assert_notequal(a1, a2) |
605 if h < 3 | 603 if h < 3 |
606 return | 604 return |
607 endif | 605 endif |
608 | 606 |
609 " Prepare buffer text | 607 " Prepare buffer text |
610 let g:lines = ['abb vim vim vi', 'vimvivim'] | 608 let lines = ['abb vim vim vi', 'vimvivim'] |
611 call writefile(g:lines, 'Xsearch.txt') | 609 call writefile(lines, 'Xsearch.txt') |
612 let g:buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) | 610 let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) |
613 call WaitFor('g:lines[0] == term_getline(g:buf, 1)') | 611 |
614 call assert_equal(g:lines[0], term_getline(g:buf, 1)) | 612 call WaitFor({-> lines == [term_getline(buf, 1), term_getline(buf, 2)] }) |
615 call assert_equal(g:lines[1], term_getline(g:buf, 2)) | |
616 unlet g:lines | |
617 | 613 |
618 " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight | 614 " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight |
619 call term_sendkeys(g:buf, ":set incsearch hlsearch\<cr>") | 615 call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") |
620 call term_sendkeys(g:buf, '/b') | 616 call term_sendkeys(buf, '/b') |
621 call term_wait(g:buf, 200) | 617 call term_wait(buf, 200) |
622 let screen_line1 = term_scrape(g:buf, 1) | 618 let screen_line1 = term_scrape(buf, 1) |
623 call assert_true(len(screen_line1) > 2) | 619 call assert_true(len(screen_line1) > 2) |
624 " a0: attr_normal | 620 " a0: attr_normal |
625 let a0 = screen_line1[0].attr | 621 let a0 = screen_line1[0].attr |
626 " a1: attr_incsearch | 622 " a1: attr_incsearch |
627 let a1 = screen_line1[1].attr | 623 let a1 = screen_line1[1].attr |
628 " a2: attr_hlsearch | 624 " a2: attr_hlsearch |
629 let a2 = screen_line1[2].attr | 625 let a2 = screen_line1[2].attr |
630 call assert_notequal(a0, a1) | 626 call assert_notequal(a0, a1) |
631 call assert_notequal(a0, a2) | 627 call assert_notequal(a0, a2) |
632 call assert_notequal(a1, a2) | 628 call assert_notequal(a1, a2) |
633 call term_sendkeys(g:buf, "\<cr>gg0") | 629 call term_sendkeys(buf, "\<cr>gg0") |
634 | 630 |
635 " Test incremental highlight search | 631 " Test incremental highlight search |
636 call term_sendkeys(g:buf, "/vim") | 632 call term_sendkeys(buf, "/vim") |
637 call term_wait(g:buf, 200) | 633 call term_wait(buf, 200) |
638 " Buffer: | 634 " Buffer: |
639 " abb vim vim vi | 635 " abb vim vim vi |
640 " vimvivim | 636 " vimvivim |
641 " Search: /vim | 637 " Search: /vim |
642 let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a2,a2,a2,a0,a0,a0] | 638 let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a2,a2,a2,a0,a0,a0] |
643 let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] | 639 let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
644 call assert_equal(attr_line1, map(term_scrape(g:buf, 1)[:len(attr_line1)-1], 'v:val.attr')) | 640 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
645 call assert_equal(attr_line2, map(term_scrape(g:buf, 2)[:len(attr_line2)-1], 'v:val.attr')) | 641 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
646 | 642 |
647 " Test <C-g> | 643 " Test <C-g> |
648 call term_sendkeys(g:buf, "\<C-g>\<C-g>") | 644 call term_sendkeys(buf, "\<C-g>\<C-g>") |
649 call term_wait(g:buf, 200) | 645 call term_wait(buf, 200) |
650 let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] | 646 let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] |
651 let attr_line2 = [a1,a1,a1,a0,a0,a2,a2,a2] | 647 let attr_line2 = [a1,a1,a1,a0,a0,a2,a2,a2] |
652 call assert_equal(attr_line1, map(term_scrape(g:buf, 1)[:len(attr_line1)-1], 'v:val.attr')) | 648 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
653 call assert_equal(attr_line2, map(term_scrape(g:buf, 2)[:len(attr_line2)-1], 'v:val.attr')) | 649 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
654 | 650 |
655 " Test <C-t> | 651 " Test <C-t> |
656 call term_sendkeys(g:buf, "\<C-t>") | 652 call term_sendkeys(buf, "\<C-t>") |
657 call term_wait(g:buf, 200) | 653 call term_wait(buf, 200) |
658 let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a1,a1,a1,a0,a0,a0] | 654 let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a1,a1,a1,a0,a0,a0] |
659 let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] | 655 let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
660 call assert_equal(attr_line1, map(term_scrape(g:buf, 1)[:len(attr_line1)-1], 'v:val.attr')) | 656 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
661 call assert_equal(attr_line2, map(term_scrape(g:buf, 2)[:len(attr_line2)-1], 'v:val.attr')) | 657 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
662 | 658 |
663 " Type Enter and a1(incsearch highlight) should become a2(hlsearch highlight) | 659 " Type Enter and a1(incsearch highlight) should become a2(hlsearch highlight) |
664 call term_sendkeys(g:buf, "\<cr>") | 660 call term_sendkeys(buf, "\<cr>") |
665 call term_wait(g:buf, 200) | 661 call term_wait(buf, 200) |
666 let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] | 662 let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] |
667 let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] | 663 let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
668 call assert_equal(attr_line1, map(term_scrape(g:buf, 1)[:len(attr_line1)-1], 'v:val.attr')) | 664 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
669 call assert_equal(attr_line2, map(term_scrape(g:buf, 2)[:len(attr_line2)-1], 'v:val.attr')) | 665 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
670 | 666 |
671 " Test nohlsearch. a2(hlsearch highlight) should become a0(normal highlight) | 667 " Test nohlsearch. a2(hlsearch highlight) should become a0(normal highlight) |
672 call term_sendkeys(g:buf, ":1\<cr>") | 668 call term_sendkeys(buf, ":1\<cr>") |
673 call term_sendkeys(g:buf, ":set nohlsearch\<cr>") | 669 call term_sendkeys(buf, ":set nohlsearch\<cr>") |
674 call term_sendkeys(g:buf, "/vim") | 670 call term_sendkeys(buf, "/vim") |
675 call term_wait(g:buf, 200) | 671 call term_wait(buf, 200) |
676 let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a0,a0,a0,a0,a0,a0] | 672 let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a0,a0,a0,a0,a0,a0] |
677 let attr_line2 = [a0,a0,a0,a0,a0,a0,a0,a0] | 673 let attr_line2 = [a0,a0,a0,a0,a0,a0,a0,a0] |
678 call assert_equal(attr_line1, map(term_scrape(g:buf, 1)[:len(attr_line1)-1], 'v:val.attr')) | 674 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
679 call assert_equal(attr_line2, map(term_scrape(g:buf, 2)[:len(attr_line2)-1], 'v:val.attr')) | 675 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
680 call delete('Xsearch.txt') | 676 call delete('Xsearch.txt') |
681 | 677 |
682 call delete('Xsearch.txt') | 678 call delete('Xsearch.txt') |
683 bwipe! | 679 bwipe! |
684 endfunc | 680 endfunc |