Mercurial > vim
changeset 32545:36519954bf67 v9.0.1604
patch 9.0.1604: errors from the codestyle test are a bit confusing
Commit: https://github.com/vim/vim/commit/abc8130d6a680026ffb2cc36b74d239e88f775d6
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 4 16:55:27 2023 +0100
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 04 Jun 2023 18:00:05 +0200 |
parents | 0f2e024cea33 |
children | 3f3e8b7ec2d5 |
files | src/testdir/runtest.vim src/testdir/test_codestyle.vim src/version.c |
diffstat | 3 files changed, 27 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/testdir/runtest.vim +++ b/src/testdir/runtest.vim @@ -111,9 +111,13 @@ if has("win32") else let s:test_script_fname = expand('%') endif + au! SwapExists * call HandleSwapExists() func HandleSwapExists() if exists('g:ignoreSwapExists') + if type(g:ignoreSwapExists) == v:t_string + let v:swapchoice = g:ignoreSwapExists + endif return endif " Ignore finding a swap file for the test script (the user might be
--- a/src/testdir/test_codestyle.vim +++ b/src/testdir/test_codestyle.vim @@ -1,17 +1,24 @@ " 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() for fname in glob('../*.[ch]', 0, 1) bwipe! + g:ignoreSwapExists = 'e' exe 'edit ' .. fname cursor(1, 1) var lnum = search(' \t') - assert_equal(0, lnum, fname .. ': space before tab') + ReportError(fname, lnum, 'space before Tab') cursor(1, 1) 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 if fname =~ 'iscygpty.c' @@ -25,22 +32,22 @@ def Test_source_files() var skip = 'getline(".") =~ "condition) {" || getline(".") =~ "vimglob_func" || getline(".") =~ "{\"" || getline(".") =~ "{\\d" || getline(".") =~ "{{{"' cursor(1, 1) 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. skip = "getline('.') =~ '\"'" cursor(1, 1) lnum = search('}\s*else', '', 0, 0, skip) - assert_equal(0, lnum, fname .. ': curly before "else"') + ReportError(fname, lnum, 'curly before "else"') cursor(1, 1) lnum = search('else\s*{', '', 0, 0, skip) - assert_equal(0, lnum, fname .. ': curly after "else"') + ReportError(fname, lnum, 'curly after "else"') cursor(1, 1) 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 bwipe! @@ -48,6 +55,7 @@ enddef def Test_test_files() for fname in glob('*.vim', 0, 1) + g:ignoreSwapExists = 'e' exe 'edit ' .. fname # some files intentionally have misplaced white space @@ -61,7 +69,7 @@ def Test_test_files() && fname !~ 'test_visual.vim' cursor(1, 1) 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 # 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_visual.vim' ? '[^/]\s$' : '[^\\]\s$') - assert_equal(0, lnum, 'testdir/' .. fname .. ': trailing white space') + ReportError('testdir/' .. fname, lnum, 'trailing white space') endif endfor @@ -88,6 +96,7 @@ def Test_help_files() set nowrapscan for fpath in glob('../../runtime/doc/*.txt', 0, 1) + g:ignoreSwapExists = 'e' exe 'edit ' .. fpath var fname = fnamemodify(fpath, ":t") @@ -106,7 +115,7 @@ def Test_help_files() || fname == 'usr_27.txt' && getline(lnum) =~ "\[^\? \t\]" continue endif - assert_equal(0, lnum, fpath .. ': space before tab') + ReportError(fpath, lnum, 'space before tab') if lnum == 0 break endif @@ -123,18 +132,17 @@ def Test_help_files() || fname == 'change.txt' && getline(lnum) =~ "foobar bla $" continue endif - assert_equal(0, lnum, fpath .. ': trailing white space') + ReportError('testdir' .. fpath, lnum, 'trailing white space') if lnum == 0 break endif endwhile - # TODO: Do check and fix help files -# # Check over 80 columns +# # TODO: Check for line over 80 columns # cursor(1, 1) # while 1 # lnum = search('\%>80v.*$') -# assert_equal(0, lnum, fpath .. ': line over 80 columns') +# ReportError(fpath, lnum, 'line over 80 columns') # if lnum == 0 # break # endif