def check_bad_character(tfile):
    """ Check for bad characters """
    with nt.assert_raises(SystemExit) as e:
        glsl.GLSLParserTest(tfile)

        # Obviously this isn't a perfect check, but it should be close enough
        if not e.exception.message.startswith('Bad character "'):
            raise AssertionError(e.exception)
def test_no_config_end():
    """ GLSLParserTest requires [end config] """
    with utils.with_tempfile('// [config]\n') as tfile:
        with nt.assert_raises(SystemExit) as exc:
            glsl.GLSLParserTest(tfile)
            nt.assert_equal(
                exc.exception,
                'No [end config] section found!',
                msg="config section not closed, no exception raised")
def test_find_config_start():
    """ GLSLParserTest finds [config] """
    content = ('// [config]\n' '// glsl_version: 1.00\n' '//\n')
    with utils.with_tempfile(content) as tfile:
        with nt.assert_raises(SystemExit) as exc:
            glsl.GLSLParserTest(tfile)
            nt.assert_not_equal(exc.exception,
                                'No [config] section found!',
                                msg="Config section not parsed")
def check_good_extension(file_, desc):
    """ A good extension should not raise a GLSLParserException """
    try:
        glsl.GLSLParserTest(file_)
    except glsl.GLSLParserException:
        nt.ok_(
            False,
            'GLSLParserException was raised by "required_extensions: {}"'
            ', but should not'.format(desc))
def check_no_duplicates(content, dup):
    """ Ensure that duplicate entries raise an error """
    with nt.assert_raises(SystemExit) as e:
        with utils.with_tempfile(content) as tfile:
            glsl.GLSLParserTest(tfile)

            nt.eq_(
                e.exception.message,
                'Duplicate entry for key {0} in file {1}'.format(dup, tfile))
def test_no_glsl_version():
    """ glsl_version section is required """
    content = ('//\n' '// expect_result: pass\n' '// [end config]\n')
    with utils.with_tempfile(content) as tfile:
        with nt.assert_raises(SystemExit) as exc:
            glsl.GLSLParserTest(tfile)
            nt.assert_equal(
                exc.exception,
                'Missing required section glsl_version from config',
                msg="config section not closed, no exception raised")
def test_no_expect_result():
    """ expect_result section is required """
    content = ('// [config]\n' '// glsl_version: 1.00\n' '//\n')
    with utils.with_tempfile(content) as tfile:
        with nt.assert_raises(glsl.GLSLParserException) as exc:
            glsl.GLSLParserTest(tfile)
            nt.assert_equal(
                exc.exception,
                'Missing required section expect_result from config',
                msg="config section not closed, no exception raised")
def test_no_config_start():
    """ GLSLParserTest requires [config] """
    content = ('// expect_result: pass\n'
               '// glsl_version: 1.00\n'
               '// [end config]\n')
    with utils.with_tempfile(content) as tfile:
        with nt.assert_raises(SystemExit) as exc:
            glsl.GLSLParserTest(tfile)
            nt.assert_equal(exc.exception,
                            'No [config] section found!',
                            msg="No config section found, no exception raised")
def _check_config(content):
    """ This is the test that actually checks the glsl config section """
    with utils.with_tempfile(content) as tfile:
        return glsl.GLSLParserTest(tfile), tfile
def test_glslparser_initializer():
    """ GLSLParserTest initializes """
    glsl.GLSLParserTest('tests/spec/glsl-es-1.00/compiler/version-macro.frag')