Commit Graph

326 Commits

Author SHA1 Message Date
Durham Goode
7c43ca7c6b hg: fix tests on OSX
Summary: sed -i without arguments doesn't work on OSX.

Reviewed By: farnz

Differential Revision: D7195193

fbshipit-source-id: a8eead927c94404a37ce5df956de82d29bc1b6a8
2018-04-13 21:51:24 -07:00
Jun Wu
884aac4596 xdiff: add a python wrapper
Summary:
Implement a `mercurial.cext.xdiff` module that exposes the xdiff algorithm.

`xdiff.blocks` should be a drop-in replacement for `bdiff.blocks`.

In theory we can change the pure C version of `bdiff.c` directly. However
that means we lose bdiff entirely. It seems more flexible to have both at
the same time so they can be easily switched via Python code. Hence the
Python module approach.

Reviewed By: ryanmce

Differential Revision: D7135205

fbshipit-source-id: 48cd3b5be7fd5ef41b64eab6c76a5c8a6ce99e05
2018-04-13 21:51:21 -07:00
Jun Wu
c9f1645a98 check-code: fix foo_bar naming detection and add a whitelist
Summary:
This patch fixes the regex. There are too many methods with underscores.
So a whitelist was added to avoid unnecessary churn of line numbers in
test-check-code.t.

Reviewed By: ryanmce

Differential Revision: D6937917

fbshipit-source-id: 9b7816278fc6f414c21f921b67d1cbb6a735a30f
2018-04-13 21:51:09 -07:00
Jun Wu
88dccd4a14 test-check: port some check-commit rules to check-code
Summary:
Port the double blank line and "foobar" naming rules to check-code.
check-commit checks "changes" while check-code checks "snapshot".

Checking changes would have a couple of disadvantages:
- No check after code is committed
- Could have difficulity dealing with commits involving other changes
  in a mono repo.

Facebook
Context: https://fb.facebook.com/groups/scm/permalink/1558174000898881

Reviewed By: DurhamG

Differential Revision: D6928820

fbshipit-source-id: 9ea998731778150b60112840bce702d9584ba15b
2018-04-13 21:51:08 -07:00
Jun Wu
4a7b28d08b serve: assign hg serve ports dynamically in tests
Summary:
Previously `hg server` uses `HGPORT` that might be in use. This patch uses
`-p 0 --port-file ...` so `hg server` always gets assigned a free port.

The change was first made by the following Ruby script:

```
re = /^  \$ hg serve(.*) -p \$(HGPORT[12]?) (.*[^\\])$\n  \$/
Dir['*.t'].each do |path|
  old = File.read(path)
  new = old.lines.map do |l|
    next l if l[/\(glob\)/] or not l['$HGPORT'] or l[/^  [$>]/]
    "#{l.chomp} (glob)\n"
  end.join.gsub re, <<-'EOS'.chomp
  $ hg serve\1 -p 0 --port-file $TESTTMP/.port \3
  $ \2=`cat $TESTTMP/.port`
  $
  EOS
  File.write(path, new) if old != new
end
```

Then there are some manual changes:

run-tests.py: It now treats `$HGPORT` in output as glob pattern `*`, since
it does not know the assigned value in tests.

test-bookmarks-pushpull.t, test-https.t: Some `hg pull`s were changed to use
explicit paths instead of relying on `.hgrc` since the test restarts the
server and `.hg/hgrc` having an outdated URL.

test-schemes.t: The test writes `$HGPORT` to `.hgrc` before assigning it.
Changed the order so the correct `$HGPORT` is written.

test-patchbomb-tls.t: Changed `(?) (glob)` to `(glob) (?)`.

Reviewed By: DurhamG

Differential Revision: D6925398

fbshipit-source-id: d5c10476f43ce23f9e99618807580cf8ba92595c
2018-04-13 21:51:07 -07:00
Matt Harbison
17e2258c44 tests: fix the check-code rule for testing non-existent files
I missed this in d3e2086bc411.
2017-12-16 12:34:40 -05:00
Matt Harbison
44a151c9d6 tests: convert the 'file://\$TESTTMP' rule to an automatic substitution
The rule only triggered on non Windows platforms, even though Windows also
required an adjustment.  Automatic seems better.

The aggressive globbing in test-subrepo-svn.t was found and rewritten by the
substitution.
2017-12-16 11:32:10 -05:00
Yuya Nishihara
3a0cd26f9a check-code: remove unused variable 'winglobmsg'
Follows up 217bd5cb0914.
2017-12-14 22:26:46 +09:00
Matt Harbison
1c506fb28b check-code: drop the rules for adding (glob) for Windows paths
I'll probably resurrect at least some of these as replacement patterns to switch
'\' to '/' when creating tests at some point.  But since this subset of globs
isn't needed anymore after 1c1248ea2685, and the rules are blocking the glob
removal, just drop them for now.  It probably isn't worth turning them into
checks for unnecessary globs being present.
2017-12-10 22:45:35 -05:00
Yuya Nishihara
2cc325585b check-code: allow tabs in heredoc 2017-12-09 00:39:15 +09:00
Augie Fackler
b9c19b5c5b contrib: ban find(1)'s -printf operator, as it is a GNU-ism
Differential Revision: https://phab.mercurial-scm.org/D1598
2017-12-05 16:44:20 -05:00
Augie Fackler
60b36d6799 contrib: improve check-code ban on $LOCALIP in output without (glob)
Differential Revision: https://phab.mercurial-scm.org/D1553
2017-11-29 17:06:45 -05:00
Anton Shestakov
67a7ac7635 check-code: grep's context flags don't need an extra space before number
A bit of useless trivia found while researching this: OpenBSD's grep's -C has a
default value (of 2) and disallows space before the argument (while -A and -B
allow).
2017-11-18 13:00:47 +08:00
Augie Fackler
81fb7bb488 contrib: remove check-code rule about indentation
We're moving towards a clang-format world, and clang-format is able to
wrap argument lists with spaces reliably, while still enforcing tabs
globally. Let's let clang-format do its job, and not do as much
C-style enforcement with regular expressions.

Differential Revision: https://phab.mercurial-scm.org/D1130
2017-10-16 11:43:41 -04:00
Jun Wu
b882ee58de check-code: suggest pycompat.is(posix|windows|darwin)
Differential Revision: https://phab.mercurial-scm.org/D1037
2017-10-12 09:34:58 -07:00
Jun Wu
6c6917ead6 check-code: forbid platform.system()
See the previous patches for the reason.

Differential Revision: https://phab.mercurial-scm.org/D1021
2017-10-11 17:42:57 -07:00
Augie Fackler
7bdb9aa337 contrib: add check-code rule banning use of readlink
readlink doesn't always exist, such as on Solaris-derived platforms.

Differential Revision: https://phab.mercurial-scm.org/D1000
2017-10-11 03:48:11 -07:00
Saurabh Singh
bacb1366fc test-check-code: fail new commits which use 'atexit' instead of 'ui.atexit'
Callbacks registered with 'atexit' are sometimes not called (like when
hg aborts and calls os._exit). On the other hand, callbacks registered with
'ui.atexit' are called in most cases. Therefore, encouraging the use of
'ui.atexit' by failing the test 'test-check-code.t' appropriately.

Test Plan:
Ran the test 'test-check-code.t' after importing 'atexit' in one of
the py files and confirmed that the test fails.

Differential Revision: https://phab.mercurial-scm.org/D961
2017-10-05 14:18:55 -07:00
Siddharth Agarwal
3a77727405 check-code: allow an exception for camelcase where required
unittest has a `maxDiff` parameter which has to be set to `None` in order for
large enough failure diffs to be displayed. Add a comment to disable the
camelcase check for `self.maxDiff = None` lines.

Differential Revision: https://phab.mercurial-scm.org/D895
2017-10-02 02:34:47 -07:00
Augie Fackler
074e849cb3 contrib: add a check to check-code to ban superfluous pass statements
These have annoyed me for a long time, and I'm tired of commenting on
them in reviews. I'm sorry for how complicated the regular expression
is, but I was too lazy to go crack open pylint's code and add the
check there.
2017-09-29 11:55:44 -04:00
Martin von Zweigbergk
78fb62643c check-code: fix incorrect capitalization in camelcase regex
This was found internally at Google as part of a monorepo-wide
cleanup.

Differential Revision: https://phab.mercurial-scm.org/D637
2017-09-06 08:22:54 -07:00
Jun Wu
ada59ccd75 check-code: forbid "\S" in egrep regular expression
BSD `egrep` does not like it. So let's forbid it.

Differential Revision: https://phab.mercurial-scm.org/D610
2017-09-01 16:44:30 -07:00
Jun Wu
e4fdb2e534 check-code: forbid using bash in shebang
Some platforms (ex. FreeBSD) do not have `bash` by default. Therefore it
should not be used in test scripts.

Differential Revision: https://phab.mercurial-scm.org/D609
2017-09-01 15:47:32 -07:00
Augie Fackler
a8e43e5637 check-code: prohibit if False antipattern
Differential Revision: https://phab.mercurial-scm.org/D20
2017-07-07 15:11:11 -04:00
Augie Fackler
04ece00541 contrib: widen "direct use of python" net again
I think I've now caught all of them.

Differential Revision: https://phab.mercurial-scm.org/D15
2017-07-06 15:15:02 -04:00
Augie Fackler
dc6a89d633 contrib: widen the "don't use python" net a little
I'm still cleaning this up, but it's easier to do in bite-size chunks
like this than all at once. The negative lookahead avoids one false
positive category from some output related to finding Subversion
bindings.

Differential Revision: https://phab.mercurial-scm.org/D13
2017-06-20 17:25:57 -04:00
Augie Fackler
c1e3251ee2 contrib: add check-code rule to enforce non-use of python in tests 2017-06-20 09:49:43 -04:00
Danek Duvall
e90fa83ca6 check-code: ban grep's context flags (-A/-B/-C) since they're not on Solaris 2017-06-06 08:58:27 -07:00
Jun Wu
d4a87ea37f check-code: suggest policy.importmod
This forbids patterns like `from mercurial.cext import parsers` which breaks
pure.
2017-05-31 11:41:54 -07:00
Siddharth Agarwal
a03b2b7cab check-code: allow skipping hasattr check in py3-only code
hasattr is safe in Python 3, and in an upcoming patch we can't use
util.safehasattr.
2017-05-21 13:34:42 -07:00
Augie Fackler
50e97668d2 style: ban [ foo == bar] bashism in tests 2017-05-15 14:08:02 -04:00
Yuya Nishihara
e4989d80e7 check-code: ignore re-exports of os.environ in encoding.py
These are valid uses of os.environ.
2017-05-01 17:23:48 +09:00
Yuya Nishihara
edbbe128cc check-code: exclude demandimport.py and policy.py from Python 3 checks
These modules can't depend on pycompat.py, which means we have to write Py3
hacks in them.
2017-04-26 21:51:19 +09:00
Yuya Nishihara
33b4c27bff check-code: rewrite py3 exclusion pattern with negative lookahead
I want to add more patterns, but negative lookbehind requires patterns of
the same length so not useful.
2017-05-01 17:10:22 +09:00
Pierre-Yves David
8ab26d7bb8 checkcode: only match pushd/popd as word
otherwise it partially match common words like "pushdestination".
2017-04-10 17:05:54 +02:00
Jun Wu
f809188b4c check-code: use "-" to specify a list of files from stdin
This will be used by the next patch.
2017-04-06 22:08:23 -07:00
Augie Fackler
dcec340a8b check-code: update test IP address enforcement checks
Instead of mentioning 127.0.0.1, we should use $LOCALIP. Anytime
$LOCALIP appears in output, we should make sure we use (glob) on that
line of output so that weird environments that do remapping jiggery
pokery (such as our FreeBSD buildbot that's in a jail) don't get
spurious test failures.
2017-04-03 18:58:00 -04:00
Martin von Zweigbergk
6b2860bef0 check-code: fix "covert" typo 2017-04-03 11:30:51 -07:00
Jun Wu
5dda7e9e48 check-code: detect r.revision(r.node(rev))
revlog.revision takes either node or rev, but taking a rev is more
efficient, because converting rev to node is just a seek and read.
That's cheaper than converting node to rev, which may require O(n) walk in
revlog index for the first times, and then triggering building the radix
tree index. Even with the radix tree built, rev -> node is still faster than
node -> rev because the radix tree requires more jumps in memory.

So r.revision(r.node(rev)) should be changed to r.revision(rev). This patch
adds a check-code rule to detect that.
2017-03-29 16:46:57 -07:00
Jun Wu
35b00f22fa runtests: change local IP glob pattern from "127.0.0.1" to "$LOCALIP"
This is similar to what 9704c8e70d2d does. Since 1363aaf74791 has changed
"127.0.0.1" to "$LOCALIP". The glob pattern needs update accordingly. It is
expected to fix tests running in some BSD jails.
2017-03-26 19:57:17 -07:00
Jun Wu
7fa1b063a1 checkcode: enforce lowercase for extension docstring title
This will ensure new extensions are consistent and `hg help -e` has a
consistent output.

I have to add a new group since the normal "pypats" will be filtered by
"pyfilters", which will remove comments and docstrings.
2017-03-23 21:23:21 -07:00
Gregory Szorc
4f8c92c87a check-code: recommend util.urlreq when importing urlparse 2017-03-21 22:46:17 -07:00
Gregory Szorc
5ca0f908bf py3: add __bool__ to every class defining __nonzero__
__nonzero__ was renamed to __bool__ in Python 3. This patch simply
aliases __bool__ to __nonzero__ for every class implementing
__nonzero__.
2017-03-13 12:40:14 -07:00
Martin von Zweigbergk
2b641873b5 merge with stable 2017-02-13 09:44:16 -08:00
FUJIWARA Katsunori
f778068b44 misc: replace domain of mercurial-devel ML address by mercurial-scm.org
This patch also adds new check-code.py pattern to detect invalid usage
of "mercurial-devel@selenic.com".
2017-02-11 00:23:55 +09:00
FUJIWARA Katsunori
e6f91a13e7 misc: replace domain of mercurial ML address by mercurial-scm.org
This patch also adds new check-code.py pattern to detect invalid usage
of "mercurial@selenic.com".

Change for test-convert-tla.t is tested, but similar change for almost
same test-convert-baz.t isn't yet tested actually, because I couldn't
find out the way to get "GNU Arch baz client".

AFAIK, buildbot skips test-convert-baz.t, too. Does anybody have
appropriate environment for testing?
2017-02-11 00:23:53 +09:00
Yedidya Feldblum
6a9ac1262a check-code: permit functools.reduce 2017-01-21 14:43:13 -08:00
Pulkit Goyal
3c7388da12 py3: replace pycompat.getenv with encoding.environ.get
pycompat.getenv returns os.getenvb on py3 which is not available on Windows.
This patch replaces them with encoding.environ.get and checks to ensure no
new instances of os.getenv or os.setenv are introduced.
2017-01-15 13:17:05 +05:30
Martin von Zweigbergk
631c635657 check-code: reject module-level @cachefunc
Module-level @cachefunc usage is risky because it can easily create a
memory "leak". Let's reject it completely for now. If a valid usage
comes up in the future, we can always improve the check or reconsider.
2017-01-13 10:11:37 -08:00
Pulkit Goyal
2207f24f07 py3: add warnings in check-code related to py3
We have our own bytes versions of things like, getopt.getopt, os.sep, os.name,
sys.executable, os.environ and few more for python 3 portability. Its better
to come up with warnings if someone breaks the things which we have fixed.

After this patch, check-code will warn us to use our bytes version.
These checks run on mercurial/ and hgext/ and pycompat.py is excluded.
2016-12-21 22:42:31 +05:30