tests/heredoctest.py
author Simon Heimberg <simohe@besonet.ch>
Mon, 25 Nov 2013 22:00:46 +0100
branchstable
changeset 1313 2a1cad657b6d
parent 1110 d5b3404b82ce
permissions -rw-r--r--
run-tests: better check for python version Compare version by using pythons tuple comparison. So we do not match on python 3.0 or newer. [ 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)