tests/heredoctest.py
author Durham Goode <durham@fb.com>
Mon, 10 Nov 2014 10:44:42 -0800
branchstable
changeset 23246 643c58303fb0
parent 22565 8d45a42b0c0f
child 25032 1db2127d2373
permissions -rw-r--r--
rebase: fix rebase with no common ancestors (issue4446) The new rebase revset didn't check for the case when there are no common ancestors. Now it does. The new behavior should be the same as the pre-3.2 behavior. Added a test.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15434
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
     1
import sys
15247
3cd1605e9d8e tests: remove temp doctest file when finished running it
Idan Kamara <idankk86@gmail.com>
parents: 15235
diff changeset
     2
15434
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
     3
globalvars = {}
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
     4
lines = sys.stdin.readlines()
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
     5
while lines:
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
     6
    l = lines.pop(0)
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
     7
    if l.startswith('SALT'):
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
     8
        print l[:-1]
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
     9
    elif l.startswith('>>> '):
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
    10
        snippet = l[4:]
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
    11
        while lines and lines[0].startswith('... '):
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
    12
            l = lines.pop(0)
22565
8d45a42b0c0f heredoctest: do not append extra newline character to continuation line
Yuya Nishihara <yuya@tcha.org>
parents: 22564
diff changeset
    13
            snippet += l[4:]
15434
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
    14
        c = compile(snippet, '<heredoc>', 'single')
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
    15
        try:
22564
9599e86159ac heredoctest: use the same dict for local/global contexts as in doctest
Yuya Nishihara <yuya@tcha.org>
parents: 15434
diff changeset
    16
            exec c in globalvars
15434
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
    17
        except Exception, inst:
5635a4017061 run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents: 15398
diff changeset
    18
            print repr(inst)