tests/heredoctest.py
branchstable
changeset 1110 d5b3404b82ce
parent 1109 8458561f6f94
--- a/tests/heredoctest.py	Tue Nov 01 12:25:54 2011 -0700
+++ b/tests/heredoctest.py	Mon Nov 07 13:46:41 2011 -0600
@@ -1,16 +1,19 @@
-import doctest, tempfile, os, sys
-
-if __name__ == "__main__":
-    if 'TERM' in os.environ:
-        del os.environ['TERM']
-
-    fd, name = tempfile.mkstemp(suffix='hg-tst')
+import sys
 
-    try:
-        os.write(fd, sys.stdin.read())
-        os.close(fd)
-        failures, _ = doctest.testfile(name, module_relative=False)
-        if failures:
-            sys.exit(1)
-    finally:
-        os.remove(name)
+globalvars = {}
+localvars = {}
+lines = sys.stdin.readlines()
+while lines:
+    l = lines.pop(0)
+    if l.startswith('SALT'):
+        print l[:-1]
+    elif l.startswith('>>> '):
+        snippet = l[4:]
+        while lines and lines[0].startswith('... '):
+            l = lines.pop(0)
+            snippet += "\n" + l[4:]
+        c = compile(snippet, '<heredoc>', 'single')
+        try:
+            exec c in globalvars, localvars
+        except Exception, inst:
+            print repr(inst)