[PATCH 0 of 2] run-tests: add debug mode

Greg Ward greg-hg at gerg.ca
Tue Nov 3 08:07:01 CST 2009


Thanks Martin!

I've just documented this feature in the wiki (DebuggingTests).
Here's what I wrote:

"""
== Debugging Test Scripts (>= 1.4) ==

Starting with Mercurial 1.4, `run-tests.py` has a "debug" mode that
disables the default "capture and diff" behavior, rendering the above
shell script obsolete.  (It also works with Python test scripts in
addition to shell test scripts.)  In debug mode, `run-tests.py` simply
echos its child's stdout (and stderr).  Naturally, this makes it
impossible for `run-tests.py` to tell if a test passed or failed:
that's up to you to do by reading its output.  As above, this is
particularly useful for running `hg` under the Python debugger.

Use the `--debug` option to activate debug mode:
{{{
./run-tests.py --debug test-something
}}}
(You can use debug mode on any number of test scripts, but in practice
it's most useful on a single script.)

Debug mode has no effect on the temporary directory used to run tests;
it will remain `$TMPDIR/hgtests.XXXXXX`.  If you want to preserve and
inspect the test environment, use `--tmpdir` to specify a different
temporary directory.  Note that the meaning of `--tmpdir` changed in
Mercurial 1.4: formerly, the test directory (`hgtests.XXXXXX`) was
created inside the temp dir.  Now, `--tmpdir` ''is'' the test
directory.  So if you are in the habit of running `./run-tests.py
--tmpdir /mnt/ramdisk`, you'll have to break that habit.  Instead, use
`TMPDIR=/mnt/ramdisk ./run-tests.py`.  `run-tests.py` will abort if
the temp dir already exists to prevent accidents for people used to
working this way.

Putting it all together, then, the way I most commonly use debug mode is this:
{{{
rm -rf tmp && ./run-tests.py --local --debug --tmpdir tmp test-something
}}}
where:
  * the `rm -rf` is necessary because `run-tests.py` requires that the
tmp dir not exist, and will not blow it away for you (to prevent
accidents)
  * `--local` is optional, but speeds things up (saves the overhead of
a throwaway build+install of Mercurial)
  * `--debug` enables debug mode
  * `--tmpdir` sets the test directory

If you need to sift through the wreckage after one run, it's in
`tmp/test-something`.  Also, keep in mind that `run-tests.py` creates
a test-specific `tmp/.hgrc`, so if you need to manually duplicate
exactly what happened in the test script, you'll want to do something
like this:
{{{
cd tmp
export HGRCPATH=$PWD/.hgrc
cd test-something
}}}
And of course, most test scripts create one or more test repositories
under that, so another level of `cd` is generally required.
"""

I also renamed the existing "Debugging Tests" section to "Debugging
Tests (pre-1.4)".

Greg


More information about the Mercurial-devel mailing list