Mercurial > hg
comparison contrib/check-code.py @ 15364:572c22c88be6 stable
tests: fix check-code detection of anchored expressions, fix echo -n usage
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 26 Oct 2011 12:56:27 -0500 |
parents | 24856af7237c |
children | 695ac6aca77f |
comparison
equal
deleted
inserted
replaced
15363:628a4a9e411d | 15364:572c22c88be6 |
---|---|
43 | 43 |
44 testpats = [ | 44 testpats = [ |
45 [ | 45 [ |
46 (r'(pushd|popd)', "don't use 'pushd' or 'popd', use 'cd'"), | 46 (r'(pushd|popd)', "don't use 'pushd' or 'popd', use 'cd'"), |
47 (r'\W\$?\(\([^\)\n]*\)\)', "don't use (()) or $(()), use 'expr'"), | 47 (r'\W\$?\(\([^\)\n]*\)\)', "don't use (()) or $(()), use 'expr'"), |
48 (r'^function', "don't use 'function', use old style"), | 48 (r'(^|\n)function', "don't use 'function', use old style"), |
49 (r'grep.*-q', "don't use 'grep -q', redirect to /dev/null"), | 49 (r'grep.*-q', "don't use 'grep -q', redirect to /dev/null"), |
50 (r'echo.*\\n', "don't use 'echo \\n', use printf"), | 50 (r'echo.*\\n', "don't use 'echo \\n', use printf"), |
51 (r'echo -n', "don't use 'echo -n', use printf"), | 51 (r'echo -n', "don't use 'echo -n', use printf"), |
52 (r'^diff.*-\w*N', "don't use 'diff -N'"), | 52 (r'(^|\n)diff.*-\w*N', "don't use 'diff -N'"), |
53 (r'(^| )wc[^|\n]*$', "filter wc output"), | 53 (r'(^| )wc[^|\n]*$', "filter wc output"), |
54 (r'head -c', "don't use 'head -c', use 'dd'"), | 54 (r'head -c', "don't use 'head -c', use 'dd'"), |
55 (r'ls.*-\w*R', "don't use 'ls -R', use 'find'"), | 55 (r'ls.*-\w*R', "don't use 'ls -R', use 'find'"), |
56 (r'printf.*\\\d\d\d', "don't use 'printf \NNN', use Python"), | 56 (r'printf.*\\\d\d\d', "don't use 'printf \NNN', use Python"), |
57 (r'printf.*\\x', "don't use printf \\x, use Python"), | 57 (r'printf.*\\x', "don't use printf \\x, use Python"), |
61 "use egrep for extended grep syntax"), | 61 "use egrep for extended grep syntax"), |
62 (r'/bin/', "don't use explicit paths for tools"), | 62 (r'/bin/', "don't use explicit paths for tools"), |
63 (r'\$PWD', "don't use $PWD, use `pwd`"), | 63 (r'\$PWD', "don't use $PWD, use `pwd`"), |
64 (r'[^\n]\Z', "no trailing newline"), | 64 (r'[^\n]\Z', "no trailing newline"), |
65 (r'export.*=', "don't export and assign at once"), | 65 (r'export.*=', "don't export and assign at once"), |
66 ('^([^"\'\n]|("[^"\n]*")|(\'[^\'\n]*\'))*\\^', "^ must be quoted"), | 66 ('(^|\n)([^"\'\n]|("[^"\n]*")|(\'[^\'\n]*\'))*\\^', "^ must be quoted"), |
67 (r'^source\b', "don't use 'source', use '.'"), | 67 (r'(^|\n)source\b', "don't use 'source', use '.'"), |
68 (r'touch -d', "don't use 'touch -d', use 'touch -t' instead"), | 68 (r'touch -d', "don't use 'touch -d', use 'touch -t' instead"), |
69 (r'ls\s+[^|\n-]+\s+-', "options to 'ls' must come before filenames"), | 69 (r'ls +[^|\n-]+ +-', "options to 'ls' must come before filenames"), |
70 (r'[^>\n]>\s*\$HGRCPATH', "don't overwrite $HGRCPATH, append to it"), | 70 (r'[^>\n]>\s*\$HGRCPATH', "don't overwrite $HGRCPATH, append to it"), |
71 (r'stop\(\)', "don't use 'stop' as a shell function name"), | 71 (r'stop\(\)', "don't use 'stop' as a shell function name"), |
72 (r'(\[|\btest\b).*-e ', "don't use 'test -e', use 'test -f'"), | 72 (r'(\[|\btest\b).*-e ', "don't use 'test -e', use 'test -f'"), |
73 ], | 73 ], |
74 # warnings | 74 # warnings |
78 testfilters = [ | 78 testfilters = [ |
79 (r"( *)(#([^\n]*\S)?)", repcomment), | 79 (r"( *)(#([^\n]*\S)?)", repcomment), |
80 (r"<<(\S+)((.|\n)*?\n\1)", rephere), | 80 (r"<<(\S+)((.|\n)*?\n\1)", rephere), |
81 ] | 81 ] |
82 | 82 |
83 uprefix = r"^ \$ " | 83 uprefix = r"(^|\n) \$\s*" |
84 uprefixc = r"^ > " | 84 uprefixc = r"(^|\n) > " |
85 utestpats = [ | 85 utestpats = [ |
86 [ | 86 [ |
87 (r'^(\S| $ ).*(\S[ \t]+|^[ \t]+)\n', "trailing whitespace on non-output"), | 87 (r'(^|\n)(\S| $ ).*(\S[ \t]+|^[ \t]+)\n', "trailing whitespace on non-output"), |
88 (uprefix + r'.*\|\s*sed', "use regex test output patterns instead of sed"), | 88 (uprefix + r'.*\|\s*sed', "use regex test output patterns instead of sed"), |
89 (uprefix + r'(true|exit 0)', "explicit zero exit unnecessary"), | 89 (uprefix + r'(true|exit 0)', "explicit zero exit unnecessary"), |
90 (uprefix + r'.*\$\?', "explicit exit code checks unnecessary"), | 90 (uprefix + r'.*\$\?', "explicit exit code checks unnecessary"), |
91 (uprefix + r'.*\|\| echo.*(fail|error)', | 91 (uprefix + r'.*\|\| echo.*(fail|error)', |
92 "explicit exit code checks unnecessary"), | 92 "explicit exit code checks unnecessary"), |
97 [] | 97 [] |
98 ] | 98 ] |
99 | 99 |
100 for i in [0, 1]: | 100 for i in [0, 1]: |
101 for p, m in testpats[i]: | 101 for p, m in testpats[i]: |
102 if p.startswith('^'): | 102 if p.startswith(r'(^|\n)'): |
103 p = uprefix + p[1:] | 103 p = uprefix + p[6:] |
104 else: | 104 else: |
105 p = uprefix + p | 105 p = uprefix + p |
106 utestpats[i].append((p, m)) | 106 utestpats[i].append((p, m)) |
107 | 107 |
108 utestfilters = [ | 108 utestfilters = [ |