# HG changeset patch # User Matt Mackall # Date 1319754124 18000 # Node ID 695ac6aca77f035cce4040a2c7fed035a8058c15 # Parent f26ed4ea46d8beb03ae521cab2cd1f9bcd44fa38 check-code: fix issues with finding patterns in unified tests, fix tests - old-style patterns without ^ were getting improperly anchored - finditer was matching against beginning of line poorly - \s was matching newlines - [^x] was matching newlines so we: - remove earlier hacks for multiline matching - fix unified test anchoring by adding .* - replace \s with [ \t] - replace [^x] with [^\nx] - force all matches into multiline mode so ^ anchors work This uncovers a number of test issues that are then repaired. diff -r f26ed4ea46d8 -r 695ac6aca77f contrib/check-code.py --- a/contrib/check-code.py Tue Oct 25 11:45:28 2011 -0400 +++ b/contrib/check-code.py Thu Oct 27 17:22:04 2011 -0500 @@ -45,30 +45,30 @@ [ (r'(pushd|popd)', "don't use 'pushd' or 'popd', use 'cd'"), (r'\W\$?\(\([^\)\n]*\)\)', "don't use (()) or $(()), use 'expr'"), - (r'(^|\n)function', "don't use 'function', use old style"), + (r'^function', "don't use 'function', use old style"), (r'grep.*-q', "don't use 'grep -q', redirect to /dev/null"), (r'echo.*\\n', "don't use 'echo \\n', use printf"), (r'echo -n', "don't use 'echo -n', use printf"), - (r'(^|\n)diff.*-\w*N', "don't use 'diff -N'"), - (r'(^| )wc[^|\n]*$', "filter wc output"), + (r'^diff.*-\w*N', "don't use 'diff -N'"), + (r'(^| )wc[^|]*$\n(?!.*\(re\))', "filter wc output"), (r'head -c', "don't use 'head -c', use 'dd'"), (r'ls.*-\w*R', "don't use 'ls -R', use 'find'"), (r'printf.*\\\d\d\d', "don't use 'printf \NNN', use Python"), (r'printf.*\\x', "don't use printf \\x, use Python"), (r'\$\(.*\)', "don't use $(expr), use `expr`"), (r'rm -rf \*', "don't use naked rm -rf, target a directory"), - (r'(^|\|\s*)grep (-\w\s+)*[^|\n]*[(|]\w', + (r'(^|\|\s*)grep (-\w\s+)*[^|]*[(|]\w', "use egrep for extended grep syntax"), (r'/bin/', "don't use explicit paths for tools"), (r'\$PWD', "don't use $PWD, use `pwd`"), (r'[^\n]\Z', "no trailing newline"), (r'export.*=', "don't export and assign at once"), - ('(^|\n)([^"\'\n]|("[^"\n]*")|(\'[^\'\n]*\'))*\\^', "^ must be quoted"), - (r'(^|\n)source\b', "don't use 'source', use '.'"), + (r'^([^"\'\n]|("[^"\n]*")|(\'[^\'\n]*\'))*\\^', "^ must be quoted"), + (r'^source\b', "don't use 'source', use '.'"), (r'touch -d', "don't use 'touch -d', use 'touch -t' instead"), (r'ls +[^|\n-]+ +-', "options to 'ls' must come before filenames"), (r'[^>\n]>\s*\$HGRCPATH', "don't overwrite $HGRCPATH, append to it"), - (r'stop\(\)', "don't use 'stop' as a shell function name"), + (r'^stop\(\)', "don't use 'stop' as a shell function name"), (r'(\[|\btest\b).*-e ', "don't use 'test -e', use 'test -f'"), ], # warnings @@ -80,11 +80,11 @@ (r"<<(\S+)((.|\n)*?\n\1)", rephere), ] -uprefix = r"(^|\n) \$\s*" -uprefixc = r"(^|\n) > " +uprefix = r"^ \$ " +uprefixc = r"^ > " utestpats = [ [ - (r'(^|\n)(\S| $ ).*(\S[ \t]+|^[ \t]+)\n', "trailing whitespace on non-output"), + (r'^(\S| $ ).*(\S[ \t]+|^[ \t]+)\n', "trailing whitespace on non-output"), (uprefix + r'.*\|\s*sed', "use regex test output patterns instead of sed"), (uprefix + r'(true|exit 0)', "explicit zero exit unnecessary"), (uprefix + r'.*\$\?', "explicit exit code checks unnecessary"), @@ -99,10 +99,10 @@ for i in [0, 1]: for p, m in testpats[i]: - if p.startswith(r'(^|\n)'): - p = uprefix + p[6:] + if p.startswith(r'^'): + p = uprefix + p[1:] else: - p = uprefix + p + p = uprefix + ".*" + p utestpats[i].append((p, m)) utestfilters = [ @@ -123,10 +123,10 @@ (r'\w,\w', "missing whitespace after ,"), (r'\w[+/*\-<>]\w', "missing whitespace in expression"), (r'^\s+\w+=\w+[^,)\n]$', "missing whitespace in assignment"), - (r'(?m)(\s+)try:\n((?:\n|\1\s.*\n)+?)\1except.*?:\n' + (r'(\s+)try:\n((?:\n|\1\s.*\n)+?)\1except.*?:\n' r'((?:\n|\1\s.*\n)+?)\1finally:', 'no try/except/finally in Py2.4'), (r'.{85}', "line too long"), - (r'(?m) x+[xo][\'"]\n\s+[\'"]x', 'string join across lines with no space'), + (r' x+[xo][\'"]\n\s+[\'"]x', 'string join across lines with no space'), (r'[^\n]\Z', "no trailing newline"), (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"), # (r'^\s+[^_ \n][^_. \n]+_[^_\n]+\s*=', "don't use underbars in identifiers"), @@ -344,9 +344,18 @@ prelines = None errors = [] for p, msg in pats: + # fix-up regexes for multiline searches + po = p + # \s doesn't match \n + p = re.sub(r'(?', p + pos = 0 n = 0 - for m in re.finditer(p, post): + for m in re.finditer(p, post, re.MULTILINE): if prelines is None: prelines = pre.splitlines() postlines = post.splitlines(True) diff -r f26ed4ea46d8 -r 695ac6aca77f tests/test-check-pyflakes.t --- a/tests/test-check-pyflakes.t Tue Oct 25 11:45:28 2011 -0400 +++ b/tests/test-check-pyflakes.t Thu Oct 27 17:22:04 2011 -0500 @@ -1,5 +1,5 @@ $ "$TESTDIR/hghave" pyflakes || exit 80 - $ cd $(dirname $TESTDIR) + $ cd `dirname $TESTDIR` $ pyflakes mercurial hgext 2>&1 | $TESTDIR/filterpyflakes.py hgext/inotify/linux/__init__.py:*: 'from _inotify import *' used; unable to detect undefined names (glob) diff -r f26ed4ea46d8 -r 695ac6aca77f tests/test-hgrc.t --- a/tests/test-hgrc.t Tue Oct 25 11:45:28 2011 -0400 +++ b/tests/test-hgrc.t Thu Oct 27 17:22:04 2011 -0500 @@ -3,13 +3,19 @@ $ HGRCPATH=`pwd`/hgrc $ export HGRCPATH +Use an alternate var for scribbling on hgrc to keep check-code from +complaining about the important settings we may be overwriting: + + $ HGRC=`pwd`/hgrc + $ export HGRC + Basic syntax error - $ echo "invalid" > $HGRCPATH + $ echo "invalid" > $HGRC $ hg version hg: parse error at $TESTTMP/hgrc:1: invalid [255] - $ echo "" > $HGRCPATH + $ echo "" > $HGRC Issue1199: Can't use '%' in hgrc (eg url encoded username) @@ -30,21 +36,21 @@ issue1829: wrong indentation - $ echo '[foo]' > $HGRCPATH - $ echo ' x = y' >> $HGRCPATH + $ echo '[foo]' > $HGRC + $ echo ' x = y' >> $HGRC $ hg version hg: parse error at $TESTTMP/hgrc:2: x = y [255] $ python -c "print '[foo]\nbar = a\n b\n c \n de\n fg \nbaz = bif cb \n'" \ - > > $HGRCPATH + > > $HGRC $ hg showconfig foo foo.bar=a\nb\nc\nde\nfg foo.baz=bif cb $ FAKEPATH=/path/to/nowhere $ export FAKEPATH - $ echo '%include $FAKEPATH/no-such-file' > $HGRCPATH + $ echo '%include $FAKEPATH/no-such-file' > $HGRC $ hg version Mercurial Distributed SCM (version *) (glob) (see http://mercurial.selenic.com for more information) @@ -75,8 +81,8 @@ $ FAKEUSER='John Doe' $ export FAKEUSER - $ echo '[ui]' > $HGRCPATH - $ echo 'username = $FAKEUSER' >> $HGRCPATH + $ echo '[ui]' > $HGRC + $ echo 'username = $FAKEUSER' >> $HGRC $ hg init usertest $ cd usertest @@ -95,10 +101,10 @@ showconfig with multiple arguments - $ echo "[alias]" > $HGRCPATH - $ echo "log = log -g" >> $HGRCPATH - $ echo "[defaults]" >> $HGRCPATH - $ echo "identify = -n" >> $HGRCPATH + $ echo "[alias]" > $HGRC + $ echo "log = log -g" >> $HGRC + $ echo "[defaults]" >> $HGRC + $ echo "identify = -n" >> $HGRC $ hg showconfig alias defaults alias.log=log -g defaults.identify=-n @@ -113,19 +119,19 @@ $ cd .. $ p=`pwd` - $ echo "[ui]" > $HGRCPATH - $ echo "debug=true" >> $HGRCPATH - $ echo "fallbackencoding=ASCII" >> $HGRCPATH - $ echo "quiet=true" >> $HGRCPATH - $ echo "slash=true" >> $HGRCPATH - $ echo "traceback=true" >> $HGRCPATH - $ echo "verbose=true" >> $HGRCPATH - $ echo "style=~/.hgstyle" >> $HGRCPATH - $ echo "logtemplate={node}" >> $HGRCPATH - $ echo "[defaults]" >> $HGRCPATH - $ echo "identify=-n" >> $HGRCPATH - $ echo "[alias]" >> $HGRCPATH - $ echo "log=log -g" >> $HGRCPATH + $ echo "[ui]" > $HGRC + $ echo "debug=true" >> $HGRC + $ echo "fallbackencoding=ASCII" >> $HGRC + $ echo "quiet=true" >> $HGRC + $ echo "slash=true" >> $HGRC + $ echo "traceback=true" >> $HGRC + $ echo "verbose=true" >> $HGRC + $ echo "style=~/.hgstyle" >> $HGRC + $ echo "logtemplate={node}" >> $HGRC + $ echo "[defaults]" >> $HGRC + $ echo "identify=-n" >> $HGRC + $ echo "[alias]" >> $HGRC + $ echo "log=log -g" >> $HGRC customized hgrc @@ -158,8 +164,8 @@ > def uisetup(ui): > ui.write('plain: %r\n' % ui.plain()) > EOF - $ echo "[extensions]" >> $HGRCPATH - $ echo "plain=./plain.py" >> $HGRCPATH + $ echo "[extensions]" >> $HGRC + $ echo "plain=./plain.py" >> $HGRC $ HGPLAINEXCEPT=; export HGPLAINEXCEPT $ hg showconfig --config ui.traceback=True --debug plain: True diff -r f26ed4ea46d8 -r 695ac6aca77f tests/test-largefiles.t --- a/tests/test-largefiles.t Tue Oct 25 11:45:28 2011 -0400 +++ b/tests/test-largefiles.t Thu Oct 27 17:22:04 2011 -0500 @@ -751,7 +751,7 @@ added 1 changesets with 1 changes to 1 files updating to branch default 1 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ kill $(cat serve.pid) + $ kill `cat serve.pid` largefiles clients still work with vanilla servers $ hg --config extensions.largefiles=! serve -R r1 -d -p 8001 --pid-file serve.pid @@ -763,7 +763,7 @@ added 1 changesets with 1 changes to 1 files updating to branch default 1 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ kill $(cat serve.pid) + $ kill `cat serve.pid` vanilla clients locked out from largefiles http repos $ mkdir r4 @@ -781,7 +781,7 @@ Please enable it in your Mercurial config file. [255] - $ kill $(cat serve.pid) + $ kill `cat serve.pid` vanilla clients locked out from largefiles ssh repos $ hg --config extensions.largefiles=! clone -e "python $TESTDIR/dummyssh" ssh://user@dummy/r4 r5 @@ -819,7 +819,7 @@ abort: http://localhost:8001/ does not appear to be a largefile store [255] $ cd .. - $ kill $(cat serve.pid) + $ kill `cat serve.pid` $ cd .. @@ -864,13 +864,13 @@ $ hg commit -m "commit a large symlink" $ rm -f largelink $ hg up >/dev/null - $ test -e largelink + $ test -f largelink [1] $ test -L largelink [1] $ rm -f largelink # make next part of the test independent of the previous $ hg up -C >/dev/null - $ test -e largelink + $ test -f largelink $ test -L largelink $ cd .. diff -r f26ed4ea46d8 -r 695ac6aca77f tests/test-progress.t --- a/tests/test-progress.t Tue Oct 25 11:45:28 2011 -0400 +++ b/tests/test-progress.t Thu Oct 27 17:22:04 2011 -0500 @@ -35,6 +35,7 @@ > } > EOF + $ cp $HGRCPATH $HGRCPATH.orig $ echo "[extensions]" >> $HGRCPATH $ echo "progress=" >> $HGRCPATH $ echo "loop=`pwd`/loop.py" >> $HGRCPATH @@ -162,7 +163,8 @@ > time.time = mocktime(int(os.environ.get('MOCKTIME', '11'))) > EOF - $ echo "[extensions]" > $HGRCPATH + $ cp $HGRCPATH.orig $HGRCPATH + $ echo "[extensions]" >> $HGRCPATH $ echo "mocktime=`pwd`/mocktime.py" >> $HGRCPATH $ echo "progress=" >> $HGRCPATH $ echo "loop=`pwd`/loop.py" >> $HGRCPATH diff -r f26ed4ea46d8 -r 695ac6aca77f tests/test-subrepo-svn.t --- a/tests/test-subrepo-svn.t Tue Oct 25 11:45:28 2011 -0400 +++ b/tests/test-subrepo-svn.t Thu Oct 27 17:22:04 2011 -0500 @@ -496,7 +496,7 @@ 0 files updated, 0 files merged, 0 files removed, 0 files unresolved $ echo "obstruct = [svn] $SVNREPO/externals" >> .hgsub $ svn co -r5 --quiet "$SVNREPO"/externals obstruct - $ hg commit -m 'Start making obstructed wc' + $ hg commit -m 'Start making obstructed working copy' committing subrepository obstruct $ hg book other $ hg co -r 'p1(tip)'