annotate src/testdir/test_codestyle.vim @ 31849:dbec60b8c253 v9.0.1257

patch 9.0.1257: code style is not check in test scripts Commit: https://github.com/vim/vim/commit/94722c510745a0cfd494c51625a514b92dd2bfb2 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 28 19:19:03 2023 +0000 patch 9.0.1257: code style is not check in test scripts Problem: Code style is not check in test scripts. Solution: Add basic code style check for test files.
author Bram Moolenaar <Bram@vim.org>
date Sat, 28 Jan 2023 20:30:04 +0100
parents 50555279168b
children 9fec560a63ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31804
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Test for checking the source code style.
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 def Test_source_files()
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 for fname in glob('../*.[ch]', 0, 1)
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 exe 'edit ' .. fname
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 cursor(1, 1)
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 var lnum = search(' \t')
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 assert_equal(0, lnum, fname .. ': space before tab')
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 cursor(1, 1)
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 lnum = search('\s$')
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 assert_equal(0, lnum, fname .. ': trailing white space')
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 # some files don't stick to the Vim style rules
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 if fname =~ 'iscygpty.c'
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 continue
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 endif
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 # Examples in comments use "condition) {", skip them.
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 # Skip if a double quote or digit comes after the "{".
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 # Skip specific string used in os_unix.c.
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 # Also skip fold markers.
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 var skip = 'getline(".") =~ "condition) {" || getline(".") =~ "vimglob_func" || getline(".") =~ "{\"" || getline(".") =~ "{\\d" || getline(".") =~ "{{{"'
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 cursor(1, 1)
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 lnum = search(')\s*{', '', 0, 0, skip)
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 assert_equal(0, lnum, fname .. ': curly after closing paren')
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 cursor(1, 1)
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 # Examples in comments use double quotes.
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 skip = "getline('.') =~ '\"'"
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 # Avoid examples that contain: "} else
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 lnum = search('[^"]}\s*else', '', 0, 0, skip)
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 assert_equal(0, lnum, fname .. ': curly before "else"')
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 cursor(1, 1)
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 lnum = search('else\s*{', '', 0, 0, skip)
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 assert_equal(0, lnum, fname .. ': curly after "else"')
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 endfor
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 bwipe!
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 enddef
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43
31849
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
44 def Test_test_files()
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
45 for fname in glob('*.vim', 0, 1)
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
46 exe 'edit ' .. fname
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
47
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
48 # some files intentionally have misplaced white space
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
49 if fname =~ 'test_cindent.vim' || fname =~ 'test_join.vim'
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
50 continue
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
51 endif
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
52
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
53 # skip files that are known to have a space before a tab
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
54 if fname !~ 'test_comments.vim'
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
55 && fname !~ 'test_listchars.vim'
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
56 && fname !~ 'test_visual.vim'
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
57 cursor(1, 1)
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
58 var lnum = search(fname =~ "test_regexp_latin" ? '[^รก] \t' : ' \t')
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
59 assert_equal(0, lnum, 'testdir/' .. fname .. ': space before tab')
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
60 endif
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
61
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
62 # skip files that are known to have trailing white space
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
63 if fname !~ 'test_cmdline.vim'
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
64 && fname !~ 'test_let.vim'
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
65 && fname !~ 'test_tagjump.vim'
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
66 && fname !~ 'test_vim9_cmd.vim'
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
67 cursor(1, 1)
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
68 var lnum = search(
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
69 fname =~ 'test_vim9_assign.vim' ? '[^=]\s$'
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
70 : fname =~ 'test_vim9_class.vim' ? '[^)]\s$'
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
71 : fname =~ 'test_vim9_script.vim' ? '[^,:3]\s$'
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
72 : fname =~ 'test_visual.vim' ? '[^/]\s$'
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
73 : '[^\\]\s$')
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
74 assert_equal(0, lnum, 'testdir/' .. fname .. ': trailing white space')
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
75 endif
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
76 endfor
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
77
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
78 bwipe!
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
79 enddef
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
80
31804
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 " vim: shiftwidth=2 sts=2 expandtab