tests/run-tests.py
changeset 35199 d997b82152e8
parent 35198 b4b0aed7bfaf
child 35200 073843b5e353
equal deleted inserted replaced
35198:b4b0aed7bfaf 35199:d997b82152e8
   296 
   296 
   297 def getparser():
   297 def getparser():
   298     """Obtain the OptionParser used by the CLI."""
   298     """Obtain the OptionParser used by the CLI."""
   299     parser = argparse.ArgumentParser(usage='%(prog)s [options] [tests]')
   299     parser = argparse.ArgumentParser(usage='%(prog)s [options] [tests]')
   300 
   300 
   301     # keep these sorted
   301     selection = parser.add_argument_group('Test Selection')
   302     parser.add_argument("--blacklist", action="append",
   302     selection.add_argument('--allow-slow-tests', action='store_true',
       
   303         help='allow extremely slow tests')
       
   304     selection.add_argument("--blacklist", action="append",
   303         help="skip tests listed in the specified blacklist file")
   305         help="skip tests listed in the specified blacklist file")
   304     parser.add_argument("--whitelist", action="append",
   306     selection.add_argument("--changed",
       
   307         help="run tests that are changed in parent rev or working directory")
       
   308     selection.add_argument("-k", "--keywords",
       
   309         help="run tests matching keywords")
       
   310     selection.add_argument("-r", "--retest", action="store_true",
       
   311         help = "retest failed tests")
       
   312     selection.add_argument("--test-list", action="append",
       
   313         help="read tests to run from the specified file")
       
   314     selection.add_argument("--whitelist", action="append",
   305         help="always run tests listed in the specified whitelist file")
   315         help="always run tests listed in the specified whitelist file")
   306     parser.add_argument("--test-list", action="append",
   316     selection.add_argument('tests', metavar='TESTS', nargs='*',
   307         help="read tests to run from the specified file")
   317                         help='Tests to run')
   308     parser.add_argument("--changed",
   318 
   309         help="run tests that are changed in parent rev or working directory")
   319     harness = parser.add_argument_group('Test Harness Behavior')
   310     parser.add_argument("-C", "--annotate", action="store_true",
   320     harness.add_argument('--bisect-repo',
   311         help="output files annotated with coverage")
   321                         metavar='bisect_repo',
   312     parser.add_argument("-c", "--cover", action="store_true",
   322                         help=("Path of a repo to bisect. Use together with "
   313         help="print a test coverage report")
   323                               "--known-good-rev"))
   314     parser.add_argument("--color", choices=["always", "auto", "never"],
   324     harness.add_argument("-d", "--debug", action="store_true",
   315                         default=os.environ.get('HGRUNTESTSCOLOR', 'auto'),
       
   316                         help="colorisation: always|auto|never (default: auto)")
       
   317     parser.add_argument("-d", "--debug", action="store_true",
       
   318         help="debug mode: write output of test scripts to console"
   325         help="debug mode: write output of test scripts to console"
   319              " rather than capturing and diffing it (disables timeout)")
   326              " rather than capturing and diffing it (disables timeout)")
   320     parser.add_argument("-f", "--first", action="store_true",
   327     harness.add_argument("-f", "--first", action="store_true",
   321         help="exit on the first test failure")
   328         help="exit on the first test failure")
   322     parser.add_argument("-H", "--htmlcov", action="store_true",
   329     harness.add_argument("-i", "--interactive", action="store_true",
   323         help="create an HTML report of the coverage of the files")
       
   324     parser.add_argument("-i", "--interactive", action="store_true",
       
   325         help="prompt to accept changed output")
   330         help="prompt to accept changed output")
   326     parser.add_argument("-j", "--jobs", type=int,
   331     harness.add_argument("-j", "--jobs", type=int,
   327         help="number of jobs to run in parallel"
   332         help="number of jobs to run in parallel"
   328              " (default: $%s or %d)" % defaults['jobs'])
   333              " (default: $%s or %d)" % defaults['jobs'])
   329     parser.add_argument("--keep-tmpdir", action="store_true",
   334     harness.add_argument("--keep-tmpdir", action="store_true",
   330         help="keep temporary directory after running tests")
   335         help="keep temporary directory after running tests")
   331     parser.add_argument("-k", "--keywords",
   336     harness.add_argument('--known-good-rev',
   332         help="run tests matching keywords")
   337                         metavar="known_good_rev",
   333     parser.add_argument("--list-tests", action="store_true",
   338                         help=("Automatically bisect any failures using this "
       
   339                               "revision as a known-good revision."))
       
   340     harness.add_argument("--list-tests", action="store_true",
   334         help="list tests instead of running them")
   341         help="list tests instead of running them")
   335     parser.add_argument("-l", "--local", action="store_true",
   342     harness.add_argument("--loop", action="store_true",
       
   343         help="loop tests repeatedly")
       
   344     harness.add_argument('--random', action="store_true",
       
   345         help='run tests in random order')
       
   346     harness.add_argument("-p", "--port", type=int,
       
   347         help="port on which servers should listen"
       
   348              " (default: $%s or %d)" % defaults['port'])
       
   349     harness.add_argument('--profile-runner', action='store_true',
       
   350                         help='run statprof on run-tests')
       
   351     harness.add_argument("-R", "--restart", action="store_true",
       
   352         help="restart at last error")
       
   353     harness.add_argument("--runs-per-test", type=int, dest="runs_per_test",
       
   354         help="run each test N times (default=1)", default=1)
       
   355     harness.add_argument("--shell",
       
   356         help="shell to use (default: $%s or %s)" % defaults['shell'])
       
   357     harness.add_argument('--showchannels', action='store_true',
       
   358                         help='show scheduling channels')
       
   359     harness.add_argument("--slowtimeout", type=int,
       
   360         help="kill errant slow tests after SLOWTIMEOUT seconds"
       
   361              " (default: $%s or %d)" % defaults['slowtimeout'])
       
   362     harness.add_argument("-t", "--timeout", type=int,
       
   363         help="kill errant tests after TIMEOUT seconds"
       
   364              " (default: $%s or %d)" % defaults['timeout'])
       
   365     harness.add_argument("--tmpdir",
       
   366         help="run tests in the given temporary directory"
       
   367              " (implies --keep-tmpdir)")
       
   368     harness.add_argument("-v", "--verbose", action="store_true",
       
   369         help="output verbose messages")
       
   370 
       
   371     hgconf = parser.add_argument_group('Mercurial Configuration')
       
   372     hgconf.add_argument("--chg", action="store_true",
       
   373         help="install and use chg wrapper in place of hg")
       
   374     hgconf.add_argument("--compiler",
       
   375         help="compiler to build with")
       
   376     hgconf.add_argument('--extra-config-opt', action="append",
       
   377         help='set the given config opt in the test hgrc')
       
   378     hgconf.add_argument("-l", "--local", action="store_true",
   336         help="shortcut for --with-hg=<testdir>/../hg, "
   379         help="shortcut for --with-hg=<testdir>/../hg, "
   337              "and --with-chg=<testdir>/../contrib/chg/chg if --chg is set")
   380              "and --with-chg=<testdir>/../contrib/chg/chg if --chg is set")
   338     parser.add_argument("--loop", action="store_true",
   381     hgconf.add_argument("--ipv6", action="store_true",
   339         help="loop tests repeatedly")
   382         help="prefer IPv6 to IPv4 for network related tests")
   340     parser.add_argument("--runs-per-test", type=int, dest="runs_per_test",
   383     hgconf.add_argument("--pure", action="store_true",
   341         help="run each test N times (default=1)", default=1)
       
   342     parser.add_argument("-n", "--nodiff", action="store_true",
       
   343         help="skip showing test changes")
       
   344     parser.add_argument("--outputdir",
       
   345         help="directory to write error logs to (default=test directory)")
       
   346     parser.add_argument("-p", "--port", type=int,
       
   347         help="port on which servers should listen"
       
   348              " (default: $%s or %d)" % defaults['port'])
       
   349     parser.add_argument("--compiler",
       
   350         help="compiler to build with")
       
   351     parser.add_argument("--pure", action="store_true",
       
   352         help="use pure Python code instead of C extensions")
   384         help="use pure Python code instead of C extensions")
   353     parser.add_argument("-R", "--restart", action="store_true",
   385     hgconf.add_argument("-3", "--py3k-warnings", action="store_true",
   354         help="restart at last error")
   386         help="enable Py3k warnings on Python 2.7+")
   355     parser.add_argument("-r", "--retest", action="store_true",
   387     hgconf.add_argument("--with-chg", metavar="CHG",
   356         help="retest failed tests")
   388         help="use specified chg wrapper in place of hg")
   357     parser.add_argument("-S", "--noskips", action="store_true",
   389     hgconf.add_argument("--with-hg",
   358         help="don't report skip tests verbosely")
       
   359     parser.add_argument("--shell",
       
   360         help="shell to use (default: $%s or %s)" % defaults['shell'])
       
   361     parser.add_argument("-t", "--timeout", type=int,
       
   362         help="kill errant tests after TIMEOUT seconds"
       
   363              " (default: $%s or %d)" % defaults['timeout'])
       
   364     parser.add_argument("--slowtimeout", type=int,
       
   365         help="kill errant slow tests after SLOWTIMEOUT seconds"
       
   366              " (default: $%s or %d)" % defaults['slowtimeout'])
       
   367     parser.add_argument("--time", action="store_true",
       
   368         help="time how long each test takes")
       
   369     parser.add_argument("--json", action="store_true",
       
   370         help="store test result data in 'report.json' file")
       
   371     parser.add_argument("--tmpdir",
       
   372         help="run tests in the given temporary directory"
       
   373              " (implies --keep-tmpdir)")
       
   374     parser.add_argument("-v", "--verbose", action="store_true",
       
   375         help="output verbose messages")
       
   376     parser.add_argument("--xunit",
       
   377         help="record xunit results at specified path")
       
   378     parser.add_argument("--view",
       
   379         help="external diff viewer")
       
   380     parser.add_argument("--with-hg",
       
   381         metavar="HG",
   390         metavar="HG",
   382         help="test using specified hg script rather than a "
   391         help="test using specified hg script rather than a "
   383              "temporary installation")
   392              "temporary installation")
   384     parser.add_argument("--chg", action="store_true",
       
   385                         help="install and use chg wrapper in place of hg")
       
   386     parser.add_argument("--with-chg", metavar="CHG",
       
   387                         help="use specified chg wrapper in place of hg")
       
   388     parser.add_argument("--ipv6", action="store_true",
       
   389                         help="prefer IPv6 to IPv4 for network related tests")
       
   390     parser.add_argument("-3", "--py3k-warnings", action="store_true",
       
   391         help="enable Py3k warnings on Python 2.7+")
       
   392     # This option should be deleted once test-check-py3-compat.t and other
   393     # This option should be deleted once test-check-py3-compat.t and other
   393     # Python 3 tests run with Python 3.
   394     # Python 3 tests run with Python 3.
   394     parser.add_argument("--with-python3", metavar="PYTHON3",
   395     hgconf.add_argument("--with-python3", metavar="PYTHON3",
   395                         help="Python 3 interpreter (if running under Python 2)"
   396         help="Python 3 interpreter (if running under Python 2)"
   396                              " (TEMPORARY)")
   397              " (TEMPORARY)")
   397     parser.add_argument('--extra-config-opt', action="append",
   398 
   398                         help='set the given config opt in the test hgrc')
   399     reporting = parser.add_argument_group('Results Reporting')
   399     parser.add_argument('--random', action="store_true",
   400     reporting.add_argument("-C", "--annotate", action="store_true",
   400                         help='run tests in random order')
   401         help="output files annotated with coverage")
   401     parser.add_argument('--profile-runner', action='store_true',
   402     reporting.add_argument("--color", choices=["always", "auto", "never"],
   402                         help='run statprof on run-tests')
   403         default=os.environ.get('HGRUNTESTSCOLOR', 'auto'),
   403     parser.add_argument('--allow-slow-tests', action='store_true',
   404         help="colorisation: always|auto|never (default: auto)")
   404                         help='allow extremely slow tests')
   405     reporting.add_argument("-c", "--cover", action="store_true",
   405     parser.add_argument('--showchannels', action='store_true',
   406         help="print a test coverage report")
   406                         help='show scheduling channels')
   407     reporting.add_argument("-H", "--htmlcov", action="store_true",
   407     parser.add_argument('--known-good-rev',
   408         help="create an HTML report of the coverage of the files")
   408                         metavar="known_good_rev",
   409     reporting.add_argument("--json", action="store_true",
   409                         help=("Automatically bisect any failures using this "
   410         help="store test result data in 'report.json' file")
   410                               "revision as a known-good revision."))
   411     reporting.add_argument("--outputdir",
   411     parser.add_argument('--bisect-repo',
   412         help="directory to write error logs to (default=test directory)")
   412                         metavar='bisect_repo',
   413     reporting.add_argument("-n", "--nodiff", action="store_true",
   413                         help=("Path of a repo to bisect. Use together with "
   414         help="skip showing test changes")
   414                               "--known-good-rev"))
   415     reporting.add_argument("-S", "--noskips", action="store_true",
   415 
   416         help="don't report skip tests verbosely")
   416     parser.add_argument('tests', metavar='TESTS', nargs='*',
   417     reporting.add_argument("--time", action="store_true",
   417                         help='Tests to run')
   418         help="time how long each test takes")
       
   419     reporting.add_argument("--view",
       
   420         help="external diff viewer")
       
   421     reporting.add_argument("--xunit",
       
   422         help="record xunit results at specified path")
   418 
   423 
   419     for option, (envvar, default) in defaults.items():
   424     for option, (envvar, default) in defaults.items():
   420         defaults[option] = type(default)(os.environ.get(envvar, default))
   425         defaults[option] = type(default)(os.environ.get(envvar, default))
   421     parser.set_defaults(**defaults)
   426     parser.set_defaults(**defaults)
   422 
   427