mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
tests: Improve the codestyle test (#12988)
Improve it by the following: 1) Also check xxd source 2) Test_source_files(): don't stop on the first error found, continue until the end of the file and report all found errors like this: Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
parent
456ae556b4
commit
b147d31489
@ -6,48 +6,44 @@ def s:ReportError(fname: string, lnum: number, msg: string)
|
|||||||
endif
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def s:PerformCheck(fname: string, pattern: string, msg: string, skip: string)
|
||||||
|
var lnum = 1
|
||||||
|
while (lnum > 0)
|
||||||
|
cursor(lnum, 1)
|
||||||
|
lnum = search(pattern, 'W', 0, 0, skip)
|
||||||
|
ReportError(fname, lnum, msg)
|
||||||
|
if (lnum > 0)
|
||||||
|
lnum += 1
|
||||||
|
endif
|
||||||
|
endwhile
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_source_files()
|
def Test_source_files()
|
||||||
for fname in glob('../*.[ch]', 0, 1)
|
for fname in glob('../*.[ch]', 0, 1) + ['../xxd/xxd.c']
|
||||||
bwipe!
|
bwipe!
|
||||||
g:ignoreSwapExists = 'e'
|
g:ignoreSwapExists = 'e'
|
||||||
exe 'edit ' .. fname
|
exe 'edit ' .. fname
|
||||||
|
|
||||||
cursor(1, 1)
|
PerformCheck(fname, ' \t', 'space before Tab', '')
|
||||||
var lnum = search(' \t')
|
|
||||||
ReportError(fname, lnum, 'space before Tab')
|
|
||||||
|
|
||||||
cursor(1, 1)
|
PerformCheck(fname, '\s$', 'trailing white space', '')
|
||||||
lnum = search('\s$')
|
|
||||||
ReportError(fname, lnum, 'trailing white space')
|
|
||||||
|
|
||||||
# some files don't stick to the Vim style rules
|
# some files don't stick to the Vim style rules
|
||||||
if fname =~ 'iscygpty.c'
|
if fname =~ 'iscygpty.c'
|
||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Examples in comments use "condition) {", skip them.
|
|
||||||
# Skip if a double quote or digit comes after the "{".
|
|
||||||
# Skip specific string used in os_unix.c.
|
|
||||||
# Also skip fold markers.
|
|
||||||
var skip = 'getline(".") =~ "condition) {" || getline(".") =~ "vimglob_func" || getline(".") =~ "{\"" || getline(".") =~ "{\\d" || getline(".") =~ "{{{"'
|
var skip = 'getline(".") =~ "condition) {" || getline(".") =~ "vimglob_func" || getline(".") =~ "{\"" || getline(".") =~ "{\\d" || getline(".") =~ "{{{"'
|
||||||
cursor(1, 1)
|
PerformCheck(fname, ')\s*{', 'curly after closing paren', skip)
|
||||||
lnum = search(')\s*{', '', 0, 0, skip)
|
|
||||||
ReportError(fname, lnum, 'curly after closing paren')
|
|
||||||
|
|
||||||
# Examples in comments use double quotes.
|
# Examples in comments use double quotes.
|
||||||
skip = "getline('.') =~ '\"'"
|
skip = "getline('.') =~ '\"'"
|
||||||
|
|
||||||
cursor(1, 1)
|
PerformCheck(fname, '}\s*else', 'curly before "else"', skip)
|
||||||
lnum = search('}\s*else', '', 0, 0, skip)
|
|
||||||
ReportError(fname, lnum, 'curly before "else"')
|
|
||||||
|
|
||||||
cursor(1, 1)
|
PerformCheck(fname, 'else\s*{', 'curly after "else"', skip)
|
||||||
lnum = search('else\s*{', '', 0, 0, skip)
|
|
||||||
ReportError(fname, lnum, 'curly after "else"')
|
|
||||||
|
|
||||||
cursor(1, 1)
|
PerformCheck(fname, '\<\(if\|while\|for\)(', 'missing white space after "if"/"while"/"for"', skip)
|
||||||
lnum = search('\<\(if\|while\|for\)(', '', 0, 0, skip)
|
|
||||||
ReportError(fname, lnum, 'missing white space after "if"/"while"/"for"')
|
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user