Commit Graph

878 Commits

Author SHA1 Message Date
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
Augie Fackler
3cdfffa124 tests: add support for listing tests to run in a file
This will make it easier for us to run the tests in the python3
whitelist in buildbot.
2017-09-18 17:11:32 -04:00
Jun Wu
0886c75e25 run-tests: allow bisecting a different repo
Add `--bisect-repo` flag which accepts a different repo to bisect.

3rd party extensions may reuse `run-tests.py` from core to run tests. Test
failure could be caused by either a core hg change or the 3rd party
extension code itself. Having a way to specify which repo to bisect is
useful.

Differential Revision: https://phab.mercurial-scm.org/D578
2017-08-02 21:24:29 -07:00
Jun Wu
0f38c6c170 run-tests: extract prefix of bisect commands to a variable
This does not change any logic.

Differential Revision: https://phab.mercurial-scm.org/D577
2017-08-02 21:01:38 -07:00
Jun Wu
5b27abd5aa run-tests: pass --with-hg to run-tests.py command used by bisect
This makes `run-tests.py -l test-run-tests.t` 23 seconds faster on my
laptop. Inside the test, `$ rt --known-good-rev=0 test-bisect.t` took 24.9
seconds before, and 1.2 seconds after.

Differential Revision: https://phab.mercurial-scm.org/D576
2017-08-02 21:01:38 -07:00
Jun Wu
0d6dfaec17 run-tests: make per-line condition support testcase names
7340465bd added multiple test cases support. The latter has a problem -
output lines cannot be made conditional with `#if`:

```
  # COUNTEREXAMPLE: DOES NOT WORK
  #testcases A B
    $ command-foo
    common ouput
  #if A
    A's ouput
  #else
    B's ouput
  #endif
    common ouput
```

That's not trivial to fix (even if it works in test, `run-tests.py -i` may
be suboptimal because diff algorithm does not know how to skip the `#if`
lines, even if it does, it may have trouble figuring out whether a changed
line belongs to inside a `#if` block or outside).

Matching output lines conditionally is useful. 4eec2f04a added per-line
condition support for hghave. This patch extends that to also support test
case names.

Differential Revision: https://phab.mercurial-scm.org/D466
2017-08-20 09:46:27 -07:00
Yuya Nishihara
14e0bb89bd run-tests: pass unicode to Pygments
This is required on Python 3, and is more correct on Python 2 because
Pygments is a unicode library.
2017-08-24 22:20:02 +09:00
Yuya Nishihara
d5420b90d5 run-tests: factor out highlight functions 2017-08-24 22:15:40 +09:00
Yuya Nishihara
622a04a8fa run-tests: include "\n" in formatted message instead of calling writeln()
So we don't have to strip "\n" from pygments output.
2017-08-24 22:09:57 +09:00
Alex Gaynor
3b5dc143a9 tests: fixed a bytes/unicode confusion in the test runner
Differential Revision: https://phab.mercurial-scm.org/D483
2017-08-23 01:08:09 +00:00
Martin von Zweigbergk
43011a8bd8 run-tests: remove unused pygments token type
Differential Revision: https://phab.mercurial-scm.org/D478
2017-08-22 10:01:27 -07:00
Martin von Zweigbergk
7366797b32 run-tests: also highlight .py test files in summary messages
With the .t files highlighted, it's very easy to not even notice
failed .py tests.

Differential Revision: https://phab.mercurial-scm.org/D471
2017-08-21 22:13:51 -07:00
Matthieu Laneuville
f835a7751f run-tests: pre instantiate pygments objects
Pre instantiate pygments objects to minimize overhead (cf. 50fbad9bb2af)
2017-08-22 11:00:00 +02:00
Matthieu Laneuville
0502a8cd8b run-tests: also color the summary messages (skipped, failed...) 2017-08-11 14:21:49 +02:00
Augie Fackler
fe8bb86ad9 tests: fix up test-run-tests failures on Python 3.6
Some of the recent work on run-tests.py didn't work on Python 3. This
fixes the regressions.

Differential Revision: https://phab.mercurial-scm.org/D270
2017-08-08 15:07:05 -04:00
Matt Harbison
4f1ba0d22a run-tests: don't drop optional lines after a missing unconditional line
The previous behavior was to bail out when hitting 'awol', so 'missing (?)' was
also dropped.
2017-07-18 00:57:11 -04:00
Matt Harbison
72e29cff86 run-tests: drop required (feature !) style lines when the output is missing
Essentially, these were acting as a verbose (?) flag, since they weren't being
dropped when required.  Foozy has a nice description [1].  Basically, a couple
more places needed to check the features before treating it as optional.

I don't like how test-run-tests.py had to be hacked, but _hghave() can't be made
a static method.  The test change was a change while developing `debugssl`,
prior to tightening up the cases where the message is printed, that this fix
would have caught.

[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-July/101941.html
2017-07-18 00:12:44 -04:00
Augie Fackler
484a641a36 tests: add support in run-tests.py for an environment variable to stop color
I don't like the color output, so this gives me a way to easily never
see it while still having pygments on my machine.
2017-07-26 17:56:44 -04:00
Jun Wu
e2c4f27de2 run-tests: pre instantiate pygments objects
This speeds up run-tests.py diff output by 10x, which affects developer
experience significantly. As demonstrated by the following test:

```
#require pygments

  $ for i in `seq 1 200`; do
  >   echo '  $ echo '$i >> test-a.t
  >   echo '  wrong' >> test-a.t
  > done

  $ cat > walltime.py <<EOF
  > from __future__ import absolute_import, print_function
  > import os, sys, time
  > t1 = time.time()
  > os.system(' '.join(sys.argv[1:]) + ' >/dev/null 2>/dev/null')
  > t2 = time.time()
  > print('%0.2f' % (t2 - t1))
  > EOF

  $ $PYTHON walltime.py $TESTDIR/run-tests.py -l --color=never $TESTTMP/test-a.t
  0.24

Before this patch:

  $ $PYTHON walltime.py $TESTDIR/run-tests.py -l --color=always $TESTTMP/test-a.t
  2.46

After this patch:

  $ $PYTHON walltime.py $TESTDIR/run-tests.py -l --color=always $TESTTMP/test-a.t
  0.25
```
2017-07-21 08:43:39 -07:00