474 |
474 |
475 def pytest(test, wd, options, replacements): |
475 def pytest(test, wd, options, replacements): |
476 py3kswitch = options.py3k_warnings and ' -3' or '' |
476 py3kswitch = options.py3k_warnings and ' -3' or '' |
477 cmd = '%s%s "%s"' % (PYTHON, py3kswitch, test) |
477 cmd = '%s%s "%s"' % (PYTHON, py3kswitch, test) |
478 vlog("# Running", cmd) |
478 vlog("# Running", cmd) |
479 return run(cmd, wd, options, replacements) |
479 if os.name == 'nt': |
480 |
480 replacements.append((r'\r\n', '\n')) |
481 def shtest(test, wd, options, replacements): |
|
482 cmd = '%s "%s"' % (options.shell, test) |
|
483 vlog("# Running", cmd) |
|
484 return run(cmd, wd, options, replacements) |
481 return run(cmd, wd, options, replacements) |
485 |
482 |
486 needescape = re.compile(r'[\x00-\x08\x0b-\x1f\x7f-\xff]').search |
483 needescape = re.compile(r'[\x00-\x08\x0b-\x1f\x7f-\xff]').search |
487 escapesub = re.compile(r'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub |
484 escapesub = re.compile(r'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub |
488 escapemap = dict((chr(i), r'\x%02x' % i) for i in range(256)) |
485 escapemap = dict((chr(i), r'\x%02x' % i) for i in range(256)) |
492 def stringescape(s): |
489 def stringescape(s): |
493 return escapesub(escapef, s) |
490 return escapesub(escapef, s) |
494 |
491 |
495 def rematch(el, l): |
492 def rematch(el, l): |
496 try: |
493 try: |
497 # ensure that the regex matches to the end of the string |
494 # use \Z to ensure that the regex matches to the end of the string |
498 return re.match(el + r'\Z', l) |
495 if os.name == 'nt': |
|
496 return re.match(el + r'\r?\n\Z', l) |
|
497 return re.match(el + r'\n\Z', l) |
499 except re.error: |
498 except re.error: |
500 # el is an invalid regex |
499 # el is an invalid regex |
501 return False |
500 return False |
502 |
501 |
503 def globmatch(el, l): |
502 def globmatch(el, l): |
522 return rematch(res, l) |
521 return rematch(res, l) |
523 |
522 |
524 def linematch(el, l): |
523 def linematch(el, l): |
525 if el == l: # perfect match (fast) |
524 if el == l: # perfect match (fast) |
526 return True |
525 return True |
527 if (el and |
526 if el: |
528 (el.endswith(" (re)\n") and rematch(el[:-6] + '\n', l) or |
527 if el.endswith(" (esc)\n"): |
529 el.endswith(" (glob)\n") and globmatch(el[:-8] + '\n', l) or |
528 el = el[:-7].decode('string-escape') + '\n' |
530 el.endswith(" (esc)\n") and |
529 if el == l or os.name == 'nt' and el[:-1] + '\r\n' == l: |
531 (el[:-7].decode('string-escape') + '\n' == l or |
530 return True |
532 el[:-7].decode('string-escape').replace('\r', '') + |
531 if (el.endswith(" (re)\n") and rematch(el[:-6], l) or |
533 '\n' == l and os.name == 'nt'))): |
532 el.endswith(" (glob)\n") and globmatch(el[:-8], l)): |
534 return True |
533 return True |
535 return False |
534 return False |
536 |
535 |
537 def tsttest(test, wd, options, replacements): |
536 def tsttest(test, wd, options, replacements): |
538 # We generate a shell script which outputs unique markers to line |
537 # We generate a shell script which outputs unique markers to line |
539 # up script results with our source. These markers include input |
538 # up script results with our source. These markers include input |
868 runner = pytest |
867 runner = pytest |
869 elif lctest.endswith('.t'): |
868 elif lctest.endswith('.t'): |
870 runner = tsttest |
869 runner = tsttest |
871 ref = testpath |
870 ref = testpath |
872 else: |
871 else: |
873 # do not try to run non-executable programs |
872 return skip("unknown test type") |
874 if not os.access(testpath, os.X_OK): |
|
875 return skip("not executable") |
|
876 runner = shtest |
|
877 |
873 |
878 # Make a tmp subdirectory to work in |
874 # Make a tmp subdirectory to work in |
879 testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \ |
875 testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \ |
880 os.path.join(HGTMP, os.path.basename(test)) |
876 os.path.join(HGTMP, os.path.basename(test)) |
881 |
877 |
883 (r':%s\b' % options.port, ':$HGPORT'), |
879 (r':%s\b' % options.port, ':$HGPORT'), |
884 (r':%s\b' % (options.port + 1), ':$HGPORT1'), |
880 (r':%s\b' % (options.port + 1), ':$HGPORT1'), |
885 (r':%s\b' % (options.port + 2), ':$HGPORT2'), |
881 (r':%s\b' % (options.port + 2), ':$HGPORT2'), |
886 ] |
882 ] |
887 if os.name == 'nt': |
883 if os.name == 'nt': |
888 replacements.append((r'\r\n', '\n')) |
|
889 replacements.append( |
884 replacements.append( |
890 (''.join(c.isalpha() and '[%s%s]' % (c.lower(), c.upper()) or |
885 (''.join(c.isalpha() and '[%s%s]' % (c.lower(), c.upper()) or |
891 c in '/\\' and r'[/\\]' or |
886 c in '/\\' and r'[/\\]' or |
892 c.isdigit() and c or |
887 c.isdigit() and c or |
893 '\\' + c |
888 '\\' + c |