Show More
@@ -52,6 +52,7 b' import signal' | |||
|
52 | 52 | import sys |
|
53 | 53 | import tempfile |
|
54 | 54 | import time |
|
55 | import re | |
|
55 | 56 | |
|
56 | 57 | closefds = os.name == 'posix' |
|
57 | 58 | def Popen4(cmd, bufsize=-1): |
@@ -459,6 +460,69 b' def battest(test, options):' | |||
|
459 | 460 | vlog("# Running", cmd) |
|
460 | 461 | return run(cmd, options) |
|
461 | 462 | |
|
463 | def tsttest(test, options): | |
|
464 | t = open(test) | |
|
465 | out = [] | |
|
466 | script = [] | |
|
467 | salt = "SALT" + str(time.time()) | |
|
468 | ||
|
469 | pos = prepos = -1 | |
|
470 | after = {} | |
|
471 | expected = {} | |
|
472 | for n, l in enumerate(t): | |
|
473 | if l.startswith(' $ '): # commands | |
|
474 | after.setdefault(pos, []).append(l) | |
|
475 | prepos = pos | |
|
476 | pos = n | |
|
477 | script.append('echo %s %s\n' % (salt, n)) | |
|
478 | script.append(l[4:]) | |
|
479 | elif l.startswith(' > '): # continuations | |
|
480 | after.setdefault(prepos, []).append(l) | |
|
481 | script.append(l[4:]) | |
|
482 | elif l.startswith(' '): # results | |
|
483 | # queue up a list of expected results | |
|
484 | expected.setdefault(pos, []).append(l[2:]) | |
|
485 | else: | |
|
486 | # non-command/result - queue up for merged output | |
|
487 | after.setdefault(pos, []).append(l) | |
|
488 | ||
|
489 | fd, name = tempfile.mkstemp(suffix='hg-tst') | |
|
490 | ||
|
491 | try: | |
|
492 | for l in script: | |
|
493 | os.write(fd, l) | |
|
494 | os.close(fd) | |
|
495 | ||
|
496 | cmd = '/bin/sh "%s"' % name | |
|
497 | vlog("# Running", cmd) | |
|
498 | exitcode, output = run(cmd, options) | |
|
499 | finally: | |
|
500 | os.remove(name) | |
|
501 | ||
|
502 | pos = -1 | |
|
503 | postout = [] | |
|
504 | for n, l in enumerate(output): | |
|
505 | if l.startswith(salt): | |
|
506 | if pos in after: | |
|
507 | postout += after.pop(pos) | |
|
508 | pos = int(l.split()[1]) | |
|
509 | else: | |
|
510 | el = None | |
|
511 | if pos in expected and expected[pos]: | |
|
512 | el = expected[pos].pop(0) | |
|
513 | ||
|
514 | if el == l: # perfect match (fast) | |
|
515 | postout.append(" " + l) | |
|
516 | elif el and re.match(el, l): # fallback regex match | |
|
517 | postout.append(" " + el) | |
|
518 | else: # mismatch - let diff deal with it | |
|
519 | postout.append(" " + l) | |
|
520 | ||
|
521 | if pos in after: | |
|
522 | postout += after.pop(pos) | |
|
523 | ||
|
524 | return exitcode, postout | |
|
525 | ||
|
462 | 526 | def run(cmd, options): |
|
463 | 527 | """Run command in a sub-process, capturing the output (stdout and stderr). |
|
464 | 528 | Return a tuple (exitcode, output). output is None in debug mode.""" |
@@ -561,6 +625,9 b' def runone(options, test, skips, fails):' | |||
|
561 | 625 | if os.name != 'nt': |
|
562 | 626 | return skip("batch script") |
|
563 | 627 | runner = battest |
|
628 | elif lctest.endswith('.t'): | |
|
629 | runner = tsttest | |
|
630 | ref = testpath | |
|
564 | 631 | else: |
|
565 | 632 | # do not run shell scripts on windows |
|
566 | 633 | if os.name == 'nt': |
@@ -821,7 +888,10 b' def runtests(options, tests):' | |||
|
821 | 888 | print "Accept this change? [n] ", |
|
822 | 889 | answer = sys.stdin.readline().strip() |
|
823 | 890 | if answer.lower() in "y yes".split(): |
|
824 |
|
|
|
891 | if test.endswith(".t"): | |
|
892 | rename(test + ".err", test) | |
|
893 | else: | |
|
894 | rename(test + ".err", test + ".out") | |
|
825 | 895 | tested += 1 |
|
826 | 896 | fails.pop() |
|
827 | 897 | continue |
@@ -958,7 +1028,7 b' def main():' | |||
|
958 | 1028 | for test in args: |
|
959 | 1029 | if (test.startswith("test-") and '~' not in test and |
|
960 | 1030 | ('.' not in test or test.endswith('.py') or |
|
961 | test.endswith('.bat'))): | |
|
1031 | test.endswith('.bat') or test.endswith('.t'))): | |
|
962 | 1032 | tests.append(test) |
|
963 | 1033 | if not tests: |
|
964 | 1034 | print "# Ran 0 tests, 0 skipped, 0 failed." |
General Comments 0
You need to be logged in to leave comments.
Login now