##// END OF EJS Templates
run-tests: replace inline python handling with more native scheme...
Matt Mackall -
r15434:5635a401 default
parent child Browse files
Show More
@@ -1,16 +1,19 b''
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
9 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)
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')
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 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):
567 script.append('echo %s %s $?\n' % (salt, line))
566 def addsalt(line, inpython):
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 572 # After we run the shell script, we re-unify the script output
570 573 # with non-active parts of the source, with synchronization by our
@@ -589,13 +592,17 b' 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,18 +612,14 b' 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 # queue up a list of expected results
619 expected.setdefault(pos, []).append(l[2:])
621 # queue up a list of expected results
622 expected.setdefault(pos, []).append(l[2:])
620 623 else:
621 624 if inpython:
622 625 script.append("EOF\n")
@@ -626,7 +629,7 b' 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')
@@ -16,6 +16,11 b' Multi-line command:'
16 16 $ foo
17 17 bar
18 18
19 Return codes before inline python:
20
21 $ false
22 [1]
23
19 24 Doctest commands:
20 25
21 26 >>> print 'foo'
@@ -28,7 +33,7 b' Doctest commands:'
28 33 y
29 34 z
30 35 >>> print
31 <BLANKLINE>
36
32 37
33 38 Regular expressions:
34 39
General Comments 0
You need to be logged in to leave comments. Login now