Commit Graph

896 Commits

Author SHA1 Message Date
Saurabh Singh
32da3b0259 run-tests: change the default hg shell for tests to bash
Summary:
Our tests use features that are provided by the bash shell to function
properly. I ran into issues with our tests on Ubuntu because the default shell
was `dash` which did not even support the `source` command. Therefore, this
commit changes the default hg shell for the tests to `bash`. Clients can always
override the default hg shell for the tests to another shell.

Reviewed By: quark-zju

Differential Revision: D7563733

fbshipit-source-id: e9c16c002793a919a49292a9aa0a876ba232c293
2018-04-13 21:51:50 -07:00
Jun Wu
901e92e858 colors: improve compatibility
Summary:
- Support 8 color mode, since some terminals (emacs) do not support 16
  colors (i.e. "bright*" colors have no effects).
- Detect emacs and use 8 color mode automatically.
- Read terminfo colors. Respect it if it says the terminal supports more
  colors. Suggested by wez.
- Read HGCOLORS. Respect it unconditionally. Change run-tests.py to set it.
- Change diff related colors to also fallback to 8 colors since "bright"
  colors are not guaranteed available.

Differential Revision: D7432965

fbshipit-source-id: da75829f856b4de737b946af72d24ff5351026cb
2018-04-13 21:51:40 -07:00
Jun Wu
3d8a2aa583 color: support fallback configs
Summary:
Allow color config to be something like `color132:red` that is to use 256
color if supported, but fallback to `red`.

To get a consistent test output. `run-tests.py` is changed to disable 256
color support explicitly.

Reviewed By: singhsrb

Differential Revision: D7388277

fbshipit-source-id: da74ae8fc70c971901d56a6985976db44cbec0d9
2018-04-13 21:51:36 -07:00
Jun Wu
c6742cd74c run-tests: source tinit.sh for all .t tests
Summary:
`.t` tests have some highly repeatitive logics, like creating a repo, etc.
This patch adds a common shell file that defines frequently used functions.

For now, `newrepo` and `enable` are added. The latter can be used to
enable a feature (ex. obsstore), or an extension.

`test-fb-hgext-fbamend-next.t` and `test-fb-hgext-absorb.t` are migrated
to use the new shell functions.

Reviewed By: phillco

Differential Revision: D7121485

fbshipit-source-id: 167fcc20e4e30864199b6c5af0958b80bfb68817
2018-04-13 21:51:20 -07:00
Adam Simpkins
1c3c143933 tests: cache the results of hghave checks
Summary:
Update run-tests.py to cache the results of hghave checks.  Some of the
linematch code can end up calling _hghave() hundreds of times in a row with the
same check.

This is particularly likely to happen on test failures, where a line with an
hghave check does not match the expected output.  In this case the same hghave
check will be re-run on each subsequent line of test output.

Reviewed By: quark-zju, farnz

Differential Revision: D7077677

fbshipit-source-id: 768a11df78924b75cde4c8b48c801b79194f7969
2018-04-13 21:51:15 -07:00
Thomas Jacob
0e6b93a0e0 Add support for RocksDB
Summary:
- Add support for RocksDB engine (developed as a drop in replacement for innodb) to hgsql to allow new xdb.hgsql.1-10 shards to host hg repos
- Prefer MySQL test DBs in same region
- Run all hgsql unit tests also for RocksDB engine
- Allow for nested ifs to make that possible (downside if you switch off rockdb tests, innodb tests are run twice)

Reviewed By: quark-zju

Differential Revision: D7014064

fbshipit-source-id: 073c36176aa7eaf74252ef33c3f47da594920b28
2018-04-13 21:51:13 -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
Jun Wu
8e2207b7e6 run-tests: exit 80 if all tests are skipped
Summary:
This can be used by a wrapper script running a single test
to detect whether the test is skipped or not.

Reviewed By: DurhamG, phillco

Differential Revision: D6879864

fbshipit-source-id: 8bc535fccdbc6ad32eec870bd9e503b6f84f694b
2018-04-13 21:51:02 -07:00
Jun Wu
fbaa53a84a run-tests: create a symlink of hg
Summary:
run-tests.py creates the `python` symlink. Let's do the same for `hg`.

This means tests can just use `hg` and do not worry about it being a
wrong one (like, the system hg). And there is no need to create fragile
shell alias, or set `ui.remotecmd`.

The check to ensure `--with-hg` provides either `hg` or `hg.exe` was
removed since it's no longer necessary.

Reviewed By: DurhamG

Differential Revision: D6879879

fbshipit-source-id: 59255102ea3c4c646afc7900696403242bcfb4db
2018-04-13 21:51:01 -07:00
Jun Wu
ae4b932a4e run-tests: increase default timeout
Summary:
With the upcoming `buck test` change, the default timeout is
not enough because of the python wrapper overhead. Let's double
the limits.

Reviewed By: DurhamG

Differential Revision: D6879874

fbshipit-source-id: 19175be8c4f48dda1fc8917d75798d840d4082da
2018-04-13 21:51:01 -07:00
Jun Wu
30ca26055f run-tests: do not override --with-hg with -l
Summary:
When `--with-hg` and `-l` are both provided. `-l` will override
`--with-hg`, which is unfriendly. Let's do the reverse.

Reviewed By: DurhamG

Differential Revision: D6879863

fbshipit-source-id: 00ea9805431cc7afa6dd521cfb9059c898ed6d1f
2018-04-13 21:51:01 -07:00
Jun Wu
9fde63a970 run-tests: add a --extra-rcpath option to load other config files
Summary:
This makes it easier to run integration tests where we want to load
additional sets of config files.

Reviewed By: DurhamG

Differential Revision: D6755017

fbshipit-source-id: af062fcc465eee969e1315f9430333908ef38303
2018-04-13 21:50:54 -07:00
Jun Wu
2c2e9112b0 hgsubversion: do not mess up with sys.path
Summary:
`run-tests.py` should set up `sys.path` correctly so `import mercurial` in
the hgsubversion tests should just work.

Also add a comment in `run-tests.py` to clarify this.

The hgsubversion module check is removed since it assumes the module lives in a
same directory as the test, which is not true with the `run-test.py --rebuild`
case.

Reviewed By: phillco

Differential Revision: D6758588

fbshipit-source-id: ba34253991e671dc972bcb1900243eab6b69fd92
2018-04-13 21:50:54 -07:00
Jun Wu
da7f79ac4a run-tests: use --local by default
Summary: Added --rebuild for the old behavior.

Reviewed By: phillco

Differential Revision: D6753296

fbshipit-source-id: 84f26af285662f91bc59db8b2a3145212118a9b6
2018-04-13 21:50:52 -07:00
Jun Wu
0d7d81e0c2 run-tests: make -j use CPU count by default
Summary:
Given the multi-core era, it seems to be a good default to make use of all
available cores. Use `-j 1` to get the old behavior.

Reviewed By: phillco

Differential Revision: D6752704

fbshipit-source-id: 842ddea1d89160eed030fc71ba08024859db9268
2018-04-13 21:50:52 -07:00
Jun Wu
e81c53461e largefiles: remove the extension
Summary:
`lfs` is the better large file solution. `largefiles` is rarely used, and
its implementation is less clean. So let's remove it.

Test Plan:
Ran all tests. A subrepo test was removed instead of cleaned up since the
longer term plan is to also drop subrepo support.

Reviewers: phillco, #mercurial

Reviewed By: phillco

Differential Revision: https://phabricator.intern.facebook.com/D6740361

Signature: 6740361:1516225594:555e3803571ad05e0434021897a2823ac99347ae
2018-01-17 11:50:44 -08:00
Kostia Balytskyi
34dcd51d76 run-tests: add simple regular expression support for .py.out files
Summary:
To incorporate hgsubversion tests into our test suite, we need to turn them into
silentrunner tests, which run python unittests, but do check for the output to match
some expected file. hgsubversion tests were not written with checking output in mind
(and even if they were, .t tests need globbing/regex support as well). So, this
simple support for (re) suffixes on .py.out files allow us to match unstable output.

Test Plan:
- perform some manual experiments
- following diffs in the stack make use of it

Reviewers: #sourcecontrol

Differential Revision: https://phabricator.intern.facebook.com/D6719877
2018-01-17 03:36:41 -08:00
Jun Wu
f446276fe1 test-run-tests: stabilize the test (issue5735)
Summary:
Previously there is a race condition because things happen in this order:

  1. Check shouldStop
  2. If shouldStop is false, print the diff
  3. Call fail() -> set shouldStop

The check and set should really happen in a same critical section.

This patch adds a lock to address the issue.

The patch was also sent as https://phab.mercurial-scm.org/D1830

Test Plan: Run `run-tests.py -l test-run-tests.t` many times and it no longer fails.

Reviewers: durham, #mercurial

Reviewed By: durham

Subscribers: durham

Differential Revision: https://phabricator.intern.facebook.com/D6680300

Signature: 6680300:1515524998:260c3e198330e7e6c94dcb6cf155f14a055b760a
2018-01-08 17:23:24 -08:00
Matt Harbison
9ffbf863b8 run-tests: use context managers for file descriptors
I've seen the following error a few times recently when running the tests with
`yes | ./run-tests.py --local -j9 -i`:

Errored test-add.t: Traceback (most recent call last):
  File "./run-tests.py", line 821, in run
    self.runTest()
  File "./run-tests.py", line 910, in runTest
    if self._result.addOutputMismatch(self, ret, out, self._refout):
  File "./run-tests.py", line 1774, in addOutputMismatch
    rename(test.errpath, test.path)
  File "./run-tests.py", line 571, in rename
    os.remove(src)
WindowsError: [Error 32] The process cannot access the file because it is being
 used by another process: 'c:\\Users\\Matt\\projects\\hg\\tests\\test-add.t.err'

This change doesn't fix the problem, but it seems like a simple enough
improvement.
2017-12-17 14:06:49 -05:00
Matt Harbison
9638df605c run-tests: add substitution patterns for common '\' path output on Windows
The goal is to reduce the amount of hand tuning of new/changed tests that is
required on Windows.  Since the OS prints the proper paths everywhere else, this
is limited to Windows.  These are based on the check-code rules that were
dropped in 217bd5cb0914.

There are some minor tweaks, because those were trying to detect '/' paths
without a '(glob)' at the end, whereas these detect '\' paths. Also, it looks
like the 'no changes made to subrepo' one was broke, because the path to the
subrepo has been getting output but was not in the pattern.  End anchors are
dropped because '(glob)' is no longer required, but '(feature !)' annotations
are a possibility.

The 'saved backup bundle' pattern dropped from run-tests.py was simply carrying
over the first capture group.  The replace() method runs prior to evaluating
'\1', but it wasn't doing anything because of the 'r' prefix on '\\'.

The 'not recording move' entry is new, because I stumbled upon it searching for
some of these patterns.  There are probably others.
2017-12-12 20:11:13 -05:00
Matt Harbison
f849320c42 run-tests: stop automatically adding a (glob) for bundle backup lines
This is the first step to dropping the existing globs for '\' matches, now that
it is handled automatically.  Instead of just dropping it, this pattern is now
used to convert to '/' paths, to reduce the amount of manual cleanup required
when creating tests on Windows.
2017-12-10 19:21:48 -05:00
Matt Harbison
b2d78bc596 run-tests: accept '\' vs '/' path differences without '(glob)'
Having to constantly adjust these is a hassle.  It's easy for this to slip by
when not testing on Windows, and then when it happens on stable, the tests fail
for the next 3 months if we follow the rules for stable.

This works the same way the EOL differences are ignored, namely to adjust on the
fly and recheck on Windows.  I can't think of any situation where there would be
a '\' on Windows, a '/' elsewhere, and the '/' should be considered a failure on
Windows.

This fixes the obvious output problems where (glob) is missing.  Without this,
test-alias.t, test-remotenames.t and test-largefiles-misc.t are failing.  The
flip side (not handled by this) is the case where an unnecessary glob is
present.  There seems to be two separate behaviors.  f3517e22bfa1 is an example
of where the test has been autocorrecting (with output differences), and
ed159a9fcf2a is an example where the test fails and reports 'no result code from
test'.  Hopefully those cases will become even more rare if people don't need to
guess at when a glob is needed for a Windows path.

It's probably unreasonable to submit a single patch that wipes out all of the
(glob) instances that were only used to hide path differences, given the churn
from other contributors.  Since their presence isn't harming the tests, these
can be removed through attrition.
2017-12-10 00:16:11 -05:00
Matt Harbison
1a1aaf5b24 run-tests: suggest a (glob) for os.path.sep mismatches with '\r\n' EOL too
We already do this for lines ending in '\n', such that the test only needs to be
run with --interactive and the changes accepted at the end.  But that wasn't
working with list-tree.py output for example, and required manual fixup.
2017-12-10 00:00:36 -05:00
Matt Harbison
1eac95a707 lfs: introduce a user level cache for lfs files
This is the same mechanism in place for largefiles, and solves several problems
working with multiple local repositories.  The existing largefiles method is
reused in place, because I suspect that there are other functions that can be
shared.  If we wait a bit to identify more before `hg cp lfutil.py ...`, the
history will be easier to trace.

The push between repo14 and repo15 in test-lfs.t arguably shouldn't be uploading
any files with a local push.  Maybe we can revisit that when `hg push` without
'lfs.url' can upload files to the push destination.  Then it would be consistent
for blobs in a local push to be linked to the local destination's cache.

The cache property is added to run-tests.py, the same as the largefiles
property, so that test generated files don't pollute the real location.  Having
files available locally broke a couple existing lfs-test-server tests, so the
cache is cleared in a few places to force file download.
2017-12-06 22:56:15 -05:00
Martin von Zweigbergk
96e10ab37b run-tests: avoid calculating _testdir again
Differential Revision: https://phab.mercurial-scm.org/D1574
2017-12-01 12:28:05 -08:00
Martin von Zweigbergk
ca0a21ad2a run-tests: simplify by using dict.pop() with default
Differential Revision: https://phab.mercurial-scm.org/D1573
2017-12-01 12:27:28 -08:00
Gregory Szorc
99a062e473 run-tests: mechanism to report exceptions during test execution
Sometimes when running tests you introduce a ton of exceptions.
The most extreme example of this is running Mercurial with Python 3,
which currently spews thousands of exceptions when running the test
harness.

This commit adds an opt-in feature to run-tests.py to aggregate
exceptions encountered by `hg` when running tests.

When --exceptions is used, the test harness enables the
"logexceptions" extension in the test environment. This extension
wraps the Mercurial function to handle exceptions and writes
information about the exception to a random filename in a directory
defined by the test harness via an environment variable. At the
end of the test harness, these files are parsed, aggregated, and
a list of all unique Mercurial frames triggering exceptions is
printed in order of frequency.

This feature is intended to aid Python 3 development. I've only
really tested it on Python 3. There is no shortage of improvements
that could be made. e.g. we could write a separate file containing
the exception report - maybe even an HTML report. We also don't
capture which tests demonstrate the exceptions, so there's no turnkey
way to test whether a code change made an exception disappear.
Perfect is the enemy of good. I think the current patch is useful
enough to land. Whoever uses it can send patches to imprve its
usefulness.

Differential Revision: https://phab.mercurial-scm.org/D1477
2017-11-20 23:02:32 -08:00
Gregory Szorc
913e1deefc run-tests: make --extra-config-opt work with Python 3
And add test coverage to ensure it works.

Differential Revision: https://phab.mercurial-scm.org/D1476
2017-11-20 21:26:11 -08:00
Gregory Szorc
c1ab166a69 run-tests: organize options into argument groups
And sort arguments so help output is more legible.

There are probably a ton of ways to group things. I tried to
picture the test harness as a pipeline and attempted to draw boundaries
around stages in that pipeline to create the groupings.

Differential Revision: https://phab.mercurial-scm.org/D1475
2017-11-20 21:08:18 -08:00
Gregory Szorc
cead888098 run-tests: convert to argparse
optparse has been deprecated since Python 3.2. Best to get on the new
boat before the old one sinks.

It looks like argparse formats its usage string differently than
optparse. Meh.

Differential Revision: https://phab.mercurial-scm.org/D1474
2017-11-20 20:41:43 -08:00
Martin von Zweigbergk
78a897a44d run-tests: make "| foo (re)" not match everything
We make "foo (re)" match the entire line by adding a \Z to the regular
expression before matching. However, that doesn't help when the
regular expression is something like "| foo", because that gets
translated to "| foo\Z", where the "|" has lower precedence and it
thus matches the empty string, which is of course a prefix of every
string. Fix by wrapping expression in a group before adding the \Z to
the end.

Differential Revision: https://phab.mercurial-scm.org/D1546
2017-11-29 10:34:49 -08:00
Matthieu Laneuville
97d465a100 run-tests: outputdir also has to be changed if $TESTDIR is not $PWD
Following 30a570fd0165, running run-tests.py from outside tests/ would lead to
the creation of .testtimes and test-*.t.err in $PWD instead of $TESTDIR. This
patch fixes that and updates the relevant test.
2017-11-18 16:12:00 +09:00
Boris Feld
36f8a40cbc run-test: drop 'execfile' usage for 'common-pattern.py' file
This is required for Python 3.
2017-11-19 04:11:21 +01:00
Boris Feld
892a48dd6e run-test: use byte for 'common-pattern.py' path
This is required for Python 3.
2017-11-19 04:10:55 +01:00
Boris Feld
01dc148f6e run-tests: allow to register any arbitrary pattern for replacement
We add a 'common-pattern.py' file that allow to define extra pattern. This seems
a cleaner approach than editing the 'run-test.py' file over and over. In
addition allowing arbitrary pattern registration will also help extension.

The format used is a python file is picked out of convenience defining a list of
tuple in 'substitutions' variable. This is picked out of convenience since it is
dead simple to implement.

The end goal is to register more pattern for Mercurial test. There are multiple
common patterns that change over time. That impact is annoying. Using pattern
emplacement for them would be handy.

The next patches will define all the needed patterns and the last patch will
mass-update the tests outputs as it was easier to do in a single pass.
2017-11-05 06:34:27 +01:00
Kyle Lippincott
4d4a9cfc92 run-tests: fix TESTDIR if testdescs are absolute paths
Commit 30a570fd0165 made TESTDIR be the location of the arguments that were
passed to run-tests.py instead of just PWD.  It assumed that these tests were
specified using relative paths, so if pwd was /tmp/foo, and the first argument
was /tmp/baz, it would set TESTDIR to /tmp/foo//tmp/baz.

Differential Revision: https://phab.mercurial-scm.org/D1433
2017-11-15 17:54:27 -08:00
Matthieu Laneuville
02caf9675e run-tests: allow automatic test discovery when providing folder as argument
Currently `run-tests.py` automatically discovers test only in the current
directory if no argument is provided. This patch makes it possible to pass a
number of tests and folders as arguments.
2017-10-19 23:13:57 +09:00
Matthieu Laneuville
c0356803bd run-tests: endswith takes bytes as argument in python3, not str 2017-11-03 21:14:57 +09:00
Matthieu Laneuville
7b14aa1a56 run-tests: $TESTDIR can be something else than $PWD
$TESTDIR is expected to be the directory were the test lives, and is often used
to reference helper functions. However, it is now set to $PWD at test invocation
time, so if `run-tests.py` is called from another folder, the test will fail.

The solution is to force $TESTDIR to be the base directory of the test itself,
irrespective of where the runner is called from.
2017-08-02 13:27:45 +09:00
Martin von Zweigbergk
4046d59941 run-tests: move newline out of colorized message
The leading newline before "ERROR:" led to an incorrect lexing of the
message and the newline got lost.

The fixed formatting can be seen in the test case. The reason we
didn't notice before was that the bad formatting just led to the loss
of a blank line in the test. However, there are other cases where it
would be joined with a line saying "Accept this change? [n]" or
"Reference output has changed (run again to prompt changes)".

Differential Revision: https://phab.mercurial-scm.org/D1159
2017-10-17 10:33:27 -07:00
Jun Wu
b7de3d0f60 run-tests: set HGPLAIN=1 when bisecting
Otherwise a customized template may break the regex matching the bisect
output.

Differential Revision: https://phab.mercurial-scm.org/D949
2017-10-04 18:51:21 -07:00
Jun Wu
e6abc27d80 run-tests: extract Popen logic to a single method
This removes 3 lines in total LOC and makes the upcoming changes easier.

Differential Revision: https://phab.mercurial-scm.org/D948
2017-10-04 18:50:18 -07:00
Jun Wu
e0d88f4bc5 run-tests: move bisect logic to a separate method
This removes 8 space indentation and makes upcoming changes easier.

Differential Revision: https://phab.mercurial-scm.org/D947
2017-10-04 18:42:24 -07:00
Jun Wu
5c5bc340e6 test-logtoprocess: make it compatible with chg
chg runs more commands and outputs more lines. This patch matches them.

Differential Revision: https://phab.mercurial-scm.org/D914
2017-10-02 18:22:43 -07:00
Augie Fackler
18842dd648 tests: fix run-tests XML reporting on Python 3
cdatasafe wants to work in terms of bytes, but of course we have a
unicode. Easy to work around, especially since we know we'll get utf-8
at the end.
2017-09-19 00:09:37 -04:00
Augie Fackler
cca5652bce tests: convert bisect support regex to binary
The bisection feature of run-tests still fails tests with this because
bisect itself doesn't work yet. We'll get there.
2017-09-19 00:08:52 -04:00
Augie Fackler
5d1dd806b5 tests: decode bytes path to hg command before hitting with shellquote 2017-09-19 00:08:12 -04:00
Augie Fackler
4eca20a289 tests: fix test-is-whitelisted check in run-tests
Again, look for bytes in a set of bytes objects.
2017-09-19 00:07:51 -04:00
Augie Fackler
0a1d05565a tests: fix run-tests "slow test" check
Look for bytes in a set of bytes objects.
2017-09-19 00:07:23 -04:00
Augie Fackler
2ec91e73fc tests: fix run-tests default values in Test constructor
As far as I can tell, default values are evaluated far earlier on
Python 3.6 than 2.7, meaning we've got to be more careful about when
we read the defaults dictionary for the kwarg defaults. Sigh.

With this change, test-run-tests.t is significantly less of a mess
under 3.6.
2017-09-19 00:06:57 -04:00