##// END OF EJS Templates
check-code: fix issues with finding patterns in unified tests, fix tests...
Matt Mackall -
r15372:695ac6ac stable
parent child Browse files
Show More
@@ -45,30 +45,30 b' 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'(^|\n)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'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'(^|\n)diff.*-\w*N', "don't use 'diff -N'"),
52 (r'^diff.*-\w*N', "don't use 'diff -N'"),
53 (r'(^| )wc[^|\n]*$', "filter wc output"),
53 (r'(^| )wc[^|]*$\n(?!.*\(re\))', "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"),
58 (r'\$\(.*\)', "don't use $(expr), use `expr`"),
58 (r'\$\(.*\)', "don't use $(expr), use `expr`"),
59 (r'rm -rf \*', "don't use naked rm -rf, target a directory"),
59 (r'rm -rf \*', "don't use naked rm -rf, target a directory"),
60 (r'(^|\|\s*)grep (-\w\s+)*[^|\n]*[(|]\w',
60 (r'(^|\|\s*)grep (-\w\s+)*[^|]*[(|]\w',
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]*")|(\'[^\'\n]*\'))*\\^', "^ must be quoted"),
66 (r'^([^"\'\n]|("[^"\n]*")|(\'[^\'\n]*\'))*\\^', "^ must be quoted"),
67 (r'(^|\n)source\b', "don't use 'source', use '.'"),
67 (r'^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 +[^|\n-]+ +-', "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
@@ -80,11 +80,11 b' testfilters = ['
80 (r"<<(\S+)((.|\n)*?\n\1)", rephere),
80 (r"<<(\S+)((.|\n)*?\n\1)", rephere),
81 ]
81 ]
82
82
83 uprefix = r"(^|\n) \$\s*"
83 uprefix = r"^ \$ "
84 uprefixc = r"(^|\n) > "
84 uprefixc = r"^ > "
85 utestpats = [
85 utestpats = [
86 [
86 [
87 (r'(^|\n)(\S| $ ).*(\S[ \t]+|^[ \t]+)\n', "trailing whitespace on non-output"),
87 (r'^(\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"),
@@ -99,10 +99,10 b' utestpats = ['
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(r'(^|\n)'):
102 if p.startswith(r'^'):
103 p = uprefix + p[6:]
103 p = uprefix + p[1:]
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 = [
@@ -123,10 +123,10 b' pypats = ['
123 (r'\w,\w', "missing whitespace after ,"),
123 (r'\w,\w', "missing whitespace after ,"),
124 (r'\w[+/*\-<>]\w', "missing whitespace in expression"),
124 (r'\w[+/*\-<>]\w', "missing whitespace in expression"),
125 (r'^\s+\w+=\w+[^,)\n]$', "missing whitespace in assignment"),
125 (r'^\s+\w+=\w+[^,)\n]$', "missing whitespace in assignment"),
126 (r'(?m)(\s+)try:\n((?:\n|\1\s.*\n)+?)\1except.*?:\n'
126 (r'(\s+)try:\n((?:\n|\1\s.*\n)+?)\1except.*?:\n'
127 r'((?:\n|\1\s.*\n)+?)\1finally:', 'no try/except/finally in Py2.4'),
127 r'((?:\n|\1\s.*\n)+?)\1finally:', 'no try/except/finally in Py2.4'),
128 (r'.{85}', "line too long"),
128 (r'.{85}', "line too long"),
129 (r'(?m) x+[xo][\'"]\n\s+[\'"]x', 'string join across lines with no space'),
129 (r' x+[xo][\'"]\n\s+[\'"]x', 'string join across lines with no space'),
130 (r'[^\n]\Z', "no trailing newline"),
130 (r'[^\n]\Z', "no trailing newline"),
131 (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"),
131 (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"),
132 # (r'^\s+[^_ \n][^_. \n]+_[^_\n]+\s*=', "don't use underbars in identifiers"),
132 # (r'^\s+[^_ \n][^_. \n]+_[^_\n]+\s*=', "don't use underbars in identifiers"),
@@ -344,9 +344,18 b' def checkfile(f, logfunc=_defaultlogger.'
344 prelines = None
344 prelines = None
345 errors = []
345 errors = []
346 for p, msg in pats:
346 for p, msg in pats:
347 # fix-up regexes for multiline searches
348 po = p
349 # \s doesn't match \n
350 p = re.sub(r'(?<!\\)\\s', r'[ \\t]', p)
351 # [^...] doesn't match newline
352 p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p)
353
354 #print po, '=>', p
355
347 pos = 0
356 pos = 0
348 n = 0
357 n = 0
349 for m in re.finditer(p, post):
358 for m in re.finditer(p, post, re.MULTILINE):
350 if prelines is None:
359 if prelines is None:
351 prelines = pre.splitlines()
360 prelines = pre.splitlines()
352 postlines = post.splitlines(True)
361 postlines = post.splitlines(True)
@@ -1,5 +1,5 b''
1 $ "$TESTDIR/hghave" pyflakes || exit 80
1 $ "$TESTDIR/hghave" pyflakes || exit 80
2 $ cd $(dirname $TESTDIR)
2 $ cd `dirname $TESTDIR`
3 $ pyflakes mercurial hgext 2>&1 | $TESTDIR/filterpyflakes.py
3 $ pyflakes mercurial hgext 2>&1 | $TESTDIR/filterpyflakes.py
4 hgext/inotify/linux/__init__.py:*: 'from _inotify import *' used; unable to detect undefined names (glob)
4 hgext/inotify/linux/__init__.py:*: 'from _inotify import *' used; unable to detect undefined names (glob)
5
5
@@ -3,13 +3,19 b' Use hgrc within $TESTTMP'
3 $ HGRCPATH=`pwd`/hgrc
3 $ HGRCPATH=`pwd`/hgrc
4 $ export HGRCPATH
4 $ export HGRCPATH
5
5
6 Use an alternate var for scribbling on hgrc to keep check-code from
7 complaining about the important settings we may be overwriting:
8
9 $ HGRC=`pwd`/hgrc
10 $ export HGRC
11
6 Basic syntax error
12 Basic syntax error
7
13
8 $ echo "invalid" > $HGRCPATH
14 $ echo "invalid" > $HGRC
9 $ hg version
15 $ hg version
10 hg: parse error at $TESTTMP/hgrc:1: invalid
16 hg: parse error at $TESTTMP/hgrc:1: invalid
11 [255]
17 [255]
12 $ echo "" > $HGRCPATH
18 $ echo "" > $HGRC
13
19
14 Issue1199: Can't use '%' in hgrc (eg url encoded username)
20 Issue1199: Can't use '%' in hgrc (eg url encoded username)
15
21
@@ -30,21 +36,21 b" Issue1199: Can't use '%' in hgrc (eg url"
30
36
31 issue1829: wrong indentation
37 issue1829: wrong indentation
32
38
33 $ echo '[foo]' > $HGRCPATH
39 $ echo '[foo]' > $HGRC
34 $ echo ' x = y' >> $HGRCPATH
40 $ echo ' x = y' >> $HGRC
35 $ hg version
41 $ hg version
36 hg: parse error at $TESTTMP/hgrc:2: x = y
42 hg: parse error at $TESTTMP/hgrc:2: x = y
37 [255]
43 [255]
38
44
39 $ python -c "print '[foo]\nbar = a\n b\n c \n de\n fg \nbaz = bif cb \n'" \
45 $ python -c "print '[foo]\nbar = a\n b\n c \n de\n fg \nbaz = bif cb \n'" \
40 > > $HGRCPATH
46 > > $HGRC
41 $ hg showconfig foo
47 $ hg showconfig foo
42 foo.bar=a\nb\nc\nde\nfg
48 foo.bar=a\nb\nc\nde\nfg
43 foo.baz=bif cb
49 foo.baz=bif cb
44
50
45 $ FAKEPATH=/path/to/nowhere
51 $ FAKEPATH=/path/to/nowhere
46 $ export FAKEPATH
52 $ export FAKEPATH
47 $ echo '%include $FAKEPATH/no-such-file' > $HGRCPATH
53 $ echo '%include $FAKEPATH/no-such-file' > $HGRC
48 $ hg version
54 $ hg version
49 Mercurial Distributed SCM (version *) (glob)
55 Mercurial Distributed SCM (version *) (glob)
50 (see http://mercurial.selenic.com for more information)
56 (see http://mercurial.selenic.com for more information)
@@ -75,8 +81,8 b' username expansion'
75
81
76 $ FAKEUSER='John Doe'
82 $ FAKEUSER='John Doe'
77 $ export FAKEUSER
83 $ export FAKEUSER
78 $ echo '[ui]' > $HGRCPATH
84 $ echo '[ui]' > $HGRC
79 $ echo 'username = $FAKEUSER' >> $HGRCPATH
85 $ echo 'username = $FAKEUSER' >> $HGRC
80
86
81 $ hg init usertest
87 $ hg init usertest
82 $ cd usertest
88 $ cd usertest
@@ -95,10 +101,10 b' username expansion'
95
101
96 showconfig with multiple arguments
102 showconfig with multiple arguments
97
103
98 $ echo "[alias]" > $HGRCPATH
104 $ echo "[alias]" > $HGRC
99 $ echo "log = log -g" >> $HGRCPATH
105 $ echo "log = log -g" >> $HGRC
100 $ echo "[defaults]" >> $HGRCPATH
106 $ echo "[defaults]" >> $HGRC
101 $ echo "identify = -n" >> $HGRCPATH
107 $ echo "identify = -n" >> $HGRC
102 $ hg showconfig alias defaults
108 $ hg showconfig alias defaults
103 alias.log=log -g
109 alias.log=log -g
104 defaults.identify=-n
110 defaults.identify=-n
@@ -113,19 +119,19 b' HGPLAIN'
113
119
114 $ cd ..
120 $ cd ..
115 $ p=`pwd`
121 $ p=`pwd`
116 $ echo "[ui]" > $HGRCPATH
122 $ echo "[ui]" > $HGRC
117 $ echo "debug=true" >> $HGRCPATH
123 $ echo "debug=true" >> $HGRC
118 $ echo "fallbackencoding=ASCII" >> $HGRCPATH
124 $ echo "fallbackencoding=ASCII" >> $HGRC
119 $ echo "quiet=true" >> $HGRCPATH
125 $ echo "quiet=true" >> $HGRC
120 $ echo "slash=true" >> $HGRCPATH
126 $ echo "slash=true" >> $HGRC
121 $ echo "traceback=true" >> $HGRCPATH
127 $ echo "traceback=true" >> $HGRC
122 $ echo "verbose=true" >> $HGRCPATH
128 $ echo "verbose=true" >> $HGRC
123 $ echo "style=~/.hgstyle" >> $HGRCPATH
129 $ echo "style=~/.hgstyle" >> $HGRC
124 $ echo "logtemplate={node}" >> $HGRCPATH
130 $ echo "logtemplate={node}" >> $HGRC
125 $ echo "[defaults]" >> $HGRCPATH
131 $ echo "[defaults]" >> $HGRC
126 $ echo "identify=-n" >> $HGRCPATH
132 $ echo "identify=-n" >> $HGRC
127 $ echo "[alias]" >> $HGRCPATH
133 $ echo "[alias]" >> $HGRC
128 $ echo "log=log -g" >> $HGRCPATH
134 $ echo "log=log -g" >> $HGRC
129
135
130 customized hgrc
136 customized hgrc
131
137
@@ -158,8 +164,8 b' plain mode with exceptions'
158 > def uisetup(ui):
164 > def uisetup(ui):
159 > ui.write('plain: %r\n' % ui.plain())
165 > ui.write('plain: %r\n' % ui.plain())
160 > EOF
166 > EOF
161 $ echo "[extensions]" >> $HGRCPATH
167 $ echo "[extensions]" >> $HGRC
162 $ echo "plain=./plain.py" >> $HGRCPATH
168 $ echo "plain=./plain.py" >> $HGRC
163 $ HGPLAINEXCEPT=; export HGPLAINEXCEPT
169 $ HGPLAINEXCEPT=; export HGPLAINEXCEPT
164 $ hg showconfig --config ui.traceback=True --debug
170 $ hg showconfig --config ui.traceback=True --debug
165 plain: True
171 plain: True
@@ -751,7 +751,7 b' vanilla clients not locked out from larg'
751 added 1 changesets with 1 changes to 1 files
751 added 1 changesets with 1 changes to 1 files
752 updating to branch default
752 updating to branch default
753 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
753 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
754 $ kill $(cat serve.pid)
754 $ kill `cat serve.pid`
755
755
756 largefiles clients still work with vanilla servers
756 largefiles clients still work with vanilla servers
757 $ hg --config extensions.largefiles=! serve -R r1 -d -p 8001 --pid-file serve.pid
757 $ hg --config extensions.largefiles=! serve -R r1 -d -p 8001 --pid-file serve.pid
@@ -763,7 +763,7 b' largefiles clients still work with vanil'
763 added 1 changesets with 1 changes to 1 files
763 added 1 changesets with 1 changes to 1 files
764 updating to branch default
764 updating to branch default
765 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
765 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
766 $ kill $(cat serve.pid)
766 $ kill `cat serve.pid`
767
767
768 vanilla clients locked out from largefiles http repos
768 vanilla clients locked out from largefiles http repos
769 $ mkdir r4
769 $ mkdir r4
@@ -781,7 +781,7 b' vanilla clients locked out from largefil'
781
781
782 Please enable it in your Mercurial config file.
782 Please enable it in your Mercurial config file.
783 [255]
783 [255]
784 $ kill $(cat serve.pid)
784 $ kill `cat serve.pid`
785
785
786 vanilla clients locked out from largefiles ssh repos
786 vanilla clients locked out from largefiles ssh repos
787 $ hg --config extensions.largefiles=! clone -e "python $TESTDIR/dummyssh" ssh://user@dummy/r4 r5
787 $ hg --config extensions.largefiles=! clone -e "python $TESTDIR/dummyssh" ssh://user@dummy/r4 r5
@@ -819,7 +819,7 b' largefiles clients refuse to push largef'
819 abort: http://localhost:8001/ does not appear to be a largefile store
819 abort: http://localhost:8001/ does not appear to be a largefile store
820 [255]
820 [255]
821 $ cd ..
821 $ cd ..
822 $ kill $(cat serve.pid)
822 $ kill `cat serve.pid`
823
823
824 $ cd ..
824 $ cd ..
825
825
@@ -864,13 +864,13 b' Symlink to a large largefile should beha'
864 $ hg commit -m "commit a large symlink"
864 $ hg commit -m "commit a large symlink"
865 $ rm -f largelink
865 $ rm -f largelink
866 $ hg up >/dev/null
866 $ hg up >/dev/null
867 $ test -e largelink
867 $ test -f largelink
868 [1]
868 [1]
869 $ test -L largelink
869 $ test -L largelink
870 [1]
870 [1]
871 $ rm -f largelink # make next part of the test independent of the previous
871 $ rm -f largelink # make next part of the test independent of the previous
872 $ hg up -C >/dev/null
872 $ hg up -C >/dev/null
873 $ test -e largelink
873 $ test -f largelink
874 $ test -L largelink
874 $ test -L largelink
875 $ cd ..
875 $ cd ..
876
876
@@ -35,6 +35,7 b''
35 > }
35 > }
36 > EOF
36 > EOF
37
37
38 $ cp $HGRCPATH $HGRCPATH.orig
38 $ echo "[extensions]" >> $HGRCPATH
39 $ echo "[extensions]" >> $HGRCPATH
39 $ echo "progress=" >> $HGRCPATH
40 $ echo "progress=" >> $HGRCPATH
40 $ echo "loop=`pwd`/loop.py" >> $HGRCPATH
41 $ echo "loop=`pwd`/loop.py" >> $HGRCPATH
@@ -162,7 +163,8 b' test delay time estimates'
162 > time.time = mocktime(int(os.environ.get('MOCKTIME', '11')))
163 > time.time = mocktime(int(os.environ.get('MOCKTIME', '11')))
163 > EOF
164 > EOF
164
165
165 $ echo "[extensions]" > $HGRCPATH
166 $ cp $HGRCPATH.orig $HGRCPATH
167 $ echo "[extensions]" >> $HGRCPATH
166 $ echo "mocktime=`pwd`/mocktime.py" >> $HGRCPATH
168 $ echo "mocktime=`pwd`/mocktime.py" >> $HGRCPATH
167 $ echo "progress=" >> $HGRCPATH
169 $ echo "progress=" >> $HGRCPATH
168 $ echo "loop=`pwd`/loop.py" >> $HGRCPATH
170 $ echo "loop=`pwd`/loop.py" >> $HGRCPATH
@@ -496,7 +496,7 b' test having obstructions when switching '
496 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
496 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
497 $ echo "obstruct = [svn] $SVNREPO/externals" >> .hgsub
497 $ echo "obstruct = [svn] $SVNREPO/externals" >> .hgsub
498 $ svn co -r5 --quiet "$SVNREPO"/externals obstruct
498 $ svn co -r5 --quiet "$SVNREPO"/externals obstruct
499 $ hg commit -m 'Start making obstructed wc'
499 $ hg commit -m 'Start making obstructed working copy'
500 committing subrepository obstruct
500 committing subrepository obstruct
501 $ hg book other
501 $ hg book other
502 $ hg co -r 'p1(tip)'
502 $ hg co -r 'p1(tip)'
General Comments 0
You need to be logged in to leave comments. Login now