tests/heredoctest.py
author Mads Kiilerich <madski@unity3d.com>
Fri, 28 Feb 2014 02:09:00 +0100
branchstable
changeset 1361 1d3aa8779efb
parent 1110 d5b3404b82ce
permissions -rw-r--r--
tests: add run-tests --changed option for running tests changed in revisions Convenient when polishing patches and changing details of how they change test output. This will probably break in weird ways for revsets with special quoting ... but it is good enough for run-tests. Usage example: yes | ./run-tests.py -li --changed qparent [ 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)