Show More
@@ -1,16 +1,19 | |||
|
1 | import doctest, tempfile, os, sys | |
|
2 | ||
|
3 | if __name__ == "__main__": | |
|
4 | if 'TERM' in os.environ: | |
|
5 | del os.environ['TERM'] | |
|
6 | ||
|
7 | fd, name = tempfile.mkstemp(suffix='hg-tst') | |
|
1 | import sys | |
|
8 | 2 | |
|
3 | globalvars = {} | |
|
4 | localvars = {} | |
|
5 | lines = sys.stdin.readlines() | |
|
6 | while lines: | |
|
7 | l = lines.pop(0) | |
|
8 | if l.startswith('SALT'): | |
|
9 | print l[:-1] | |
|
10 | elif l.startswith('>>> '): | |
|
11 | snippet = l[4:] | |
|
12 | while lines and lines[0].startswith('... '): | |
|
13 | l = lines.pop(0) | |
|
14 | snippet += "\n" + l[4:] | |
|
15 | c = compile(snippet, '<heredoc>', 'single') | |
|
9 | 16 | try: |
|
10 | os.write(fd, sys.stdin.read()) | |
|
11 | os.close(fd) | |
|
12 | failures, _ = doctest.testfile(name, module_relative=False) | |
|
13 | if failures: | |
|
14 | sys.exit(1) | |
|
15 | finally: | |
|
16 | os.remove(name) | |
|
17 | exec c in globalvars, localvars | |
|
18 | except Exception, inst: | |
|
19 | print repr(inst) |
@@ -563,7 +563,10 def tsttest(test, wd, options, replaceme | |||
|
563 | 563 | # up script results with our source. These markers include input |
|
564 | 564 | # line number and the last return code |
|
565 | 565 | salt = "SALT" + str(time.time()) |
|
566 | def addsalt(line): | |
|
566 | def addsalt(line, inpython): | |
|
567 | if inpython: | |
|
568 | script.append('%s %d 0\n' % (salt, line)) | |
|
569 | else: | |
|
567 | 570 | script.append('echo %s %s $?\n' % (salt, line)) |
|
568 | 571 | |
|
569 | 572 | # After we run the shell script, we re-unify the script output |
@@ -589,13 +592,17 def tsttest(test, wd, options, replaceme | |||
|
589 | 592 | if not l.endswith('\n'): |
|
590 | 593 | l += '\n' |
|
591 | 594 | if l.startswith(' >>> '): # python inlines |
|
595 | after.setdefault(pos, []).append(l) | |
|
596 | prepos = pos | |
|
597 | pos = n | |
|
592 | 598 | if not inpython: |
|
593 | 599 | # we've just entered a Python block, add the header |
|
594 | 600 | inpython = True |
|
595 | addsalt(n) | |
|
601 | addsalt(prepos, False) # make sure we report the exit code | |
|
596 | 602 | script.append('%s -m heredoctest <<EOF\n' % PYTHON) |
|
597 | prepos = pos | |
|
598 | pos = n | |
|
603 | addsalt(n, True) | |
|
604 | script.append(l[2:]) | |
|
605 | if l.startswith(' ... '): # python inlines | |
|
599 | 606 | after.setdefault(prepos, []).append(l) |
|
600 | 607 | script.append(l[2:]) |
|
601 | 608 | elif l.startswith(' $ '): # commands |
@@ -605,16 +612,12 def tsttest(test, wd, options, replaceme | |||
|
605 | 612 | after.setdefault(pos, []).append(l) |
|
606 | 613 | prepos = pos |
|
607 | 614 | pos = n |
|
608 | addsalt(n) | |
|
615 | addsalt(n, False) | |
|
609 | 616 | script.append(l[4:]) |
|
610 | 617 | elif l.startswith(' > '): # continuations |
|
611 | 618 | after.setdefault(prepos, []).append(l) |
|
612 | 619 | script.append(l[4:]) |
|
613 | 620 | elif l.startswith(' '): # results |
|
614 | if inpython: | |
|
615 | script.append(l[2:]) | |
|
616 | after.setdefault(prepos, []).append(l) | |
|
617 | else: | |
|
618 | 621 |
|
|
619 | 622 |
|
|
620 | 623 | else: |
@@ -626,7 +629,7 def tsttest(test, wd, options, replaceme | |||
|
626 | 629 | |
|
627 | 630 | if inpython: |
|
628 | 631 | script.append("EOF\n") |
|
629 | addsalt(n + 1) | |
|
632 | addsalt(n + 1, False) | |
|
630 | 633 | |
|
631 | 634 | # Write out the script and execute it |
|
632 | 635 | fd, name = tempfile.mkstemp(suffix='hg-tst') |
General Comments 0
You need to be logged in to leave comments.
Login now