diff options
author | Bram Moolenaar <Bram@vim.org> | 2023-06-04 16:55:27 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2023-06-04 16:55:27 +0100 |
commit | abc8130d6a680026ffb2cc36b74d239e88f775d6 (patch) | |
tree | c3b596b8e36e39447405006701b10d7a48ec7ba0 /src/testdir | |
parent | 3c802277604a6b21110e41bedfe4c937ba7c2b7d (diff) |
patch 9.0.1604: errors from the codestyle test are a bit confusingv9.0.1604
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.
Diffstat (limited to 'src/testdir')
-rw-r--r-- | src/testdir/runtest.vim | 4 | ||||
-rw-r--r-- | src/testdir/test_codestyle.vim | 34 |
2 files changed, 25 insertions, 13 deletions
diff --git a/src/testdir/runtest.vim b/src/testdir/runtest.vim index 1cdeeef5aa..7ad8539c93 100644 --- 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 diff --git a/src/testdir/test_codestyle.vim b/src/testdir/test_codestyle.vim index 509e1351cb..074468e777 100644 --- 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 |