robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:9.1.1865: tests: do not notice lines containing only a tab (#40182)de10d10d3f

master
4.1 KiB141 linesraw
1" Test for checking the source code style.
2
3func s:ReportError(fname, lnum, msg)
4  if a:lnum > 0
5    call assert_report(a:fname .. ' line ' .. a:lnum .. ': ' .. a:msg)
6  endif
7endfunc
8
9func s:PerformCheck(fname, pattern, msg, skip)
10  let prev_lnum = 1
11  let lnum = 1
12  while (lnum > 0)
13    call cursor(lnum, 1)
14    let lnum = search(a:pattern, 'W', 0, 0, a:skip)
15    if (prev_lnum == lnum)
16      break
17    endif
18    let prev_lnum = lnum
19    if (lnum > 0)
20      call s:ReportError(a:fname, lnum, a:msg)
21    endif
22  endwhile
23endfunc
24
25func Test_test_files()
26  for fname in glob('*.vim', 0, 1)
27    let g:ignoreSwapExists = 'e'
28    exe 'edit ' .. fname
29
30    " some files intentionally have misplaced white space
31    if fname =~ 'test_cindent.vim' || fname =~ 'test_join.vim'
32      continue
33    endif
34
35    " skip files that are known to have a space before a tab
36    if fname !~ 'test_comments.vim'
37          \ && fname !~ 'test_listchars.vim'
38          \ && fname !~ 'test_visual.vim'
39      call cursor(1, 1)
40      let skip = 'getline(".") =~ "codestyle: ignore"'
41      let lnum = search(fname =~ "test_regexp_latin" ? '[^á] \t' : ' \t', 'W', 0, 0, skip)
42      call s:ReportError('testdir/' .. fname, lnum, 'space before Tab')
43    endif
44
45    " skip files that are known to have trailing white space
46    if fname !~ 'test_cmdline.vim'
47          \ && fname !~ 'test_let.vim'
48          \ && fname !~ 'test_tagjump.vim'
49          \ && fname !~ 'test_vim9_cmd.vim'
50      call cursor(1, 1)
51      let lnum = search(
52            \ fname =~ 'test_vim9_assign.vim' ? '[^=]\s$'
53            \ : fname =~ 'test_vim9_class.vim' ? '[^)]\s$'
54            \ : fname =~ 'test_vim9_script.vim' ? '[^,:3]\s$'
55            \ : fname =~ 'test_visual.vim' ? '[^/]\s$'
56            \ : '[^\\]\s$')
57      call s:ReportError('testdir/' .. fname, lnum, 'trailing white space')
58    endif
59  endfor
60
61  bwipe!
62endfunc
63
64func Test_help_files()
65  set nowrapscan
66
67  for fpath in glob('../../../runtime/doc/*.txt', 0, 1)
68    let g:ignoreSwapExists = 'e'
69    exe 'edit ' .. fpath
70
71    let fname = fnamemodify(fpath, ":t")
72
73    " todo.txt is for developers, it's not need a strictly check
74    " version*.txt is a history and large size, so it's not checked
75    if fname == 'todo.txt' || fname =~ 'version.*\.txt'
76      continue
77    endif
78
79    " Check for mixed tabs and spaces
80    call cursor(1, 1)
81    while 1
82      let lnum = search('[^/] \t')
83      if fname == 'visual.txt' && getline(lnum) =~ "STRING  \tjkl"
84            \ || fname == 'usr_27.txt' && getline(lnum) =~ "\[^\? \t\]"
85        continue
86      endif
87      call s:ReportError(fpath, lnum, 'space before tab')
88      if lnum == 0
89        break
90      endif
91    endwhile
92
93    " Check for unnecessary whitespace at the end of a line
94    call cursor(1, 1)
95    while 1
96      let lnum = search('\%([^/~\\]\|^\)\s\+$')
97      " skip line that are known to have trailing white space
98      if fname == 'map.txt' && getline(lnum) =~ "unmap @@ $"
99            \ || fname == 'usr_12.txt' && getline(lnum) =~ "^\t/ \t$"
100            \ || fname == 'usr_41.txt' && getline(lnum) =~ "map <F4> o#include  $"
101            \ || fname == 'change.txt' && getline(lnum) =~ "foobar bla $"
102        continue
103      endif
104      call s:ReportError('testdir' .. fpath, lnum, 'trailing white space')
105      if lnum == 0
106        break
107      endif
108    endwhile
109
110
111  endfor
112
113  set wrapscan&vim
114  bwipe!
115endfunc
116
117
118func Test_runtime_wrong_shellescape()
119  " Check that shellescape() is called with the {special} argument (a second,
120  " non-zero argument) when its result is used in a ":!" ex command.
121  " This could cause code injection!
122  let pattern = '\<shellescape(\%([^,()]\|([^()]*)\)\+)'
123
124  let q = "['" .. '"]'
125  let bang_exe = '\<\%(exe\%[cute]\|sil\%[ent]\)\>.*' .. q .. '[^"' .. "']*!"
126
127  let skip = 'getline(".") !~ ' .. string(bang_exe)
128        \ .. ' || getline(".") =~ ' .. string('\<system\%(list\)\=(')
129        \ .. ' || getline(".") =~ ' .. string('^\s*"')
130
131  for fpath in glob('../../../runtime/**/*.vim', 0, 1)
132    let g:ignoreSwapExists = 'e'
133    exe 'edit ' .. fpath
134    call s:PerformCheck(fpath, pattern,
135          \ 'shellescape() without {special} flag used in ":!" command', skip)
136  endfor
137
138  :%bwipe!
139endfunc
140
141" vim: shiftwidth=2 sts=2 expandtab