[PATCH 1 of 2 RFC] tests: add helper script for processing doctests read from stdin

Idan Kamara idankk86 at gmail.com
Wed Oct 12 15:05:13 CDT 2011


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1318449673 -7200
# Node ID c3793a3a0926288e6d46db8a2dc1e571aee141a5
# Parent  81c97964d123cf1bb3f55ed1dd6ad1356fb47538
tests: add helper script for processing doctests read from stdin

Writes stdin to a temp file and doctests it.

In the future we might want to spare the temp file and directly call into
doctest.

Also, with some tweaking it seems possible to adjust the line numbers reported
in an error report so they match the ones in the original file.

diff --git a/tests/heredoctest.py b/tests/heredoctest.py
new file mode 100644
--- /dev/null
+++ b/tests/heredoctest.py
@@ -0,0 +1,9 @@
+import doctest, tempfile, os, sys
+
+if __name__ == "__main__":
+    fd, name = tempfile.mkstemp(suffix='hg-tst')
+    os.write(fd, sys.stdin.read())
+    os.close(fd)
+    failures, _ = doctest.testfile(name, module_relative=False)
+    if failures:
+        sys.exit(1)


More information about the Mercurial-devel mailing list