tests/run-tests.py
changeset 1021 4ecaec765d76
parent 1019 e7fbd63e5a98
child 1022 34ebea1c49c9
equal deleted inserted replaced
1020:5dc5c899428a 1021:4ecaec765d76
    85 
    85 
    86 # reserved exit code to skip test (used by hghave)
    86 # reserved exit code to skip test (used by hghave)
    87 SKIPPED_STATUS = 80
    87 SKIPPED_STATUS = 80
    88 SKIPPED_PREFIX = 'skipped: '
    88 SKIPPED_PREFIX = 'skipped: '
    89 FAILED_PREFIX  = 'hghave check failed: '
    89 FAILED_PREFIX  = 'hghave check failed: '
    90 PYTHON = sys.executable
    90 PYTHON = sys.executable.replace('\\', '/')
    91 IMPL_PATH = 'PYTHONPATH'
    91 IMPL_PATH = 'PYTHONPATH'
    92 if 'java' in sys.platform:
    92 if 'java' in sys.platform:
    93     IMPL_PATH = 'JYTHONPATH'
    93     IMPL_PATH = 'JYTHONPATH'
    94 
    94 
    95 requiredtools = ["python", "diff", "grep", "unzip", "gunzip", "bunzip2", "sed"]
    95 requiredtools = ["python", "diff", "grep", "unzip", "gunzip", "bunzip2", "sed"]
   528     except re.error:
   528     except re.error:
   529         # el is an invalid regex
   529         # el is an invalid regex
   530         return False
   530         return False
   531 
   531 
   532 def globmatch(el, l):
   532 def globmatch(el, l):
   533     # The only supported special characters are * and ?. Escaping is
   533     # The only supported special characters are * and ? plus / which also
   534     # supported.
   534     # matches \ on windows. Escaping of these caracters is supported.
   535     i, n = 0, len(el)
   535     i, n = 0, len(el)
   536     res = ''
   536     res = ''
   537     while i < n:
   537     while i < n:
   538         c = el[i]
   538         c = el[i]
   539         i += 1
   539         i += 1
   540         if c == '\\' and el[i] in '*?\\':
   540         if c == '\\' and el[i] in '*?\\/':
   541             res += el[i - 1:i + 1]
   541             res += el[i - 1:i + 1]
   542             i += 1
   542             i += 1
   543         elif c == '*':
   543         elif c == '*':
   544             res += '.*'
   544             res += '.*'
   545         elif c == '?':
   545         elif c == '?':
   546             res += '.'
   546             res += '.'
       
   547         elif c == '/' and os.name == 'nt':
       
   548             res += '[/\\\\]'
   547         else:
   549         else:
   548             res += re.escape(c)
   550             res += re.escape(c)
   549     return rematch(res, l)
   551     return rematch(res, l)
   550 
   552 
   551 def linematch(el, l):
   553 def linematch(el, l):
   552     if el == l: # perfect match (fast)
   554     if el == l: # perfect match (fast)
   553         return True
   555         return True
   554     if (el and
   556     if (el and
   555         (el.endswith(" (re)\n") and rematch(el[:-6] + '\n', l) or
   557         (el.endswith(" (re)\n") and rematch(el[:-6] + '\n', l) or
   556          el.endswith(" (glob)\n") and globmatch(el[:-8] + '\n', l) or
   558          el.endswith(" (glob)\n") and globmatch(el[:-8] + '\n', l) or
   557          el.endswith(" (esc)\n") and el.decode('string-escape') == l)):
   559          el.endswith(" (esc)\n") and
       
   560              (el[:-7].decode('string-escape') + '\n' == l or
       
   561               el[:-7].decode('string-escape').replace('\r', '') +
       
   562                   '\n' == l and os.name == 'nt'))):
   558         return True
   563         return True
   559     return False
   564     return False
   560 
   565 
   561 def tsttest(test, wd, options, replacements):
   566 def tsttest(test, wd, options, replacements):
   562     # We generate a shell script which outputs unique markers to line
   567     # We generate a shell script which outputs unique markers to line
   636     try:
   641     try:
   637         for l in script:
   642         for l in script:
   638             os.write(fd, l)
   643             os.write(fd, l)
   639         os.close(fd)
   644         os.close(fd)
   640 
   645 
   641         cmd = '"%s" "%s"' % (options.shell, name)
   646         cmd = '%s "%s"' % (options.shell, name)
   642         vlog("# Running", cmd)
   647         vlog("# Running", cmd)
   643         exitcode, output = run(cmd, wd, options, replacements)
   648         exitcode, output = run(cmd, wd, options, replacements)
   644         # do not merge output if skipped, return hghave message instead
   649         # do not merge output if skipped, return hghave message instead
   645         # similarly, with --debug, output is None
   650         # similarly, with --debug, output is None
   646         if exitcode == SKIPPED_STATUS or output is None:
   651         if exitcode == SKIPPED_STATUS or output is None:
   860             return skip("not executable")
   865             return skip("not executable")
   861         runner = shtest
   866         runner = shtest
   862 
   867 
   863     # Make a tmp subdirectory to work in
   868     # Make a tmp subdirectory to work in
   864     testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \
   869     testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \
   865         os.path.join(HGTMP, os.path.basename(test))
   870         os.path.join(HGTMP, os.path.basename(test)).replace('\\', '/')
   866 
   871 
   867     os.mkdir(testtmp)
   872     replacements = [
   868     ret, out = runner(testpath, testtmp, options, [
       
   869         (re.escape(testtmp), '$TESTTMP'),
       
   870         (r':%s\b' % options.port, ':$HGPORT'),
   873         (r':%s\b' % options.port, ':$HGPORT'),
   871         (r':%s\b' % (options.port + 1), ':$HGPORT1'),
   874         (r':%s\b' % (options.port + 1), ':$HGPORT1'),
   872         (r':%s\b' % (options.port + 2), ':$HGPORT2'),
   875         (r':%s\b' % (options.port + 2), ':$HGPORT2'),
   873         ])
   876         ]
       
   877     if os.name == 'nt':
       
   878         replacements.append((r'\r\n', '\n'))
       
   879         replacements.append(
       
   880             (''.join(c.isalpha() and '[%s%s]' % (c.lower(), c.upper()) or
       
   881                      c in '/\\' and r'[/\\]' or
       
   882                      c.isdigit() and c or
       
   883                      '\\' + c
       
   884                      for c in testtmp), '$TESTTMP'))
       
   885     else:
       
   886         replacements.append((re.escape(testtmp), '$TESTTMP'))
       
   887 
       
   888     os.mkdir(testtmp)
       
   889     ret, out = runner(testpath, testtmp, options, replacements)
   874     vlog("# Ret was:", ret)
   890     vlog("# Ret was:", ret)
   875 
   891 
   876     mark = '.'
   892     mark = '.'
   877 
   893 
   878     skipped = (ret == SKIPPED_STATUS)
   894     skipped = (ret == SKIPPED_STATUS)