Mercurial > vim
comparison src/testdir/test_quickfix.vim @ 27897:2a2c0958a913 v8.2.4474
patch 8.2.4474: memory allocation failures not tested in quickfix code
Commit: https://github.com/vim/vim/commit/5a2d4a3ecb67942d47615507a163ffcd5863c073
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Sat Feb 26 10:31:32 2022 +0000
patch 8.2.4474: memory allocation failures not tested in quickfix code
Problem: Memory allocation failures not tested in quickfix code.
Solution: Add alloc IDs and tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/9848)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 26 Feb 2022 11:45:03 +0100 |
parents | d1af65b322d0 |
children | 2b595cee4c85 |
comparison
equal
deleted
inserted
replaced
27896:960de0084729 | 27897:2a2c0958a913 |
---|---|
619 func Test_browse() | 619 func Test_browse() |
620 call Xtest_browse('c') | 620 call Xtest_browse('c') |
621 call Xtest_browse('l') | 621 call Xtest_browse('l') |
622 endfunc | 622 endfunc |
623 | 623 |
624 " Test for memory allocation failures | |
625 func Xnomem_tests(cchar) | |
626 call s:setup_commands(a:cchar) | |
627 | |
628 call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0) | |
629 call assert_fails('Xvimgrep vim runtest.vim', 'E342:') | |
630 | |
631 call test_alloc_fail(GetAllocId('qf_dirname_now'), 0, 0) | |
632 call assert_fails('Xvimgrep vim runtest.vim', 'E342:') | |
633 | |
634 call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0) | |
635 call assert_fails('Xfile runtest.vim', 'E342:') | |
636 | |
637 call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0) | |
638 call assert_fails('Xfile runtest.vim', 'E342:') | |
639 | |
640 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0) | |
641 call assert_fails('Xfile runtest.vim', 'E342:') | |
642 | |
643 call test_alloc_fail(GetAllocId('qf_efm_fmtstr'), 0, 0) | |
644 set efm=%f | |
645 call assert_fails('Xexpr ["Xfile1"]', 'E342:') | |
646 set efm& | |
647 | |
648 call test_alloc_fail(GetAllocId('qf_efm_fmtpart'), 0, 0) | |
649 set efm=%f:%l:%m,%f-%l-%m | |
650 call assert_fails('Xaddexpr ["Xfile2", "Xfile3"]', 'E342:') | |
651 set efm& | |
652 | |
653 call test_alloc_fail(GetAllocId('qf_title'), 0, 0) | |
654 call assert_fails('Xexpr ""', 'E342:') | |
655 call assert_equal('', g:Xgetlist({'all': 1}).title) | |
656 | |
657 call test_alloc_fail(GetAllocId('qf_mef_name'), 0, 0) | |
658 set makeef=Xtmp##.err | |
659 call assert_fails('Xgrep needle haystack', 'E342:') | |
660 set makeef& | |
661 | |
662 call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0) | |
663 call assert_fails('Xexpr "Xfile1:10:Line10"', 'E342:') | |
664 | |
665 if a:cchar == 'l' | |
666 for id in ['qf_qfline', 'qf_qfinfo'] | |
667 lgetexpr ["Xfile1:10:L10", "Xfile2:20:L20"] | |
668 call test_alloc_fail(GetAllocId(id), 0, 0) | |
669 call assert_fails('new', 'E342:') | |
670 call assert_equal(2, winnr('$')) | |
671 call assert_equal([], getloclist(0)) | |
672 %bw! | |
673 endfor | |
674 endif | |
675 | |
676 call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0) | |
677 try | |
678 call assert_fails('Xvimgrep vim runtest.vim', 'E342:') | |
679 catch /^Vim:Interrupt$/ | |
680 endtry | |
681 | |
682 call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0) | |
683 try | |
684 call assert_fails('Xvimgrep /vim/f runtest.vim', 'E342:') | |
685 catch /^Vim:Interrupt$/ | |
686 endtry | |
687 | |
688 let l = getqflist({"lines": ["Xfile1:10:L10"]}) | |
689 call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0) | |
690 call assert_fails('call g:Xsetlist(l.items)', 'E342:') | |
691 | |
692 call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0) | |
693 try | |
694 call assert_fails('Xhelpgrep quickfix', 'E342:') | |
695 catch /^Vim:Interrupt$/ | |
696 endtry | |
697 | |
698 call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0) | |
699 call assert_fails('let l = g:Xgetlist({"lines": ["Xfile1:10:L10"]})', 'E342:') | |
700 call assert_equal(#{items: []}, l) | |
701 | |
702 if a:cchar == 'l' | |
703 call setqflist([], 'f') | |
704 call setloclist(0, [], 'f') | |
705 call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0) | |
706 call assert_fails('lhelpgrep quickfix', 'E342:') | |
707 call assert_equal([], getloclist(0)) | |
708 | |
709 call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0) | |
710 call assert_fails('lvimgrep vim runtest.vim', 'E342:') | |
711 | |
712 let l = getqflist({"lines": ["Xfile1:10:L10"]}) | |
713 call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0) | |
714 call assert_fails('call setloclist(0, l.items)', 'E342:') | |
715 | |
716 call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0) | |
717 call assert_fails('lbuffer', 'E342:') | |
718 | |
719 call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0) | |
720 call assert_fails('lexpr ["Xfile1:10:L10", "Xfile2:20:L20"]', 'E342:') | |
721 | |
722 call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0) | |
723 call assert_fails('lfile runtest.vim', 'E342:') | |
724 endif | |
725 | |
726 call test_alloc_fail(GetAllocId('qf_dirstack'), 0, 0) | |
727 set efm=%DEntering\ dir\ %f,%f:%l:%m | |
728 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E342:') | |
729 set efm& | |
730 | |
731 call test_alloc_fail(GetAllocId('qf_dirstack'), 0, 0) | |
732 set efm=%+P[%f],(%l)%m | |
733 call assert_fails('Xexpr ["[runtest.vim]", "(1)Hello"]', 'E342:') | |
734 set efm& | |
735 | |
736 call test_alloc_fail(GetAllocId('qf_multiline_pfx'), 0, 0) | |
737 set efm=%EError,%Cline\ %l,%Z%m | |
738 call assert_fails('Xexpr ["Error", "line 1", "msg"]', 'E342:') | |
739 set efm& | |
740 | |
741 call test_alloc_fail(GetAllocId('qf_makecmd'), 0, 0) | |
742 call assert_fails('Xgrep vim runtest.vim', 'E342:') | |
743 | |
744 call test_alloc_fail(GetAllocId('qf_linebuf'), 0, 0) | |
745 call assert_fails('Xexpr repeat("a", 8192)', 'E342:') | |
746 | |
747 call test_alloc_fail(GetAllocId('qf_linebuf'), 0, 0) | |
748 call assert_fails('Xexpr [repeat("a", 8192)]', 'E342:') | |
749 | |
750 new | |
751 call setline(1, repeat('a', 8192)) | |
752 call test_alloc_fail(GetAllocId('qf_linebuf'), 0, 0) | |
753 call assert_fails('Xbuffer', 'E342:') | |
754 %bw! | |
755 | |
756 call writefile([repeat('a', 8192)], 'Xtest') | |
757 call test_alloc_fail(GetAllocId('qf_linebuf'), 0, 0) | |
758 call assert_fails('Xfile Xtest', 'E342:') | |
759 call delete('Xtest') | |
760 endfunc | |
761 | |
624 func Test_nomem() | 762 func Test_nomem() |
625 call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0) | 763 call Xnomem_tests('c') |
626 call assert_fails('vimgrep vim runtest.vim', 'E342:') | 764 call Xnomem_tests('l') |
627 | |
628 call GetAllocId('qf_dirname_now')->test_alloc_fail(0, 0) | |
629 call assert_fails('vimgrep vim runtest.vim', 'E342:') | |
630 | |
631 call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0) | |
632 call assert_fails('cfile runtest.vim', 'E342:') | |
633 | |
634 call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0) | |
635 call assert_fails('cfile runtest.vim', 'E342:') | |
636 | |
637 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0) | |
638 call assert_fails('cfile runtest.vim', 'E342:') | |
639 | |
640 endfunc | 765 endfunc |
641 | 766 |
642 func s:test_xhelpgrep(cchar) | 767 func s:test_xhelpgrep(cchar) |
643 call s:setup_commands(a:cchar) | 768 call s:setup_commands(a:cchar) |
644 Xhelpgrep quickfix | 769 Xhelpgrep quickfix |