changeset 33108:3acd40c4c684

tests: Improve the codestyle test (#12988) Commit: https://github.com/vim/vim/commit/b147d314897b7a82081644edf779e22138d44f2c Author: Christian Brabandt <cb@256bit.org> Date: Fri Sep 1 17:58:35 2023 +0100 tests: Improve the codestyle test (https://github.com/vim/vim/issues/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>
author Christian Brabandt <cb@256bit.org>
date Fri, 01 Sep 2023 19:00:13 +0200
parents c7c0e23db8e1
children 2b5cc29b0a0e
files src/testdir/test_codestyle.vim
diffstat 1 files changed, 19 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_codestyle.vim
+++ b/src/testdir/test_codestyle.vim
@@ -6,48 +6,44 @@ def s:ReportError(fname: string, lnum: n
   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!