diff --git a/contrib/check-code.py b/contrib/check-code.py --- a/contrib/check-code.py +++ b/contrib/check-code.py @@ -45,30 +45,30 @@ testpats = [ [ (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 @@ testfilters = [ (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 @@ utestpats = [ 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 @@ pypats = [ (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 @@ def checkfile(f, logfunc=_defaultlogger. 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 --git a/tests/test-check-pyflakes.t b/tests/test-check-pyflakes.t --- a/tests/test-check-pyflakes.t +++ b/tests/test-check-pyflakes.t @@ -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 --git a/tests/test-hgrc.t b/tests/test-hgrc.t --- a/tests/test-hgrc.t +++ b/tests/test-hgrc.t @@ -3,13 +3,19 @@ Use hgrc within $TESTTMP $ 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 @@ Issue1199: Can't use '%' in hgrc (eg url 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 @@ username expansion $ 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 @@ username expansion 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 @@ HGPLAIN $ 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 @@ plain mode with exceptions > 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 --git a/tests/test-largefiles.t b/tests/test-largefiles.t --- a/tests/test-largefiles.t +++ b/tests/test-largefiles.t @@ -751,7 +751,7 @@ vanilla clients not locked out from larg 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 @@ largefiles clients still work with vanil 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 @@ vanilla clients locked out from largefil 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 @@ largefiles clients refuse to push largef 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 @@ Symlink to a large largefile should beha $ 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 --git a/tests/test-progress.t b/tests/test-progress.t --- a/tests/test-progress.t +++ b/tests/test-progress.t @@ -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 @@ test delay time estimates > 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 --git a/tests/test-subrepo-svn.t b/tests/test-subrepo-svn.t --- a/tests/test-subrepo-svn.t +++ b/tests/test-subrepo-svn.t @@ -496,7 +496,7 @@ test having obstructions when switching 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)'