Show More
@@ -525,20 +525,36 b' def tsttest(test, wd, options, replaceme' | |||
|
525 | 525 | t = open(test) |
|
526 | 526 | out = [] |
|
527 | 527 | script = [] |
|
528 | ||
|
529 | # We generate a shell script which outputs unique markers to line | |
|
530 | # up script results with our source. These markers include input | |
|
531 | # line number and the last return code | |
|
528 | 532 | salt = "SALT" + str(time.time()) |
|
533 | def addsalt(line): | |
|
534 | script.append('echo %s %s $?\n' % (salt, line)) | |
|
529 | 535 | |
|
536 | # After we run the shell script, we re-unify the script output | |
|
537 | # with non-active parts of the source, with synchronization by our | |
|
538 | # SALT line number markers. The after table contains the | |
|
539 | # non-active components, ordered by line number | |
|
540 | after = {} | |
|
530 | 541 | pos = prepos = -1 |
|
531 | after = {} | |
|
542 | ||
|
543 | # Expected shellscript output | |
|
532 | 544 | expected = {} |
|
545 | ||
|
546 | # We keep track of whether or not we're in a Python block so we | |
|
547 | # can generate the surrounding doctest magic | |
|
533 | 548 | inpython = False |
|
549 | ||
|
534 | 550 | for n, l in enumerate(t): |
|
535 | 551 | if not l.endswith('\n'): |
|
536 | 552 | l += '\n' |
|
537 | if l.startswith(' >>> '): | |
|
553 | if l.startswith(' >>> '): # python inlines | |
|
538 | 554 | if not inpython: |
|
539 | 555 | # we've just entered a Python block, add the header |
|
540 | 556 | inpython = True |
|
541 | script.append('echo %s %s $?\n' % (salt, n)) | |
|
557 | addsalt(n) | |
|
542 | 558 | script.append('%s -m heredoctest <<EOF\n' % PYTHON) |
|
543 | 559 | prepos = pos |
|
544 | 560 | pos = n |
@@ -551,7 +567,7 b' def tsttest(test, wd, options, replaceme' | |||
|
551 | 567 | after.setdefault(pos, []).append(l) |
|
552 | 568 | prepos = pos |
|
553 | 569 | pos = n |
|
554 | script.append('echo %s %s $?\n' % (salt, n)) | |
|
570 | addsalt(n) | |
|
555 | 571 | script.append(l[4:]) |
|
556 | 572 | elif l.startswith(' > '): # continuations |
|
557 | 573 | after.setdefault(prepos, []).append(l) |
@@ -570,15 +586,13 b' def tsttest(test, wd, options, replaceme' | |||
|
570 | 586 | # non-command/result - queue up for merged output |
|
571 | 587 | after.setdefault(pos, []).append(l) |
|
572 | 588 | |
|
573 | if inpython: | |
|
574 | script.append("EOF\n") | |
|
575 | ||
|
576 | 589 | t.close() |
|
577 | 590 | |
|
578 | script.append('echo %s %s $?\n' % (salt, n + 1)) | |
|
591 | if inpython: | |
|
592 | script.append("EOF\n") | |
|
593 | addsalt(n + 1) | |
|
579 | 594 | |
|
580 | 595 | fd, name = tempfile.mkstemp(suffix='hg-tst') |
|
581 | ||
|
582 | 596 | try: |
|
583 | 597 | for l in script: |
|
584 | 598 | os.write(fd, l) |
@@ -621,6 +635,8 b' def tsttest(test, wd, options, replaceme' | |||
|
621 | 635 | res += re.escape(c) |
|
622 | 636 | return rematch(res, l) |
|
623 | 637 | |
|
638 | # Merge the script output back into a unified test | |
|
639 | ||
|
624 | 640 | pos = -1 |
|
625 | 641 | postout = [] |
|
626 | 642 | ret = 0 |
@@ -631,8 +647,10 b' def tsttest(test, wd, options, replaceme' | |||
|
631 | 647 | |
|
632 | 648 | if lout: |
|
633 | 649 | if lcmd: |
|
650 | # output block had no trailing newline, clean up | |
|
634 | 651 | lout += ' (no-eol)\n' |
|
635 | 652 | |
|
653 | # find the expected output at the current position | |
|
636 | 654 | el = None |
|
637 | 655 | if pos in expected and expected[pos]: |
|
638 | 656 | el = expected[pos].pop(0) |
@@ -656,6 +674,7 b' def tsttest(test, wd, options, replaceme' | |||
|
656 | 674 | if ret != 0: |
|
657 | 675 | postout.append(" [%s]\n" % ret) |
|
658 | 676 | if pos in after: |
|
677 | # merge in non-active test bits | |
|
659 | 678 | postout += after.pop(pos) |
|
660 | 679 | pos = int(lcmd.split()[0]) |
|
661 | 680 |
General Comments 0
You need to be logged in to leave comments.
Login now