#!/usr/bin/sh
#
# Copyright (c) 2006 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# Author: David Malcolm


# Check the correct Python executable to run this file.
# Python3 will be preferred.
""":"

cmd=$(python-check.sh)

exec -- $cmd $0 "$@";

":"""

import sys
import fileinput
import unittest
import rhts.testinfo

class __DeferredFileInputFilenameString(object):
    """
    The PrintingParser classes want to have a filename so they can give
    useful error messages.

    However, annoyingly, fileinput.filename() only returns a value once input
    has been read from the string.

    So this class exists so that you can pass a string-like object around,
    and have the actual filename string generated later on, when needed, and when
    fileinput.filename() will be generating good output.
    """
    def __str__(self):
        return fileinput.filename()
        
if __name__=='__main__':
    input = fileinput.input(openhook=fileinput.hook_encoded('utf8'))
    p = rhts.testinfo.StdoutParser(__DeferredFileInputFilenameString())
    p.parse(input)
    if p.numErrors or p.numWarnings:
        sys.exit(1)
