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.
( )
yuja |
hg-reviewers |
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.
Lint Skipped |
Unit Tests Skipped |
if ex.errno != errno.ENOENT: | if ex.errno != errno.ENOENT: | ||||
raise | raise | ||||
return cases | return cases | ||||
def getparser(): | def getparser(): | ||||
"""Obtain the OptionParser used by the CLI.""" | """Obtain the OptionParser used by the CLI.""" | ||||
parser = argparse.ArgumentParser(usage='%(prog)s [options] [tests]') | parser = argparse.ArgumentParser(usage='%(prog)s [options] [tests]') | ||||
# keep these sorted | selection = parser.add_argument_group('Test Selection') | ||||
parser.add_argument("--blacklist", action="append", | selection.add_argument('--allow-slow-tests', action='store_true', | ||||
help='allow extremely slow tests') | |||||
selection.add_argument("--blacklist", action="append", | |||||
help="skip tests listed in the specified blacklist file") | help="skip tests listed in the specified blacklist file") | ||||
parser.add_argument("--whitelist", action="append", | selection.add_argument("--changed", | ||||
help="always run tests listed in the specified whitelist file") | |||||
parser.add_argument("--test-list", action="append", | |||||
help="read tests to run from the specified file") | |||||
parser.add_argument("--changed", | |||||
help="run tests that are changed in parent rev or working directory") | help="run tests that are changed in parent rev or working directory") | ||||
parser.add_argument("-C", "--annotate", action="store_true", | selection.add_argument("-k", "--keywords", | ||||
help="output files annotated with coverage") | help="run tests matching keywords") | ||||
parser.add_argument("-c", "--cover", action="store_true", | selection.add_argument("-r", "--retest", action="store_true", | ||||
help="print a test coverage report") | help = "retest failed tests") | ||||
parser.add_argument("--color", choices=["always", "auto", "never"], | selection.add_argument("--test-list", action="append", | ||||
default=os.environ.get('HGRUNTESTSCOLOR', 'auto'), | help="read tests to run from the specified file") | ||||
help="colorisation: always|auto|never (default: auto)") | selection.add_argument("--whitelist", action="append", | ||||
parser.add_argument("-d", "--debug", action="store_true", | help="always run tests listed in the specified whitelist file") | ||||
selection.add_argument('tests', metavar='TESTS', nargs='*', | |||||
help='Tests to run') | |||||
harness = parser.add_argument_group('Test Harness Behavior') | |||||
harness.add_argument('--bisect-repo', | |||||
metavar='bisect_repo', | |||||
help=("Path of a repo to bisect. Use together with " | |||||
"--known-good-rev")) | |||||
harness.add_argument("-d", "--debug", action="store_true", | |||||
help="debug mode: write output of test scripts to console" | help="debug mode: write output of test scripts to console" | ||||
" rather than capturing and diffing it (disables timeout)") | " rather than capturing and diffing it (disables timeout)") | ||||
parser.add_argument("-f", "--first", action="store_true", | harness.add_argument("-f", "--first", action="store_true", | ||||
help="exit on the first test failure") | help="exit on the first test failure") | ||||
parser.add_argument("-H", "--htmlcov", action="store_true", | harness.add_argument("-i", "--interactive", action="store_true", | ||||
help="create an HTML report of the coverage of the files") | |||||
parser.add_argument("-i", "--interactive", action="store_true", | |||||
help="prompt to accept changed output") | help="prompt to accept changed output") | ||||
parser.add_argument("-j", "--jobs", type=int, | harness.add_argument("-j", "--jobs", type=int, | ||||
help="number of jobs to run in parallel" | help="number of jobs to run in parallel" | ||||
" (default: $%s or %d)" % defaults['jobs']) | " (default: $%s or %d)" % defaults['jobs']) | ||||
parser.add_argument("--keep-tmpdir", action="store_true", | harness.add_argument("--keep-tmpdir", action="store_true", | ||||
help="keep temporary directory after running tests") | help="keep temporary directory after running tests") | ||||
parser.add_argument("-k", "--keywords", | harness.add_argument('--known-good-rev', | ||||
help="run tests matching keywords") | metavar="known_good_rev", | ||||
parser.add_argument("--list-tests", action="store_true", | help=("Automatically bisect any failures using this " | ||||
"revision as a known-good revision.")) | |||||
harness.add_argument("--list-tests", action="store_true", | |||||
help="list tests instead of running them") | help="list tests instead of running them") | ||||
parser.add_argument("-l", "--local", action="store_true", | harness.add_argument("--loop", action="store_true", | ||||
help="shortcut for --with-hg=<testdir>/../hg, " | |||||
"and --with-chg=<testdir>/../contrib/chg/chg if --chg is set") | |||||
parser.add_argument("--loop", action="store_true", | |||||
help="loop tests repeatedly") | help="loop tests repeatedly") | ||||
parser.add_argument("--runs-per-test", type=int, dest="runs_per_test", | harness.add_argument('--random', action="store_true", | ||||
help="run each test N times (default=1)", default=1) | help='run tests in random order') | ||||
parser.add_argument("-n", "--nodiff", action="store_true", | harness.add_argument("-p", "--port", type=int, | ||||
help="skip showing test changes") | |||||
parser.add_argument("--outputdir", | |||||
help="directory to write error logs to (default=test directory)") | |||||
parser.add_argument("-p", "--port", type=int, | |||||
help="port on which servers should listen" | help="port on which servers should listen" | ||||
" (default: $%s or %d)" % defaults['port']) | " (default: $%s or %d)" % defaults['port']) | ||||
parser.add_argument("--compiler", | harness.add_argument('--profile-runner', action='store_true', | ||||
help="compiler to build with") | help='run statprof on run-tests') | ||||
parser.add_argument("--pure", action="store_true", | harness.add_argument("-R", "--restart", action="store_true", | ||||
help="use pure Python code instead of C extensions") | |||||
parser.add_argument("-R", "--restart", action="store_true", | |||||
help="restart at last error") | help="restart at last error") | ||||
parser.add_argument("-r", "--retest", action="store_true", | harness.add_argument("--runs-per-test", type=int, dest="runs_per_test", | ||||
help="retest failed tests") | help="run each test N times (default=1)", default=1) | ||||
parser.add_argument("-S", "--noskips", action="store_true", | harness.add_argument("--shell", | ||||
help="don't report skip tests verbosely") | |||||
parser.add_argument("--shell", | |||||
help="shell to use (default: $%s or %s)" % defaults['shell']) | help="shell to use (default: $%s or %s)" % defaults['shell']) | ||||
parser.add_argument("-t", "--timeout", type=int, | harness.add_argument('--showchannels', action='store_true', | ||||
help="kill errant tests after TIMEOUT seconds" | help='show scheduling channels') | ||||
" (default: $%s or %d)" % defaults['timeout']) | harness.add_argument("--slowtimeout", type=int, | ||||
parser.add_argument("--slowtimeout", type=int, | |||||
help="kill errant slow tests after SLOWTIMEOUT seconds" | help="kill errant slow tests after SLOWTIMEOUT seconds" | ||||
" (default: $%s or %d)" % defaults['slowtimeout']) | " (default: $%s or %d)" % defaults['slowtimeout']) | ||||
parser.add_argument("--time", action="store_true", | harness.add_argument("-t", "--timeout", type=int, | ||||
help="time how long each test takes") | help="kill errant tests after TIMEOUT seconds" | ||||
parser.add_argument("--json", action="store_true", | " (default: $%s or %d)" % defaults['timeout']) | ||||
help="store test result data in 'report.json' file") | harness.add_argument("--tmpdir", | ||||
parser.add_argument("--tmpdir", | |||||
help="run tests in the given temporary directory" | help="run tests in the given temporary directory" | ||||
" (implies --keep-tmpdir)") | " (implies --keep-tmpdir)") | ||||
parser.add_argument("-v", "--verbose", action="store_true", | harness.add_argument("-v", "--verbose", action="store_true", | ||||
help="output verbose messages") | help="output verbose messages") | ||||
parser.add_argument("--xunit", | |||||
help="record xunit results at specified path") | hgconf = parser.add_argument_group('Mercurial Configuration') | ||||
parser.add_argument("--view", | hgconf.add_argument("--chg", action="store_true", | ||||
help="external diff viewer") | |||||
parser.add_argument("--with-hg", | |||||
metavar="HG", | |||||
help="test using specified hg script rather than a " | |||||
"temporary installation") | |||||
parser.add_argument("--chg", action="store_true", | |||||
help="install and use chg wrapper in place of hg") | help="install and use chg wrapper in place of hg") | ||||
parser.add_argument("--with-chg", metavar="CHG", | hgconf.add_argument("--compiler", | ||||
help="use specified chg wrapper in place of hg") | help="compiler to build with") | ||||
parser.add_argument("--ipv6", action="store_true", | hgconf.add_argument('--extra-config-opt', action="append", | ||||
help='set the given config opt in the test hgrc') | |||||
hgconf.add_argument("-l", "--local", action="store_true", | |||||
help="shortcut for --with-hg=<testdir>/../hg, " | |||||
"and --with-chg=<testdir>/../contrib/chg/chg if --chg is set") | |||||
hgconf.add_argument("--ipv6", action="store_true", | |||||
help="prefer IPv6 to IPv4 for network related tests") | help="prefer IPv6 to IPv4 for network related tests") | ||||
parser.add_argument("-3", "--py3k-warnings", action="store_true", | hgconf.add_argument("--pure", action="store_true", | ||||
help="use pure Python code instead of C extensions") | |||||
hgconf.add_argument("-3", "--py3k-warnings", action="store_true", | |||||
help="enable Py3k warnings on Python 2.7+") | help="enable Py3k warnings on Python 2.7+") | ||||
hgconf.add_argument("--with-chg", metavar="CHG", | |||||
help="use specified chg wrapper in place of hg") | |||||
hgconf.add_argument("--with-hg", | |||||
metavar="HG", | |||||
help="test using specified hg script rather than a " | |||||
"temporary installation") | |||||
# This option should be deleted once test-check-py3-compat.t and other | # This option should be deleted once test-check-py3-compat.t and other | ||||
# Python 3 tests run with Python 3. | # Python 3 tests run with Python 3. | ||||
parser.add_argument("--with-python3", metavar="PYTHON3", | hgconf.add_argument("--with-python3", metavar="PYTHON3", | ||||
help="Python 3 interpreter (if running under Python 2)" | help="Python 3 interpreter (if running under Python 2)" | ||||
" (TEMPORARY)") | " (TEMPORARY)") | ||||
parser.add_argument('--extra-config-opt', action="append", | |||||
help='set the given config opt in the test hgrc') | |||||
parser.add_argument('--random', action="store_true", | |||||
help='run tests in random order') | |||||
parser.add_argument('--profile-runner', action='store_true', | |||||
help='run statprof on run-tests') | |||||
parser.add_argument('--allow-slow-tests', action='store_true', | |||||
help='allow extremely slow tests') | |||||
parser.add_argument('--showchannels', action='store_true', | |||||
help='show scheduling channels') | |||||
parser.add_argument('--known-good-rev', | |||||
metavar="known_good_rev", | |||||
help=("Automatically bisect any failures using this " | |||||
"revision as a known-good revision.")) | |||||
parser.add_argument('--bisect-repo', | |||||
metavar='bisect_repo', | |||||
help=("Path of a repo to bisect. Use together with " | |||||
"--known-good-rev")) | |||||
parser.add_argument('tests', metavar='TESTS', nargs='*', | reporting = parser.add_argument_group('Results Reporting') | ||||
help='Tests to run') | reporting.add_argument("-C", "--annotate", action="store_true", | ||||
help="output files annotated with coverage") | |||||
reporting.add_argument("--color", choices=["always", "auto", "never"], | |||||
default=os.environ.get('HGRUNTESTSCOLOR', 'auto'), | |||||
help="colorisation: always|auto|never (default: auto)") | |||||
reporting.add_argument("-c", "--cover", action="store_true", | |||||
help="print a test coverage report") | |||||
reporting.add_argument("-H", "--htmlcov", action="store_true", | |||||
help="create an HTML report of the coverage of the files") | |||||
reporting.add_argument("--json", action="store_true", | |||||
help="store test result data in 'report.json' file") | |||||
reporting.add_argument("--outputdir", | |||||
help="directory to write error logs to (default=test directory)") | |||||
reporting.add_argument("-n", "--nodiff", action="store_true", | |||||
help="skip showing test changes") | |||||
reporting.add_argument("-S", "--noskips", action="store_true", | |||||
help="don't report skip tests verbosely") | |||||
reporting.add_argument("--time", action="store_true", | |||||
help="time how long each test takes") | |||||
reporting.add_argument("--view", | |||||
help="external diff viewer") | |||||
reporting.add_argument("--xunit", | |||||
help="record xunit results at specified path") | |||||
for option, (envvar, default) in defaults.items(): | for option, (envvar, default) in defaults.items(): | ||||
defaults[option] = type(default)(os.environ.get(envvar, default)) | defaults[option] = type(default)(os.environ.get(envvar, default)) | ||||
parser.set_defaults(**defaults) | parser.set_defaults(**defaults) | ||||
return parser | return parser | ||||
def parseargs(args, parser): | def parseargs(args, parser): |