Commit Graph

150 Commits

Author SHA1 Message Date
Jun Wu
dc42feebe8 test-run-tests.t: remove warning about entry point
Summary:
The warning was removed by D9436487. This diff should fold into that change.
Unfortunately buck test didn't run with run-tests.py changes. So lets fix it.

Reviewed By: singhsrb

Differential Revision: D9444368

fbshipit-source-id: 8e27ae14d56e559fc063d5500ebb789c4fe26545
2018-08-21 20:04:52 -07:00
Kostia Balytskyi
0598171436 hg: fix linux test failure
Summary:
Generally, it seems the `mercurial/entrypoint.py` approach might need some
more thinking, but in this particular case I'd prefer to just fix the tests.

Here's what's going wrong:
- D9407009 intoduced a logic to expect `mercurial/entrypoint.py` to always
exist under the `hg` installation on a *run-tests* level
- `run-tests.py test-run-tests.t` however runs `run-tests.py` (yo dawg), while
`hg` is a symlink to `$(which true)`
- while the `mercurial/entrypoint.py` script cannot be found by the test
suite in this case, it's not important becuase no real Mercurial is run.
Therefore, I propose to change `SystemExit` to `log`. On one hand, the absense
of `mercurial/entrypoint.py` is a big deal, so we should know about it. On the
other, this case can run completely without it. In the dominant majority of the
other test cases, we'll learn about the absense of `mercurial/entrypoint.py`
by means of the failing Mercurial call.

Generally, this migth require some more thought, but for now let's fix tests.

Reviewed By: lukaspiatkowski

Differential Revision: D9421433

fbshipit-source-id: e39628015ff96f27368b99ec1f99145c0cb1ae7b
2018-08-21 07:51:24 -07:00
Phil Cohen
b05631eff7 tests: remove the testreport= prefix in report.json
Summary: This prefix makes this file harder because it isn't valid JSON. Per discussion with quark-zju, remove it.

Reviewed By: singhsrb

Differential Revision: D8769139

fbshipit-source-id: f45703c963898202775e90d536dde2894e5029bb
2018-07-09 13:36:27 -07:00
Kostia Balytskyi
68222220cd tests_: add a glob to test-run-tests
Summary:
This is dependent on the runtime order of things, we can eliminate this
dependency by globbing.

Reviewed By: ryanmce

Differential Revision: D8379540

fbshipit-source-id: 4b3cb1c4403dcbf3591a1a79da22359d2857cedb
2018-06-12 07:34:15 -07:00
Jun Wu
776584f6fc run-tests: use basename when showing test errors
Summary:
The current buck test outputs failures like:

  --- /xxx/xxxxx/xxxxx-xx-xxxxxx-xxxxxxx-529-1528508531/xxxxxx/xxx/hg/tests/test-fb-hgext-sparse-extensions.t
  +++ /xxx/xxxxx/xxxxx-xx-xxxxxx-xxxxxxx-529-1528508531/xxxxxx/xxx/hg/tests/test-fb-hgext-sparse-extensions.t.err
  ....

The file name is too long. It's nicer to just get to the point and show the
basename:

  --- test-fb-hgext-sparse-extensions.t
  +++ test-fb-hgext-sparse-extensions.t.err

So this patch does that.

Reviewed By: phillco

Differential Revision: D8360547

fbshipit-source-id: 103929747944e819441a428d30dd6c6516439a71
2018-06-11 18:32:36 -07:00
Jun Wu
df73510ede tests: fix tests caused by tinit change
Reviewed By: singhsrb

Differential Revision: D7141028

fbshipit-source-id: 186955ce5f91befcdbbc1ccdc8ba7ff2c3e4fa92
2018-04-13 21:51:20 -07:00
Jun Wu
e3bbd1757c serve: assign hg serve ports dynamically (part 2)
Summary:
This is similar to what D6925398 does. But covers areas that D6925398 missed
because the codemod script wasn't able to handle multiple-line `hg serve`
commands.

Reviewed By: DurhamG

Differential Revision: D6937919

fbshipit-source-id: a67de178527c11a0ed8bbac82f0c46d44b81be77
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
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
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
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
Martin von Zweigbergk
d28cfbc9a5 tests: avoid echo with backslash escapes
Some shells' echo (e.g. Bash's) do not interpret backslash escapes by
default, while others shells' do (e.g. Dash's). This led to a failure
in test-run-tests.t. We could switch to the more compatible printf,
but using a heredoc seems simpler, so that's what this patch does.

For anyone who wants to test this for themselves, remove the "unset
HGTEST_SHELL" line in helper-runtests.sh and pass
e.g. "--shell=/bin/dash" to the test runner.

Differential Revision: https://phab.mercurial-scm.org/D1699
2017-12-14 22:30:03 -08:00
Matt Harbison
7d8bebd9c1 tests: remove (glob) annotations that were only for '\' matches
# skip-blame because this was mechanically rewritten the following script.  I
ran it on both *.t and *.py, but none of the *.py changes were proper.  All *.t
ones appear to be, and they run without addition failures on both Windows and
Linux.

  import argparse
  import os
  import re

  ap = argparse.ArgumentParser()
  ap.add_argument('path', nargs='+')
  opts = ap.parse_args()

  globre = re.compile(r'^(.*) \(glob\)(.*)$')

  for p in opts.path:
      tmp = p + '.tmp'
      with open(p, 'rb') as src, open(tmp, 'wb') as dst:
          for line in src:
              m = globre.match(line)
              if not m or '$LOCALIP' in line or '*' in line:
                  dst.write(line)
                  continue
              if '?' in line[:-3] or ('?' in line[:-3] and line[-3:] != '(?)'):
                  dst.write(line)
                  continue
              dst.write(m.group(1) + m.group(2) + '\n')
      os.unlink(p)
      os.rename(tmp, p)
2017-12-10 22:50:57 -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
Augie Fackler
c207c2b0a0 tests: add some commentary and diagnostics to test-run-tests.t
Hopefully this will give us a shot at fixing it on the Windows builder.

Differential Revision: https://phab.mercurial-scm.org/D1653
2017-12-11 09:37:11 -05:00
Jun Wu
af13a05eaa test-run-tests: do not rebuild hg in the test
d600bda4 and fc0f3ed0 added code to call `$PYTHON run-tests.py ...`. That
will rebuild hg, is slow and could have other crashes from setup.py, like:

  Unable to find a working hg binary to extract the version from the
  repository tags

Therefore use `run-tests.py -l` instead.

Differential Revision: https://phab.mercurial-scm.org/D1595
2017-12-05 12:23:48 -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
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
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
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
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
d0c2c0b351 tests: de-flake test-run-tests.t's "--jobs=2 --first" test
Once in a while, test-nothing.t finished before test-failure.t or
test-failure-copy.t (I haven't checked which one actually gets run
first). Since there already are two tests that will fail in the same
way, just run those two instead so the diff will be reproducible and
not timing-dependent.

The test case was added in d5f1ee5ea1d3 (run-tests: handle --jobs and
--first gracefully, 2014-10-09), and I have checked that backing that
out results in two failures being printed. Note that the summary may
still include multiple tests even if --first is given, it's just that
the diff is only printed for the first failure.

Differential Revision: https://phab.mercurial-scm.org/D1186
2017-10-18 16:28:18 -07: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
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
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
Matthieu Laneuville
0502a8cd8b run-tests: also color the summary messages (skipped, failed...) 2017-08-11 14:21:49 +02: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
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
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
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
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
Augie Fackler
fa569dd767 tests: sed away python #! in test-run-tests.t to avoid some upcoming insanity 2017-06-20 09:33:19 -04:00
Siddharth Agarwal
1a9dd59bc4 run-tests: make --restart work with output dir 2017-06-07 21:17:24 -07:00
Siddharth Agarwal
7a8b4a7007 run-tests: write JSON reports to output dir 2017-06-07 20:46:43 -07:00
Siddharth Agarwal
8cbca49faa run-tests: write test times to output dir 2017-06-07 20:32:11 -07:00
Siddharth Agarwal
3c77851e4b run-tests: allow specifying an output dir to write .errs to
I'm trying to use run-tests.py on a read-only file system. This series allows
that to happen.
2017-06-07 20:30:08 -07:00
Siddharth Agarwal
7eab0d3988 run-tests: add information about skipped tests to XUnit output
The XUnit spec supports skipped tests.
2017-06-07 15:47:06 -07:00
Siddharth Agarwal
1c6373299a run-tests: wrap failures in an XUnit 'failure' element
This is closer to what most XUnit consumers can understand.
2017-06-07 15:47:06 -07:00
Siddharth Agarwal
d9e3c09954 run-tests: add a way to list tests, with JSON and XUnit support
Some test runners are interested in listing tests, so they can do their own
filtering on top (usually based on attributes like historically observed
runtime). Add support for that.
2017-06-06 14:38:59 -07:00
Augie Fackler
2a698100ca tests: fix run-tests when there's a bad #if in a test
That has (and still does) caused the test to be skipped, but without
this fix it was possible to exit this block of code without clearing
the output channel, which poisoned the channel list for later test
method runs. Fix this by always clearing the channel in a finally.

The test for this is somewhat unfortunate. Sadly, I couldn't get a way
to reproduce this with less than 2n+1 test cases, nor could I get it
to reproduce reliably without the sleep statements. It's also crucial
that the test with the broken #if be smaller (in terms of byte count)
than the sleeping tests, so that it runs first and would poison the
channel list prior to another test needing that entry from the list.
2017-05-30 20:48:43 -04:00
Kyle Lippincott
9d816ecc30 tests: hint how to run slow tests when rejecting 2017-05-26 14:52:54 -07:00
Jun Wu
70f3088190 run-tests: support multiple cases in .t test
Sometimes we want to run similar tests with slightly different
configurations. Previously we duplicate the test files. This patch
introduces special "#testcases" syntax that allows a single .t file to
contain multiple test cases.

Defined cases could be tested using "#if".

For example, if a test should behave the same with or without an
experimental flag, we can add the following to the .t header:

    #testcases default experimental-a
    #if experimental-a
      $ cat >> $HGRCPATH << EOF
      > [experimental]
      > feature=a
      > EOF
    #endif

The "experimental-a" block won't be executed when running the "default" test
case.
2017-05-16 23:10:31 -07:00
Matt Harbison
bcb0f3fe5c run-tests: support per-line conditional output in tests
Duplicating entire tests just because the output is different is both error
prone and can make the tests harder to read.  This harnesses the existing '(?)'
infrastructure, both to improve readability, and because it seemed like the path
of least resistance.

The form is:

  $ test_cmd
  output (hghave-feature !) # required if hghave.has_feature(), else optional
  out2 (no-hghave-feature2 !) # req if not hghave.has_feature2(), else optional

I originally extended the '(?)' syntax.  For example, this:

  2 r4/.hg/cache/checkisexec (execbit ?)

pretty naturally reads as "checkisexec, if execbit".  In some ways though, this
inverts the meaning of '?'.  For '(?)', the line is purely optional.  In the
example, it is mandatory iff execbit.  Otherwise, it is carried forward as
optional, to preserve the test output.  I tried it the other way, (listing
'no-exec' in the example), but that is too confusing to read.  Kostia suggested
using '!', and that seems fine.
2017-04-05 23:17:27 -04:00
Matt Harbison
f4383fc869 test-run-tests: pad the failure test to preserve the run order
Test size seems to dictate the order in which the tests are run, and the next
patch will add to test-success.t.  Similar to 525fd2b88f44.
2017-04-05 22:59:44 -04:00