tests/heredoctest.py
author Mads Kiilerich <madski@unity3d.com>
Tue, 15 Jan 2013 23:30:10 +0100
branchstable
changeset 1196 c0daf79e5680
parent 1110 d5b3404b82ce
permissions -rw-r--r--
tests: run with PYTHONHASHSEED=random Python set and dict iteration order is in principle undefined but usually 'quite stable'. Setting PYTHONHASHSEED=random will make the iteration order more random in Python 2.6.8 and 2.7.3 and where it has been backported. This can thus help spot dependencies on undefined behaviour and prevent future problems. [ original upstream message ]
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1110
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
     1
import sys
1108
168da136346a tests: remove temp doctest file when finished running it
Idan Kamara <idankk86@gmail.com>
parents: 1107
diff changeset
     2
1110
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
     3
globalvars = {}
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
     4
localvars = {}
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
     5
lines = sys.stdin.readlines()
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
     6
while lines:
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
     7
    l = lines.pop(0)
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
     8
    if l.startswith('SALT'):
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
     9
        print l[:-1]
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
    10
    elif l.startswith('>>> '):
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
    11
        snippet = l[4:]
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
    12
        while lines and lines[0].startswith('... '):
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
    13
            l = lines.pop(0)
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
    14
            snippet += "\n" + l[4:]
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
    15
        c = compile(snippet, '<heredoc>', 'single')
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
    16
        try:
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
    17
            exec c in globalvars, localvars
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
    18
        except Exception, inst:
d5b3404b82ce run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 1109
diff changeset
    19
            print repr(inst)