Show More
@@ -1,16 +1,19 b'' | |||||
1 | import doctest, tempfile, os, sys |
|
1 | import 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') |
|
|||
8 |
|
2 | |||
9 | try: |
|
3 | globalvars = {} | |
10 | os.write(fd, sys.stdin.read()) |
|
4 | localvars = {} | |
11 | os.close(fd) |
|
5 | lines = sys.stdin.readlines() | |
12 | failures, _ = doctest.testfile(name, module_relative=False) |
|
6 | while lines: | |
13 | if failures: |
|
7 | l = lines.pop(0) | |
14 | sys.exit(1) |
|
8 | if l.startswith('SALT'): | |
15 | finally: |
|
9 | print l[:-1] | |
16 | os.remove(name) |
|
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') | |||
|
16 | try: | |||
|
17 | exec c in globalvars, localvars | |||
|
18 | except Exception, inst: | |||
|
19 | print repr(inst) |
@@ -563,8 +563,11 b' def tsttest(test, wd, options, replaceme' | |||||
563 | # up script results with our source. These markers include input |
|
563 | # up script results with our source. These markers include input | |
564 | # line number and the last return code |
|
564 | # line number and the last return code | |
565 | salt = "SALT" + str(time.time()) |
|
565 | salt = "SALT" + str(time.time()) | |
566 | def addsalt(line): |
|
566 | def addsalt(line, inpython): | |
567 | script.append('echo %s %s $?\n' % (salt, line)) |
|
567 | if inpython: | |
|
568 | script.append('%s %d 0\n' % (salt, line)) | |||
|
569 | else: | |||
|
570 | script.append('echo %s %s $?\n' % (salt, line)) | |||
568 |
|
571 | |||
569 | # After we run the shell script, we re-unify the script output |
|
572 | # After we run the shell script, we re-unify the script output | |
570 | # with non-active parts of the source, with synchronization by our |
|
573 | # with non-active parts of the source, with synchronization by our | |
@@ -589,13 +592,17 b' def tsttest(test, wd, options, replaceme' | |||||
589 | if not l.endswith('\n'): |
|
592 | if not l.endswith('\n'): | |
590 | l += '\n' |
|
593 | l += '\n' | |
591 | if l.startswith(' >>> '): # python inlines |
|
594 | if l.startswith(' >>> '): # python inlines | |
|
595 | after.setdefault(pos, []).append(l) | |||
|
596 | prepos = pos | |||
|
597 | pos = n | |||
592 | if not inpython: |
|
598 | if not inpython: | |
593 | # we've just entered a Python block, add the header |
|
599 | # we've just entered a Python block, add the header | |
594 | inpython = True |
|
600 | inpython = True | |
595 | addsalt(n) |
|
601 | addsalt(prepos, False) # make sure we report the exit code | |
596 | script.append('%s -m heredoctest <<EOF\n' % PYTHON) |
|
602 | script.append('%s -m heredoctest <<EOF\n' % PYTHON) | |
597 | prepos = pos |
|
603 | addsalt(n, True) | |
598 | pos = n |
|
604 | script.append(l[2:]) | |
|
605 | if l.startswith(' ... '): # python inlines | |||
599 | after.setdefault(prepos, []).append(l) |
|
606 | after.setdefault(prepos, []).append(l) | |
600 | script.append(l[2:]) |
|
607 | script.append(l[2:]) | |
601 | elif l.startswith(' $ '): # commands |
|
608 | elif l.startswith(' $ '): # commands | |
@@ -605,18 +612,14 b' def tsttest(test, wd, options, replaceme' | |||||
605 | after.setdefault(pos, []).append(l) |
|
612 | after.setdefault(pos, []).append(l) | |
606 | prepos = pos |
|
613 | prepos = pos | |
607 | pos = n |
|
614 | pos = n | |
608 | addsalt(n) |
|
615 | addsalt(n, False) | |
609 | script.append(l[4:]) |
|
616 | script.append(l[4:]) | |
610 | elif l.startswith(' > '): # continuations |
|
617 | elif l.startswith(' > '): # continuations | |
611 | after.setdefault(prepos, []).append(l) |
|
618 | after.setdefault(prepos, []).append(l) | |
612 | script.append(l[4:]) |
|
619 | script.append(l[4:]) | |
613 | elif l.startswith(' '): # results |
|
620 | elif l.startswith(' '): # results | |
614 | if inpython: |
|
621 | # queue up a list of expected results | |
615 |
|
|
622 | expected.setdefault(pos, []).append(l[2:]) | |
616 | after.setdefault(prepos, []).append(l) |
|
|||
617 | else: |
|
|||
618 | # queue up a list of expected results |
|
|||
619 | expected.setdefault(pos, []).append(l[2:]) |
|
|||
620 | else: |
|
623 | else: | |
621 | if inpython: |
|
624 | if inpython: | |
622 | script.append("EOF\n") |
|
625 | script.append("EOF\n") | |
@@ -626,7 +629,7 b' def tsttest(test, wd, options, replaceme' | |||||
626 |
|
629 | |||
627 | if inpython: |
|
630 | if inpython: | |
628 | script.append("EOF\n") |
|
631 | script.append("EOF\n") | |
629 | addsalt(n + 1) |
|
632 | addsalt(n + 1, False) | |
630 |
|
633 | |||
631 | # Write out the script and execute it |
|
634 | # Write out the script and execute it | |
632 | fd, name = tempfile.mkstemp(suffix='hg-tst') |
|
635 | fd, name = tempfile.mkstemp(suffix='hg-tst') |
@@ -16,6 +16,11 b' Multi-line command:' | |||||
16 | $ foo |
|
16 | $ foo | |
17 | bar |
|
17 | bar | |
18 |
|
18 | |||
|
19 | Return codes before inline python: | |||
|
20 | ||||
|
21 | $ false | |||
|
22 | [1] | |||
|
23 | ||||
19 | Doctest commands: |
|
24 | Doctest commands: | |
20 |
|
25 | |||
21 | >>> print 'foo' |
|
26 | >>> print 'foo' | |
@@ -28,7 +33,7 b' Doctest commands:' | |||||
28 | y |
|
33 | y | |
29 | z |
|
34 | z | |
30 |
|
35 | |||
31 | <BLANKLINE> |
|
36 | ||
32 |
|
37 | |||
33 | Regular expressions: |
|
38 | Regular expressions: | |
34 |
|
39 |
General Comments 0
You need to be logged in to leave comments.
Login now