11" Test for checking the source code style.
22
3+ def s: ReportError (fname: string , lnum: number , msg: string )
4+ if lnum > 0
5+ assert_report (fname .. ' line ' .. lnum .. ' : ' .. msg)
6+ endif
7+ enddef
8+
39def Test_source_files ()
410 for fname in glob (' ../*.[ch]' , 0 , 1 )
511 bwipe!
12+ g: ignoreSwapExists = ' e'
613 exe ' edit ' .. fname
714
815 cursor (1 , 1 )
916 var lnum = search (' \t' )
10- assert_equal ( 0 , lnum, fname .. ' : space before tab ' )
17+ ReportError (fname , lnum, ' space before Tab ' )
1118
1219 cursor (1 , 1 )
1320 lnum = search (' \s$' )
14- assert_equal ( 0 , lnum, fname .. ' : trailing white space' )
21+ ReportError (fname , lnum, ' trailing white space' )
1522
1623 # some files don't stick to the Vim style rules
1724 if fname = ~ ' iscygpty.c'
@@ -25,29 +32,30 @@ def Test_source_files()
2532 var skip = ' getline(".") =~ "condition) {" || getline(".") =~ "vimglob_func" || getline(".") =~ "{\"" || getline(".") =~ "{\\d" || getline(".") =~ "{{{"'
2633 cursor (1 , 1 )
2734 lnum = search (' )\s*{' , ' ' , 0 , 0 , skip )
28- assert_equal ( 0 , lnum, fname .. ' : curly after closing paren' )
35+ ReportError (fname , lnum, ' curly after closing paren' )
2936
3037 # Examples in comments use double quotes.
3138 skip = " getline('.') =~ '\" '"
3239
3340 cursor (1 , 1 )
3441 lnum = search (' }\s*else' , ' ' , 0 , 0 , skip )
35- assert_equal ( 0 , lnum, fname .. ' : curly before "else"' )
42+ ReportError (fname , lnum, ' curly before "else"' )
3643
3744 cursor (1 , 1 )
3845 lnum = search (' else\s*{' , ' ' , 0 , 0 , skip )
39- assert_equal ( 0 , lnum, fname .. ' : curly after "else"' )
46+ ReportError (fname , lnum, ' curly after "else"' )
4047
4148 cursor (1 , 1 )
4249 lnum = search (' \<\(if\|while\|for\)(' , ' ' , 0 , 0 , skip )
43- assert_equal ( 0 , lnum, fname .. ' : missing white space after "if"/"while"/"for"' )
50+ ReportError (fname , lnum, ' missing white space after "if"/"while"/"for"' )
4451 endfor
4552
4653 bwipe!
4754enddef
4855
4956def Test_test_files ()
5057 for fname in glob (' *.vim' , 0 , 1 )
58+ g: ignoreSwapExists = ' e'
5159 exe ' edit ' .. fname
5260
5361 # some files intentionally have misplaced white space
@@ -61,7 +69,7 @@ def Test_test_files()
6169 && fname !~ ' test_visual.vim'
6270 cursor (1 , 1 )
6371 var lnum = search (fname = ~ " test_regexp_latin" ? ' [^á] \t' : ' \t' )
64- assert_equal ( 0 , lnum, ' testdir/' .. fname .. ' : space before tab ' )
72+ ReportError ( ' testdir/' .. fname, lnum, ' space before Tab ' )
6573 endif
6674
6775 # skip files that are known to have trailing white space
@@ -76,7 +84,7 @@ def Test_test_files()
7684 : fname = ~ ' test_vim9_script.vim' ? ' [^,:3]\s$'
7785 : fname = ~ ' test_visual.vim' ? ' [^/]\s$'
7886 : ' [^\\]\s$' )
79- assert_equal ( 0 , lnum, ' testdir/' .. fname .. ' : trailing white space' )
87+ ReportError ( ' testdir/' .. fname, lnum, ' trailing white space' )
8088 endif
8189 endfor
8290
@@ -88,6 +96,7 @@ def Test_help_files()
8896 set nowrapscan
8997
9098 for fpath in glob (' ../../runtime/doc/*.txt' , 0 , 1 )
99+ g: ignoreSwapExists = ' e'
91100 exe ' edit ' .. fpath
92101
93102 var fname = fnamemodify (fpath, " :t" )
@@ -106,7 +115,7 @@ def Test_help_files()
106115 || fname == ' usr_27.txt' && getline (lnum) = ~ " \[ ^\? \t \] "
107116 continue
108117 endif
109- assert_equal ( 0 , lnum, fpath .. ' : space before tab' )
118+ ReportError (fpath , lnum, ' space before tab' )
110119 if lnum == 0
111120 break
112121 endif
@@ -123,18 +132,17 @@ def Test_help_files()
123132 || fname == ' change.txt' && getline (lnum) = ~ " foobar bla $"
124133 continue
125134 endif
126- assert_equal ( 0 , lnum, fpath .. ' : trailing white space' )
135+ ReportError ( ' testdir ' .. fpath , lnum, ' trailing white space' )
127136 if lnum == 0
128137 break
129138 endif
130139 endwhile
131140
132- # TODO : Do check and fix help files
133- # # Check over 80 columns
141+ # # TODO : Check for line over 80 columns
134142# cursor (1 , 1 )
135143# while 1
136144# lnum = search (' \%>80v.*$' )
137- # assert_equal ( 0 , lnum, fpath .. ' : line over 80 columns' )
145+ # ReportError (fpath , lnum, ' line over 80 columns' )
138146# if lnum == 0
139147# break
140148# endif
0 commit comments