Mercurial > public > mercurial-scm > hg
comparison contrib/check-code.py @ 16495:5f9835ed3d6d stable
check-code: put grouping around regexps generated from testpats
This removes the pitfall that would make the testpath r'a|b' match 'b' on all
lines in .t tests.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Mon, 23 Apr 2012 01:56:48 +0200 |
parents | e1f0305eabe4 |
children | abbabbbe4ec2 |
comparison
equal
deleted
inserted
replaced
16494:e1f0305eabe4 | 16495:5f9835ed3d6d |
---|---|
41 return m.group(1) + t | 41 return m.group(1) + t |
42 | 42 |
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'^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'sed.*-i', "don't use 'sed -i', use a temporary file"), | 50 (r'sed.*-i', "don't use 'sed -i', use a temporary file"), |
51 (r'echo.*\\n', "don't use 'echo \\n', use printf"), | 51 (r'echo.*\\n', "don't use 'echo \\n', use printf"), |
106 ] | 106 ] |
107 | 107 |
108 for i in [0, 1]: | 108 for i in [0, 1]: |
109 for p, m in testpats[i]: | 109 for p, m in testpats[i]: |
110 if p.startswith(r'^'): | 110 if p.startswith(r'^'): |
111 p = uprefix + p[1:] | 111 p = r"^ \$ (%s)" % p[1:] |
112 else: | 112 else: |
113 p = uprefix + ".*" + p | 113 p = r"^ \$ .*(%s)" % p |
114 utestpats[i].append((p, m)) | 114 utestpats[i].append((p, m)) |
115 | 115 |
116 utestfilters = [ | 116 utestfilters = [ |
117 (r"( *)(#([^\n]*\S)?)", repcomment), | 117 (r"( *)(#([^\n]*\S)?)", repcomment), |
118 ] | 118 ] |