diff options
author | Christian Brabandt <cb@256bit.org> | 2023-09-01 17:58:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-01 18:58:35 +0200 |
commit | b147d314897b7a82081644edf779e22138d44f2c (patch) | |
tree | bb5537f4bdf570f2f02f630de07699d3b28a659d | |
parent | 456ae556b43f277c65ceb518d58034b11cd58cfb (diff) |
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>
-rw-r--r-- | src/testdir/test_codestyle.vim | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/src/testdir/test_codestyle.vim b/src/testdir/test_codestyle.vim index 074468e777..359410d2d0 100644 --- a/src/testdir/test_codestyle.vim +++ b/src/testdir/test_codestyle.vim @@ -6,48 +6,44 @@ def s:ReportError(fname: string, lnum: number, msg: string) endif 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() - for fname in glob('../*.[ch]', 0, 1) + for fname in glob('../*.[ch]', 0, 1) + ['../xxd/xxd.c'] bwipe! g:ignoreSwapExists = 'e' exe 'edit ' .. fname - cursor(1, 1) - var lnum = search(' \t') - ReportError(fname, lnum, 'space before Tab') + PerformCheck(fname, ' \t', 'space before Tab', '') - cursor(1, 1) - lnum = search('\s$') - ReportError(fname, lnum, 'trailing white space') + PerformCheck(fname, '\s$', 'trailing white space', '') # some files don't stick to the Vim style rules if fname =~ 'iscygpty.c' continue 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(".") =~ "{{{"' - cursor(1, 1) - lnum = search(')\s*{', '', 0, 0, skip) - ReportError(fname, lnum, 'curly after closing paren') + PerformCheck(fname, ')\s*{', 'curly after closing paren', skip) # Examples in comments use double quotes. skip = "getline('.') =~ '\"'" - cursor(1, 1) - lnum = search('}\s*else', '', 0, 0, skip) - ReportError(fname, lnum, 'curly before "else"') + PerformCheck(fname, '}\s*else', 'curly before "else"', skip) - cursor(1, 1) - lnum = search('else\s*{', '', 0, 0, skip) - ReportError(fname, lnum, 'curly after "else"') + PerformCheck(fname, 'else\s*{', 'curly after "else"', skip) - cursor(1, 1) - lnum = search('\<\(if\|while\|for\)(', '', 0, 0, skip) - ReportError(fname, lnum, 'missing white space after "if"/"while"/"for"') + PerformCheck(fname, '\<\(if\|while\|for\)(', 'missing white space after "if"/"while"/"for"', skip) endfor bwipe! |