tests/heredoctest.py
author Idan Kamara <idankk86@gmail.com>
Wed, 12 Oct 2011 22:01:13 +0200
branchstable
changeset 1107 943253aadddb
child 1108 168da136346a
permissions -rw-r--r--
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. [ original upstream message ]
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1107
943253aadddb tests: add helper script for processing doctests read from stdin
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     1
import doctest, tempfile, os, sys
943253aadddb tests: add helper script for processing doctests read from stdin
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     2
943253aadddb tests: add helper script for processing doctests read from stdin
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     3
if __name__ == "__main__":
943253aadddb tests: add helper script for processing doctests read from stdin
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     4
    fd, name = tempfile.mkstemp(suffix='hg-tst')
943253aadddb tests: add helper script for processing doctests read from stdin
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     5
    os.write(fd, sys.stdin.read())
943253aadddb tests: add helper script for processing doctests read from stdin
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     6
    os.close(fd)
943253aadddb tests: add helper script for processing doctests read from stdin
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     7
    failures, _ = doctest.testfile(name, module_relative=False)
943253aadddb tests: add helper script for processing doctests read from stdin
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     8
    if failures:
943253aadddb tests: add helper script for processing doctests read from stdin
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     9
        sys.exit(1)