0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 9.0.1604: errors from the codestyle test are a bit confusing

Problem:    Errors from the codestyle test are a bit confusing.
Solution:   Use assert_report() with a clearer message.  Avoid a warning for
            an existing swap file.
This commit is contained in:
Bram Moolenaar 2023-06-04 16:55:27 +01:00
parent 3c80227760
commit abc8130d6a
3 changed files with 27 additions and 13 deletions

View File

@ -111,9 +111,13 @@ if has("win32")
else else
let s:test_script_fname = expand('%') let s:test_script_fname = expand('%')
endif endif
au! SwapExists * call HandleSwapExists() au! SwapExists * call HandleSwapExists()
func HandleSwapExists() func HandleSwapExists()
if exists('g:ignoreSwapExists') if exists('g:ignoreSwapExists')
if type(g:ignoreSwapExists) == v:t_string
let v:swapchoice = g:ignoreSwapExists
endif
return return
endif endif
" Ignore finding a swap file for the test script (the user might be " Ignore finding a swap file for the test script (the user might be

View File

@ -1,17 +1,24 @@
" Test for checking the source code style. " Test for checking the source code style.
def s:ReportError(fname: string, lnum: number, msg: string)
if lnum > 0
assert_report(fname .. ' line ' .. lnum .. ': ' .. msg)
endif
enddef
def Test_source_files() def Test_source_files()
for fname in glob('../*.[ch]', 0, 1) for fname in glob('../*.[ch]', 0, 1)
bwipe! bwipe!
g:ignoreSwapExists = 'e'
exe 'edit ' .. fname exe 'edit ' .. fname
cursor(1, 1) cursor(1, 1)
var lnum = search(' \t') var lnum = search(' \t')
assert_equal(0, lnum, fname .. ': space before tab') ReportError(fname, lnum, 'space before Tab')
cursor(1, 1) cursor(1, 1)
lnum = search('\s$') lnum = search('\s$')
assert_equal(0, lnum, fname .. ': trailing white space') 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'
@ -25,22 +32,22 @@ def Test_source_files()
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) cursor(1, 1)
lnum = search(')\s*{', '', 0, 0, skip) lnum = search(')\s*{', '', 0, 0, skip)
assert_equal(0, lnum, fname .. ': curly after closing paren') 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) cursor(1, 1)
lnum = search('}\s*else', '', 0, 0, skip) lnum = search('}\s*else', '', 0, 0, skip)
assert_equal(0, lnum, fname .. ': curly before "else"') ReportError(fname, lnum, 'curly before "else"')
cursor(1, 1) cursor(1, 1)
lnum = search('else\s*{', '', 0, 0, skip) lnum = search('else\s*{', '', 0, 0, skip)
assert_equal(0, lnum, fname .. ': curly after "else"') ReportError(fname, lnum, 'curly after "else"')
cursor(1, 1) cursor(1, 1)
lnum = search('\<\(if\|while\|for\)(', '', 0, 0, skip) lnum = search('\<\(if\|while\|for\)(', '', 0, 0, skip)
assert_equal(0, lnum, fname .. ': missing white space after "if"/"while"/"for"') ReportError(fname, lnum, 'missing white space after "if"/"while"/"for"')
endfor endfor
bwipe! bwipe!
@ -48,6 +55,7 @@ enddef
def Test_test_files() def Test_test_files()
for fname in glob('*.vim', 0, 1) for fname in glob('*.vim', 0, 1)
g:ignoreSwapExists = 'e'
exe 'edit ' .. fname exe 'edit ' .. fname
# some files intentionally have misplaced white space # some files intentionally have misplaced white space
@ -61,7 +69,7 @@ def Test_test_files()
&& fname !~ 'test_visual.vim' && fname !~ 'test_visual.vim'
cursor(1, 1) cursor(1, 1)
var lnum = search(fname =~ "test_regexp_latin" ? '[^á] \t' : ' \t') var lnum = search(fname =~ "test_regexp_latin" ? '[^á] \t' : ' \t')
assert_equal(0, lnum, 'testdir/' .. fname .. ': space before tab') ReportError('testdir/' .. fname, lnum, 'space before Tab')
endif endif
# skip files that are known to have trailing white space # skip files that are known to have trailing white space
@ -76,7 +84,7 @@ def Test_test_files()
: fname =~ 'test_vim9_script.vim' ? '[^,:3]\s$' : fname =~ 'test_vim9_script.vim' ? '[^,:3]\s$'
: fname =~ 'test_visual.vim' ? '[^/]\s$' : fname =~ 'test_visual.vim' ? '[^/]\s$'
: '[^\\]\s$') : '[^\\]\s$')
assert_equal(0, lnum, 'testdir/' .. fname .. ': trailing white space') ReportError('testdir/' .. fname, lnum, 'trailing white space')
endif endif
endfor endfor
@ -88,6 +96,7 @@ def Test_help_files()
set nowrapscan set nowrapscan
for fpath in glob('../../runtime/doc/*.txt', 0, 1) for fpath in glob('../../runtime/doc/*.txt', 0, 1)
g:ignoreSwapExists = 'e'
exe 'edit ' .. fpath exe 'edit ' .. fpath
var fname = fnamemodify(fpath, ":t") var fname = fnamemodify(fpath, ":t")
@ -106,7 +115,7 @@ def Test_help_files()
|| fname == 'usr_27.txt' && getline(lnum) =~ "\[^\? \t\]" || fname == 'usr_27.txt' && getline(lnum) =~ "\[^\? \t\]"
continue continue
endif endif
assert_equal(0, lnum, fpath .. ': space before tab') ReportError(fpath, lnum, 'space before tab')
if lnum == 0 if lnum == 0
break break
endif endif
@ -123,18 +132,17 @@ def Test_help_files()
|| fname == 'change.txt' && getline(lnum) =~ "foobar bla $" || fname == 'change.txt' && getline(lnum) =~ "foobar bla $"
continue continue
endif endif
assert_equal(0, lnum, fpath .. ': trailing white space') ReportError('testdir' .. fpath, lnum, 'trailing white space')
if lnum == 0 if lnum == 0
break break
endif endif
endwhile endwhile
# TODO: Do check and fix help files # # TODO: Check for line over 80 columns
# # Check over 80 columns
# cursor(1, 1) # cursor(1, 1)
# while 1 # while 1
# lnum = search('\%>80v.*$') # lnum = search('\%>80v.*$')
# assert_equal(0, lnum, fpath .. ': line over 80 columns') # ReportError(fpath, lnum, 'line over 80 columns')
# if lnum == 0 # if lnum == 0
# break # break
# endif # endif

View File

@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1604,
/**/ /**/
1603, 1603,
/**/ /**/