tests/run-tests.py
changeset 742 a3594a64511f
parent 741 e5bfe51eeea9
child 775 16f4cb2900fe
equal deleted inserted replaced
737:dc8fe24c628e 742:a3594a64511f
    81     'port': ('HGTEST_PORT', 20059),
    81     'port': ('HGTEST_PORT', 20059),
    82 }
    82 }
    83 
    83 
    84 def parseargs():
    84 def parseargs():
    85     parser = optparse.OptionParser("%prog [options] [tests]")
    85     parser = optparse.OptionParser("%prog [options] [tests]")
       
    86 
       
    87     # keep these sorted
       
    88     parser.add_option("--blacklist", action="append",
       
    89         help="skip tests listed in the specified blacklist file")
    86     parser.add_option("-C", "--annotate", action="store_true",
    90     parser.add_option("-C", "--annotate", action="store_true",
    87         help="output files annotated with coverage")
    91         help="output files annotated with coverage")
    88     parser.add_option("--child", type="int",
    92     parser.add_option("--child", type="int",
    89         help="run as child process, summary to given fd")
    93         help="run as child process, summary to given fd")
    90     parser.add_option("-c", "--cover", action="store_true",
    94     parser.add_option("-c", "--cover", action="store_true",
    91         help="print a test coverage report")
    95         help="print a test coverage report")
       
    96     parser.add_option("-d", "--debug", action="store_true",
       
    97         help="debug mode: write output of test scripts to console"
       
    98              " rather than capturing and diff'ing it (disables timeout)")
    92     parser.add_option("-f", "--first", action="store_true",
    99     parser.add_option("-f", "--first", action="store_true",
    93         help="exit on the first test failure")
   100         help="exit on the first test failure")
       
   101     parser.add_option("--inotify", action="store_true",
       
   102         help="enable inotify extension when running tests")
    94     parser.add_option("-i", "--interactive", action="store_true",
   103     parser.add_option("-i", "--interactive", action="store_true",
    95         help="prompt to accept changed output")
   104         help="prompt to accept changed output")
    96     parser.add_option("-j", "--jobs", type="int",
   105     parser.add_option("-j", "--jobs", type="int",
    97         help="number of jobs to run in parallel"
   106         help="number of jobs to run in parallel"
    98              " (default: $%s or %d)" % defaults['jobs'])
   107              " (default: $%s or %d)" % defaults['jobs'])
       
   108     parser.add_option("--keep-tmpdir", action="store_true",
       
   109         help="keep temporary directory after running tests")
    99     parser.add_option("-k", "--keywords",
   110     parser.add_option("-k", "--keywords",
   100         help="run tests matching keywords")
   111         help="run tests matching keywords")
   101     parser.add_option("--keep-tmpdir", action="store_true",
   112     parser.add_option("-l", "--local", action="store_true",
   102         help="keep temporary directory after running tests")
   113         help="shortcut for --with-hg=<testdir>/../hg")
   103     parser.add_option("--tmpdir", type="string",
   114     parser.add_option("-n", "--nodiff", action="store_true",
   104         help="run tests in the given temporary directory"
   115         help="skip showing test changes")
   105              " (implies --keep-tmpdir)")
       
   106     parser.add_option("-d", "--debug", action="store_true",
       
   107         help="debug mode: write output of test scripts to console"
       
   108              " rather than capturing and diff'ing it (disables timeout)")
       
   109     parser.add_option("-R", "--restart", action="store_true",
       
   110         help="restart at last error")
       
   111     parser.add_option("-p", "--port", type="int",
   116     parser.add_option("-p", "--port", type="int",
   112         help="port on which servers should listen"
   117         help="port on which servers should listen"
   113              " (default: $%s or %d)" % defaults['port'])
   118              " (default: $%s or %d)" % defaults['port'])
       
   119     parser.add_option("--pure", action="store_true",
       
   120         help="use pure Python code instead of C extensions")
       
   121     parser.add_option("-R", "--restart", action="store_true",
       
   122         help="restart at last error")
   114     parser.add_option("-r", "--retest", action="store_true",
   123     parser.add_option("-r", "--retest", action="store_true",
   115         help="retest failed tests")
   124         help="retest failed tests")
   116     parser.add_option("-S", "--noskips", action="store_true",
   125     parser.add_option("-S", "--noskips", action="store_true",
   117         help="don't report skip tests verbosely")
   126         help="don't report skip tests verbosely")
   118     parser.add_option("-t", "--timeout", type="int",
   127     parser.add_option("-t", "--timeout", type="int",
   119         help="kill errant tests after TIMEOUT seconds"
   128         help="kill errant tests after TIMEOUT seconds"
   120              " (default: $%s or %d)" % defaults['timeout'])
   129              " (default: $%s or %d)" % defaults['timeout'])
       
   130     parser.add_option("--tmpdir", type="string",
       
   131         help="run tests in the given temporary directory"
       
   132              " (implies --keep-tmpdir)")
   121     parser.add_option("-v", "--verbose", action="store_true",
   133     parser.add_option("-v", "--verbose", action="store_true",
   122         help="output verbose messages")
   134         help="output verbose messages")
   123     parser.add_option("-n", "--nodiff", action="store_true",
   135     parser.add_option("--view", type="string",
   124         help="skip showing test changes")
   136         help="external diff viewer")
   125     parser.add_option("--with-hg", type="string",
   137     parser.add_option("--with-hg", type="string",
   126         metavar="HG",
   138         metavar="HG",
   127         help="test using specified hg script rather than a "
   139         help="test using specified hg script rather than a "
   128              "temporary installation")
   140              "temporary installation")
   129     parser.add_option("--local", action="store_true",
       
   130         help="shortcut for --with-hg=<testdir>/../hg")
       
   131     parser.add_option("--pure", action="store_true",
       
   132         help="use pure Python code instead of C extensions")
       
   133     parser.add_option("-3", "--py3k-warnings", action="store_true",
   141     parser.add_option("-3", "--py3k-warnings", action="store_true",
   134         help="enable Py3k warnings on Python 2.6+")
   142         help="enable Py3k warnings on Python 2.6+")
   135     parser.add_option("--inotify", action="store_true",
       
   136         help="enable inotify extension when running tests")
       
   137     parser.add_option("--blacklist", action="append",
       
   138         help="skip tests listed in the specified blacklist file")
       
   139 
   143 
   140     for option, default in defaults.items():
   144     for option, default in defaults.items():
   141         defaults[option] = int(os.environ.get(*default))
   145         defaults[option] = int(os.environ.get(*default))
   142     parser.set_defaults(**defaults)
   146     parser.set_defaults(**defaults)
   143     (options, args) = parser.parse_args()
   147     (options, args) = parser.parse_args()
   569         signal.alarm(0)
   573         signal.alarm(0)
   570 
   574 
   571     mark = '.'
   575     mark = '.'
   572 
   576 
   573     skipped = (ret == SKIPPED_STATUS)
   577     skipped = (ret == SKIPPED_STATUS)
       
   578 
   574     # If we're not in --debug mode and reference output file exists,
   579     # If we're not in --debug mode and reference output file exists,
   575     # check test output against it.
   580     # check test output against it.
   576     if options.debug:
   581     if options.debug:
   577         refout = None                   # to match out == None
   582         refout = None                   # to match out == None
   578     elif os.path.exists(ref):
   583     elif os.path.exists(ref):
   579         f = open(ref, "r")
   584         f = open(ref, "r")
   580         refout = splitnewlines(f.read())
   585         refout = splitnewlines(f.read())
   581         f.close()
   586         f.close()
   582     else:
   587     else:
   583         refout = []
   588         refout = []
       
   589 
       
   590     if (ret != 0 or out != refout) and not skipped and not options.debug:
       
   591         # Save errors to a file for diagnosis
       
   592         f = open(err, "wb")
       
   593         for line in out:
       
   594             f.write(line)
       
   595         f.close()
   584 
   596 
   585     if skipped:
   597     if skipped:
   586         mark = 's'
   598         mark = 's'
   587         if out is None:                 # debug mode: nothing to parse
   599         if out is None:                 # debug mode: nothing to parse
   588             missing = ['unknown']
   600             missing = ['unknown']
   601         if ret:
   613         if ret:
   602             fail("output changed and returned error code %d" % ret)
   614             fail("output changed and returned error code %d" % ret)
   603         else:
   615         else:
   604             fail("output changed")
   616             fail("output changed")
   605         if not options.nodiff:
   617         if not options.nodiff:
   606             showdiff(refout, out, ref, err)
   618             if options.view:
       
   619                 os.system("%s %s %s" % (options.view, ref, err))
       
   620             else:
       
   621                 showdiff(refout, out, ref, err)
   607         ret = 1
   622         ret = 1
   608     elif ret:
   623     elif ret:
   609         mark = '!'
   624         mark = '!'
   610         fail("returned error code %d" % ret)
   625         fail("returned error code %d" % ret)
   611 
   626 
   612     if not options.verbose:
   627     if not options.verbose:
   613         sys.stdout.write(mark)
   628         sys.stdout.write(mark)
   614         sys.stdout.flush()
   629         sys.stdout.flush()
   615 
       
   616     if ret != 0 and not skipped and not options.debug:
       
   617         # Save errors to a file for diagnosis
       
   618         f = open(err, "wb")
       
   619         for line in out:
       
   620             f.write(line)
       
   621         f.close()
       
   622 
   630 
   623     killdaemons()
   631     killdaemons()
   624 
   632 
   625     os.chdir(TESTDIR)
   633     os.chdir(TESTDIR)
   626     if not options.keep_tmpdir:
   634     if not options.keep_tmpdir: