Commit Graph

102 Commits

Author SHA1 Message Date
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
Matt Harbison
5ccbc1ad30 run-tests: prevent a (glob) declaration from reordering (?) lines
Previously, if a series of optional output lines marked with '(?)' had a (glob)
in one of the first lines, the output would be reordered such that it came last
if none of the lines were output.  The (re) declaration wasn't affected, which
was helpful in figuring this out.  There were no tests for '(re) (?)' so add
that to make sure everything plays nice.
2017-04-05 22:00:33 -04: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
Augie Fackler
2356a5286e run-tests: add support for using 127.0.0.1 as a glob
Some systems don't have a 127/8 address for localhost (I noticed this
on a FreeBSD jail). In order to work around this, use 127.0.0.1 as a
glob pattern. A future commit will update needed output lines and add
a requirement to check-code.py.
2016-07-09 23:01:02 -04:00
timeless
80bbc318a8 tests: add run-test .testtimes basic testing 2016-04-03 20:49:30 +00:00
timeless
6164721a93 test-run-tests: clean up inuse server eagerly 2016-05-11 15:20:25 +00:00
timeless
7176708168 tests: refactor run-tests helpers
test-run-tests-rev.t will need them
2016-05-11 16:40:16 +00:00
timeless
64b3f40be2 run-tests: handle json.dumps divergence
In py2, json.dumps includes a trailing space after a comma at the
end of lines. The py3 behavior which omits the trailing space is
preferable, so we're going to strip it.
2016-05-05 23:17:19 +00:00
timeless
1e3c2f317c tests: add coverage for run-tests.py --whitelist 2016-05-06 00:45:31 +00:00
timeless
2493adae19 run-tests: handle empty tests 2016-04-05 04:26:20 +00:00
timeless
ac72d955ec run-tests: make _processoutput picky about optional globs
72b40f92c680 enabled lines that were not matched to be found later in cases of jitter.

Unfortunately, in this model an optional line would always jitter to the end when
it is not present. That is not ideal.

It would be possible to do better, by queuing all writes until the end in case
an optional line jitters, but for now, it is simpler to assume optional lines
have a fixed place in the stream.
2016-03-30 09:13:47 +00:00
timeless
0873ced1ee tests: ensure run-tests handles multiple lines of churn
72b40f92c680 added the ability to remember lines (including their flags, like glob)
and tolerate them even if the output order varies.

This test ensures that the code will continue to work in the future.
2016-03-21 20:56:46 +00:00
timeless
ff17cf9b70 tests: remove obsolete uses of HGTEST_RUN_TESTS_PURE
dffce3bb1563 added arguments to run-tests.py calls to propagate --pure when
--with-hg is not used.

6bb9fddace23 unified places to use --with-hg via rt(), which obviated the
need for passing HGTEST_RUN_TESTS_PURE.
2016-03-21 21:06:49 +00:00
Augie Fackler
b15267eb94 run-tests: add support for automatically bisecting test failures 2016-03-19 14:26:10 -04:00
Matt Harbison
f0863290ab run-tests: defer leftover (?) cleanup until after all output is exhausted
Previously, after matching a single line, any contiguous subsequent lines ending
with (?) would be added to the output and removed from the expected output.
This is a problem if the subsequent test output would have matched the consumed
(?) line, because it kept the optional line and then added a duplicate without
the (?) [1].  Instead, wait until there is nothing more to match before handling
the leftovers.

[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2016-February/080197.html
2016-02-28 23:21:28 -05:00
Matt Harbison
14f6ca56b3 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.
2016-02-28 23:16:30 -05:00
David R. MacIver
3ebd7298a9 run-tests: allow run-tests.py to run tests outside current directory
When reloading tests, run-tests.py was assuming that it could look
up the test by the basename, which only works if you are running
tests which are in the current directory.

This patch changes that lookup to use the full path. This is all
that was needed, and does not appear to cause any problems for
any of the existing testing work flows based on running the
suggested commands at the top of run-tests.py.

Motivation: In order to test Mercurial with Hypothesis (according
to https://www.mercurial-scm.org/wiki/HypothesisPlan) it is
useful to be able to generate temporary test files and execute
them. Generating temporary files in the tests/ directory leads to
a lot of suboptimal clutter.
2016-02-18 08:52:15 +00:00
Yuya Nishihara
ad2de493a5 tests: load json with no fallback
The json module should be available in Python 2.6 or newer.
2016-01-09 13:20:15 +09:00
timeless
e09049f8f5 run-tests: warn about symlinks to non hg scripts
If you symlink /usr/bin/true to /something/hg and try to run
--with-hg=/something/hg, run-tests will end up running /usr/bin/hg,
not /usr/bin/true.
2016-02-08 22:50:19 +00:00
Laurent Charignon
bdac46ce5b run-tests: fix crash when --json and --blacklist are both used (issue5050)
This patch fixes a crash when both --json and --blacklist were given as
arguments of run-tests.py. Now, instead of crashing, we add an entry for
blacklisted tests in the json output to show that the tests were skipped.
2016-01-19 08:22:27 -08:00
Laurent Charignon
693c12d5a7 run-tests: add 'diff' entry in json report
This patch adds to the json report the "diff" between expected and observed
result. This diff can be useful for automatically filing bug report on failing
tests.
2016-01-05 13:33:09 -08:00
timeless
c93f79b92f run-tests: fix get port to try differing ports
The code was moving its offset each time through the loop,
but because it failed to update port, the port was not
going to be available...
2015-12-29 04:30:38 +00:00
timeless
2a6d0ff53a run-tests: avoid double counting server fails 2015-12-28 16:01:31 +00:00
timeless
da9e1e1cb0 run-tests: report missing feature for skipped tests 2015-12-22 08:00:03 +00:00
Matt Harbison
41b4785ddb test-run-tests: glob away a --debug run difference on Windows
This internal test is piped through 'grep -v pwd' to eliminate the pwd alias set
when running with MSYS.  Unfortunately, the '.' from the successful run of the
prior internal test precedes the pwd alias for the next test on the same line,
so grep filters out '.' too, except for the final test.

It also looks like there may be a bug with --debug: the output of the internal
test that had this diff says 2 ran, 0 failed (one test being test-failure.t),
but if --debug is omitted from the internal test, then it says 2 ran, 1 failed.

With this longstanding issue fixed, the test suite finally runs cleanly on
Windows (except subrepo merge documented in issue 4988), with 88 skips.  \o/
2015-11-23 12:14:01 -05:00
Matt Mackall
830377c397 tests: avoid duplicate install steps in test-run-tests
At several seconds each, this is significantly slowing down the test.
2015-12-06 15:14:01 -06:00
Matt Mackall
8d86df8f01 run-tests: report timeouts in a less alarming fashion
Rather than report timed-out tests like this:

 ERROR: test-convert-svn-sink.t output changed
 !

..simply put a 't' rather than a '.' in the stream.
2015-12-04 14:55:10 -06:00
timeless
7337637dd1 run-tests: add --slowtimeout and use it for slow tests 2015-11-25 00:39:05 +00:00
Matt Harbison
bf40666b90 test-run-tests: conditionalize the $TESTDIR check for Windows separator
The variable uniformly uses '\' separators, so the straight equality check with
'/' separating the last component fails.  It also doesn't like having the quote
appear in the middle of the string when testing.
2015-11-16 16:56:00 -05:00
Matt Harbison
31dd910b50 test-run-tests: add globs for Windows
There are two other unrelated failures in this test.  For some reason child1 has
a space after it, thus 2 spaces before the glob, otherwise the glob is ignored
and removed.
2015-10-01 22:14:11 -04:00
timeless@mozdev.org
dba46baf88 run-tests: report paths saved by --keep-tmpdir 2015-09-30 16:01:19 -04:00
timeless@mozdev.org
20963e1f94 run-tests: use $HGTEST_RUN_TESTS_PURE
test-run-tests and test-hghave call run-tests;
if you don't have a working build environment, and you are trying
to use --pure, then if they don't use --pure or --with-hg,
they'll break.
2015-09-02 15:19:05 -04:00
Augie Fackler
cd6222a983 run-tests: add support for marking tests as very slow
I want to add tests for our packaging rules, but those necessarily run
a whole build, or possibly two if both native packaging and docker are
available. This lets us flag such tests with a `#require slow` so that
they don't unnecessarily slow down normal test runs.
2015-08-24 22:23:45 -04:00
FUJIWARA Katsunori
4a75be9bfa run-tests.py: add TESTDIR to PATH if it differs from RUNTESTDIR
Before this patch, `RUNTESTDIR` is added to `PATH`, but `TESTDIR`
isn't.

This doesn't cause any problems, if `run-tests.py` runs in `tests`
directory of Mercurial source tree. In this case, `RUNTESTDIR` should
be equal to `TESTDIR`.

On the other hand, if `run-tests.py` runs in `tests` of third party
tools, commands in that directory should be executed with explicit
`$TESTDIR/` prefix in `*.t` test scripts. This isn't suitable for the
policy "drop explicit $TESTDIR from executables" of Mercurial itself
(see fcb1c7d8c36e).

BTW, fcb1c7d8c36e describes that "$TESTDIR is added to the path" even
though `TESTDIR` isn't added to `PATH` exactly speaking, because
`TESTDIR` and `RUNTESTDIR` weren't yet distinguished from each other
at that time.

This is a one of preparations for issue4677.
2015-07-03 06:56:03 +09:00
FUJIWARA Katsunori
70980837e8 run-tests.py: add RUNTESTDIR to refer tests of Mercurial
Before this patch, there is no way to refer files under `tests` or so
of Mercurial source tree, when `run-tests.py` runs in `tests` of third
party tools. In this case, `TESTDIR` refers the latter `tests`.

This prevents third party tools from using useful tools in Mercurial
source tree (e.g. `contrib/check-code.py`).

This patch adds `RUNTESTDIR` environment variable to refer `tests` of
Mercurial source tree, in which `run-tests.py` now running is
placed. For example, tests of third party tools can refer
`contrib/check-code.py` in Mercurial source tree as
`$RUNTESTDIR/../contrib/check-code.py`.

BTW, for similarity with `TESTDIR` referring `test*s*` directory,
newly added environment variable isn't named as `RUNTEST*S*DIR`. In
addition to it, the corresponded local variable is also named as
`runtestdir`.

This is a one of preparations for issue4677.
2015-07-03 06:56:03 +09:00
FUJIWARA Katsunori
c5c4f4ba0d run-tests.py: execute hghave by the path relative to run-tests.py
Before this patch, `run-tests.py` executes `hghave` by the path
relative to `TESTDIR` (= cwd of `run-tests.py` running).

This prevents third party tools for Mercurial from running
`run-tests.py`, which is placed in `tests` of Mercurial source tree,
in `tests` of own source tree. In such cases, `TESTDIR` refers the
latter `tests`, and `hghave` doesn't exist in it.

This is a one of preparations for issue4677.
2015-07-03 06:56:03 +09:00
Matt Mackall
3ad28905f6 tests: drop explicit $TESTDIR from executables
$TESTDIR is added to the path, so this is superfluous. Also,
inconsistent use of quotes means we might have broken on tests with
paths containing spaces.
2015-06-08 14:44:30 -05:00
Matt Mackall
b597cb9caa tests: add (?) flag for optional lines
When the test engine fails to match output on a line marked with (?),
it will simply continue to the next expected line and try again. This
allows simplifying tests that have either version-specific or
non-fixed behavior, for instance:

  $ coin-flip
  heads (?)
  tails (?)

(There's no form of back-tracking attempted, so optional matches
should be specific.)
2015-05-31 16:59:34 -05:00
Pierre-Yves David
bffec7e365 run-tests: include 'start' and 'end' in --time output
This is useful information to understand what is taking time in tests. Both are
included because I can see myself sorting this output using shell script. Having
both data makes it much easier than extracting 'start'+'real'.
2015-05-07 23:40:29 -07:00
Pierre-Yves David
bd7f28d558 run-tests: track start and end time of tests
We currently have information about how long each test took, but we have no data
about their actual scheduling. So we now track when a test started and stopped
(in the referential of the whole tests run) to expose this information.

The data is currently in the json only because the json output is meant to be
extensible. Later changeset will includes this data in the text output and we
will be happy to bikeshed its formating there.

Yes, "end" is actually just "start" + "time", but computing it an including it
in the output is simple, cheap and convenient.
2015-05-07 23:34:58 -07:00
Augie Fackler
6ea86f31bb test-run-tests.t: work around file.write() returning an int
In Python 3.5, file.write() returns the number of bytes it wrote
instead of None.
2015-04-13 16:37:53 -04:00
Matt Mackall
82d521ccc3 merge with stable 2015-05-10 14:45:13 -05:00
Pierre-Yves David
0cae7109a3 test-run-test: unset run-test specific environment variables
Otherwise variable set for the real test run interfere with the test runner
tests.
2015-05-08 11:32:24 -07:00
Pierre-Yves David
9f318745fd run-test: add a test for json output when -i is used
The -i can apparently confused some internal data structure, we want to make
sure we do not regress.
2015-05-08 19:32:11 -07:00
Gregory Szorc
704132c0a7 run-tests: don't error when glob matched line ends with backslash
As part of writing another test, I triggered an array index error in
glob match processing code by having a (glob) line end in a single
backslash (which is the escape character).

Adding a simple bounds check prevents the error in run-tests.py.
2015-04-17 14:12:01 -07:00
Gregory Szorc
918575b5f2 run-tests: wait for test threads after first error
The test runner has the ability to stop on first error.

Tests are executed in new Python threads. The test runner starts new
threads when it has capacity to do so. Before this patch, the "stop on
first error" logic would return immediately from the "run tests"
function, without waiting on test threads to complete. There was thus
a race between the test runner thread doing cleanup work and the test
thread performing activity. For example, the test thread could be in
the middle of executing a test shell script and the test runner
could remove the test's temporary directory. Depending on timing, this
could result in any number of output from the test runner.

This patch eliminates the race condition by having the test runner
explicitly wait for test threads to complete before continuing.

I discovered this issue as I modified the test harness in a subsequent
patch and was reliably able to tickle the race condition.
2015-03-28 19:39:03 -07:00
Gregory Szorc
01447cbf3e run-tests: explicitly handle unicode when writing xunit file
The xunit writer was passing a str to a minidom API. An implicit
.decode('ascii') was performed somewhere, causing UnicodeDecodeError
if test output contained non-ascii sequences.

This patch converts test output to utf-8 before passing it to minidom.
We use the "replace" strategy to ensure invalid utf-8 sequences get
munged into �.
2015-03-29 10:41:23 -07:00
FUJIWARA Katsunori
7162b6792b run-tests.py: inherit --pure option from outer run-tests.py execution
Before this patch, "test-run-tests.t" doesn't test "run-tests.py" with
"--pure", even if outer "run-tests.py" is executed with it.

This patch uses not "HG_RUN_TESTS_PURE" but "HGTEST_RUN_TESTS_PURE",
because "HG_" prefixed environments are forcibly dropped in "_getenv()".

This is also useful to run "run-tests.py" successfully by
"run-tests.py --pure" on Windows without any compilation tools (like
VisualStudio).
2015-01-22 00:07:06 +09:00
Mads Kiilerich
7ebc1609d6 run-tests: automatically add (glob) to "saved backup bundle to" lines
Avoid spending too much time adding (glob) after running run-tests -i. This
doesn't handle all cases but it helps.

The run-tests tests add a bit of escaping of trailing (glob) in the output to
avoid interference from the outer test runner.

The regexp for matching the output lines contains a group for making multiline
substitute in a way that works with Python before 2.7.
2014-11-27 02:04:30 +01:00