Commit Graph

853 Commits

Author SHA1 Message Date
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
Martin von Zweigbergk
d1b1e4a13b run-tests: remove unnecessary 'with_color' variable
Its value is always the same as that of 'pygmentspresent'.

Differential Revision: https://phab.mercurial-scm.org/D118
2017-07-17 16:32:10 -07:00
Martin von Zweigbergk
63ec7f9083 run-tests: warn if --color=always and no pygments installed
Differential Revision: https://phab.mercurial-scm.org/D117
2017-07-17 16:27:13 -07:00
Martin von Zweigbergk
41812f06d0 run-tests: drop unnecessary check for pygmentspresent
47985606a0ae (run-tests: check if stream is a tty before using color,
2017-07-18) made the check redundant but forgot to remove it.

Differential Revision: https://phab.mercurial-scm.org/D116
2017-07-17 16:28:42 -07:00
Martin von Zweigbergk
b32f922e53 run-tests: pass color option via test case object , not global var
At first I updated the color field of the 'options' object (from the
CLI parser), but then I decided to put it directly on the test case
object itself to avoid mutating the shared object (even though all
tests would have the same value).

Differential Revision: https://phab.mercurial-scm.org/D114
2017-07-17 16:15:15 -07:00
Matthieu Laneuville
ab721e92b9 run-tests: check if stream is a tty before using color
Previous implementation (ccf66c9bf5af) checked only if sys.stderr was a tty
which was less general. Also makes sure that colors is never used if pygments is
not available, irrespective of --color flag value.
2017-07-18 07:19:26 +09:00
Pulkit Goyal
2ceeb040ad run-tests: make sure to check if pygments is installed before using it
e80041832e introduced support to color the output of tests but used pygments
without checking whether it's installed or not. That breaks test-run-tests.t for
machines which don't have pygments installed. This patch conditionalize the
color test in test-run-tests.t and also add a check to make sure pygments is
installed before using that.
2017-07-15 02:17:05 +05:30
Matt Harbison
bf865ea34e run-tests: disable color on Windows
More Windows sadness.  Maybe someone can figure out how to make win32 color
work, but I think we avoid importing stuff from the mercurial package in this
module.  On the plus side, this conditionalizes away a test failure.
2017-07-15 00:52:36 -04:00
Matthieu Laneuville
91e78ef185 run-tests: add color to output if pygments is available
The output of run-tests has no formatting by default, which hampers readability.
This patch colors the diff output when pygments is available. To avoid coloring
even when pygments is available, use --color never.
2017-06-29 20:45:12 +09:00
Yuya Nishihara
8f9aa59cf3 tests: actually restore the original environment before running syshg
Since os.environ may be overridden in run-tests.py, several important
variables such as PATH weren't restored.

I don't like the idea of using the system hg *by default* because the
executable and the configs are out of our control. But I don't mind as
long as the tests pass.
2017-06-30 21:49:29 +09:00
Adam Simpkins
7b7dd183b0 tests: fix variable name regular expression in _genrestoreenv()
Update the code to correctly anchor the expression on the end of the name, to
require that the entire name match this expression.  It was already anchored at
the start by using re.match(), but this does not anchor it at the end.
2017-06-29 11:29:19 -07:00
Adam Simpkins
738cc44d4e tests: more completely restore the environment in syshgenv
Update the syshgenv function to attempt to completely restore the original
environment, rather than only updating a few specific variables.  run_tests.py
now generates a shell script that can be used to restore the original
environment, and syshgenv sources it.

This is a bit more complicated than the previous code, but should do a better
job of running the system hg in the correct environment.

I've tested it on Linux using python 2.x, but let me know if it causes issues
in other environments.  I'm not terribly familiar with how the tests get run on
Windows, for instance, and how the environment needs to be updated there.
2017-06-28 12:23:22 -07:00
Adam Simpkins
b5772c6bc4 tests: save the original PATH and PYTHONPATH variables
When running the tests, define ORIG_PATH and ORIG_PYTHONPATH environment
variables that contain the original contents of PATH and PYTHONPATH, before
they were modified by run-tests.py

This will make it possible for tests to refer to the original contents of these
variables if necessary.  In particular, this is necessary for invoking the
correct version of hg for examining the local repository (the mercurial
repository itself, not the temporary test repositories).  Various tests examine
the local repository to check the file lists and contents of commit messages.
2017-06-27 17:24:31 -07:00
Jun Wu
f17b667b60 run-tests: fix -i when "#testcases" is used in .t test
The "#testcases" feature introduced by 250afd791085 has issues with "-i"
because "-i" uses "test.name.endswith('.t')" to test if a test is .t or not.

test.name could now be something like "test-foo.t (caseA)" so the above
endswith test is no longer valid.

This patch changes the test to use "self.path" which won't have the issue.
2017-06-21 01:12:31 -07:00
Jun Wu
ca342cbec6 run-tests: update .t reference output after reading the test
The .t file is both test input and reference output. They should always
match. However we have different code paths to read reference output
(Test.__init__ -> Test.readrefout) and test input (TTest._run) so they might
be inconsistent if somethings change the file between those two functions.

This patch assigns "lines" read by "_run" back to "_refout" if "_refout" is
not None (with --debug, see Test.readrefout) so reference output and test
input will always match.
2017-06-21 01:12:31 -07:00
Jun Wu
df1862bacf run-tests: do not prompt changes (-i) if a race condition is detected
The race condition is like:

  1. run-tests.py reads test-a.t as reference output, content A
  2. run-tests.py runs the test (which could be content B, another race
     condition fixed by the next patch, but assume it's content A here)
  3. something changes test-a.t to content C
  4. run-tests.py compares test output (content D) with content A
  5. with "-i", run-tests.py prompts diff(A, D), while the file has content
     C instead of A at this time

This patch detects the above case and tell the user to rerun the test if
they want to apply test changes.
2017-06-21 01:05:20 -07:00
Gregory Szorc
fc4c9d6ad7 tests: removed ReportedTest exception
The only call site called addFailure before raising, which is
exactly what the failure exception handler does. So this
complexity is not needed.

We have test coverage of this "server failed to start" scenario
and nothing appeared to change.
2017-06-03 17:32:52 -07:00
Gregory Szorc
896a966845 tests: remove support for warned tests
The previous changeset removed the last caller of addWarn(). So,
we rip out that method and all the code related to tracking warned
tests in the results system.

There was even a comment saying we may want to fold warned tests into
the "failed" state, which is what the previous changeset did.
2017-06-03 17:22:45 -07:00
Gregory Szorc
ef424bd1cf tests: remove WarnTest
We would raise this if a test didn't return a result code. AFAICT
this can only occur if there is a logic error in the test harness
itself.

I don't think it is worth the code complexity to distinguish this
failure scenario from a regular test failure.
2017-06-03 17:13:35 -07:00
Gregory Szorc
52ea71bafe tests: remove unused IgnoreTest exception
AFAICT its last use was removed in dac81132c652.
2017-06-03 17:09:13 -07:00
Gregory Szorc
e7d240ea93 tests: use unittest.SkipTest
unittest.SkipTest was introduced in Python 2.7. We previously defined
it with our own class so we could run on Python 2.6.
2017-06-03 17:04:42 -07:00
Matt Harbison
2ca7e36798 run-tests: explicitly flush test runner output for Windows stability
When hghave testing goes awry, the output order was changing on Windows.

  diff --git a/tests/test-run-tests.t b/tests/test-run-tests.t
  --- a/tests/test-run-tests.t
  +++ b/tests/test-run-tests.t
  @@ -920,10 +920,10 @@
      > EOF
      > done
      $ rt -j 2
  -  ....
  +  ....skipped: unknown feature: notarealhghavefeature\r (esc)
  +
  +
      # Ran 5 tests, 0 skipped, 0 warned, 0 failed.
  -  skipped: unknown feature: notarealhghavefeature
  -
      $ cd ..
      $ rm -rf broken

Since 'skipped: unknown feature: notarealhghavefeature\n\n' is printed to stdout
and the rest to stderr, it seems like maybe stdio isn't line buffered on
Windows.  When a program exits, stdout is flushed before stderr[1].

[1] https://blogs.msdn.microsoft.com/oldnewthing/20060519-09/?p=31133
2017-06-18 22:19:54 -04:00
Augie Fackler
b3e56018f0 tests: try and fail more gracefully with broken unicode escapes 2017-06-15 13:13:36 -04:00
Siddharth Agarwal
1a9dd59bc4 run-tests: make --restart work with output dir 2017-06-07 21:17:24 -07:00
Siddharth Agarwal
dc354fabde run-tests: output coverage to output dir
There do not appear to be any tests for this, and I've never used either of
these options before, but this works.
2017-06-07 21:17:06 -07:00
Siddharth Agarwal
7a8b4a7007 run-tests: write JSON reports to output dir 2017-06-07 20:46:43 -07:00