tests/heredoctest.py
author Danek Duvall <danek.duvall@oracle.com>
Wed, 02 Mar 2016 14:58:29 -0800
changeset 28337 869e65e68aee
parent 27297 4179d054b3e9
child 29485 6a98f9408a50
permissions -rw-r--r--
tests: Solaris cmp complains about empty files, even with -s When you compare an empty file, such as /dev/null, with a non-empty file, Solaris cmp complains on stderr with "cmp: EOF on /dev/null", even if the -s argument is present. GNU cmp makes the complaint, but silences it with -s. We can change the pdiff utility to simply redirect stderr to /dev/null so that we don't have to worry about this difference in the test files.

from __future__ import absolute_import

import sys

globalvars = {}
lines = sys.stdin.readlines()
while lines:
    l = lines.pop(0)
    if l.startswith('SALT'):
        print(l[:-1])
    elif l.startswith('>>> '):
        snippet = l[4:]
        while lines and lines[0].startswith('... '):
            l = lines.pop(0)
            snippet += l[4:]
        c = compile(snippet, '<heredoc>', 'single')
        try:
            exec(c, globalvars)
        except Exception as inst:
            print(repr(inst))