<commit_before># Copyright 2015 The Shaderc Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import expect
from glslc_test_framework import inside_glslc_testsuite
from placeholder import FileShader


def core_vert_shader_without_version():
    # gl_ClipDistance doesn't exist in es profile (at least until 3.10).
    return 'void main() { gl_ClipDistance[0] = 5.; }'


def core_frag_shader_without_version():
    # gl_SampleID appears in core profile from 4.00.
    # gl_sampleID doesn't exsit in es profile (at least until 3.10).
    return 'void main() { int temp = gl_SampleID; }'


@inside_glslc_testsuite('OptionStd')
class TestStdNoArg(expect.ErrorMessage):
    """Tests -std alone."""

    glslc_args = ['-std']
    expected_error = ["glslc: error: unknown argument: '-std'\n"]


@inside_glslc_testsuite('OptionStd')
class TestStdEqNoArg(expect.ErrorMessage):
    """Tests -std= with no argument."""

    glslc_args = ['-std=']
    expected_error = ["glslc: error: invalid value '' in '-std='\n"]


@inside_glslc_testsuite('OptionStd')
class TestStdEqSpaceArg(expect.ErrorMessage):
    """Tests -std= <version-profile>."""

    shader = FileShader(core_frag_shader_without_version(), '.frag')
    glslc_args = ['-c', '-std=', '450core', shader]
    expected_error = ["glslc: error: invalid value '' in '-std='\n"]

@inside_glslc_testsuite('OptionStd')
class TestMissingVersionAndStd(expect.ErrorMessage):
    """Tests that missing both #version and -std results in errors."""

    shader = FileShader(core_frag_shader_without_version(), '.frag')
    glslc_args = ['-c', shader]
    expected_error = [
        shader, ":1: error: 'gl_SampleID' : undeclared identifier\n",
        shader, ":1: error: '=' :  cannot convert from 'temp float' to ",
        "'temp int'\n2 errors generated.\n"]


@inside_glslc_testsuite('OptionStd')
class TestMissingVersionButHavingStd(expect.ValidObjectFile):
    """Tests that correct -std fixes missing #version."""

    shader = FileShader(core_frag_shader_without_version(), '.frag')
    glslc_args = ['-c', '-std=450core', shader]


@inside_glslc_testsuite('OptionStd')
class TestMissingVersionAndWrongStd(expect.ErrorMessage):
    """Tests missing #version and wrong -std results in errors."""

    shader = FileShader(core_frag_shader_without_version(), '.frag')
    glslc_args = ['-c', '-std=310es', shader]
    expected_error = [
        shader, ":1: error: 'gl_SampleID' : undeclared identifier\n",
        shader, ":1: error: '=' :  cannot convert from 'temp float' to ",
        "'temp mediump int'\n2 errors generated.\n"]


@inside_glslc_testsuite('OptionStd')
class TestConflictingVersionAndStd(expect.ValidObjectFileWithWarning):
    """Tests that with both #version and -std, -std takes precedence."""

    # Wrong #version here on purpose.
    shader = FileShader(
        '#version 310 es\n' + core_frag_shader_without_version(), '.frag')
    # -std overwrites the wrong #version.
    glslc_args = ['-c', '-std=450core', shader]

    expected_warning = [
        shader, ': warning: (version, profile) forced to be (450, core), while '
        'in source code it is (310, es)\n1 warning generated.\n']


@inside_glslc_testsuite('OptionStd')
class TestMultipleStd(expect.ValidObjectFile):
    """Tests that for multiple -std, the last one takes effect."""

    shader = FileShader(core_frag_shader_without_version(), '.frag')<commit_msg>Sync with upstream glslang.<commit_after># Copyright 2015 The Shaderc Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import expect
from glslc_test_framework import inside_glslc_testsuite
from placeholder import FileShader


def core_vert_shader_without_version():
    # gl_ClipDistance doesn't exist in es profile (at least until 3.10).
    return 'void main() { gl_ClipDistance[0] = 5.; }'


def core_frag_shader_without_version():
    # gl_SampleID appears in core profile from 4.00.
    # gl_sampleID doesn't exsit in es profile (at least until 3.10).
    return 'void main() { int temp = gl_SampleID; }'


@inside_glslc_testsuite('OptionStd')
class TestStdNoArg(expect.ErrorMessage):
    """Tests -std alone."""

    glslc_args = ['-std']
    expected_error = ["glslc: error: unknown argument: '-std'\n"]


@inside_glslc_testsuite('OptionStd')
class TestStdEqNoArg(expect.ErrorMessage):
    """Tests -std= with no argument."""

    glslc_args = ['-std=']
    expected_error = ["glslc: error: invalid value '' in '-std='\n"]


@inside_glslc_testsuite('OptionStd')
class TestStdEqSpaceArg(expect.ErrorMessage):
    """Tests -std= <version-profile>."""

    shader = FileShader(core_frag_shader_without_version(), '.frag')
    glslc_args = ['-c', '-std=', '450core', shader]
    expected_error = ["glslc: error: invalid value '' in '-std='\n"]

@inside_glslc_testsuite('OptionStd')
class TestMissingVersionAndStd(expect.ErrorMessage):
    """Tests that missing both #version and -std results in errors."""

    shader = FileShader(core_frag_shader_without_version(), '.frag')
    glslc_args = ['-c', shader]
    expected_error = [
        shader, ":1: error: 'gl_SampleID' : undeclared identifier\n",
        shader, ":1: error: '=' :  cannot convert from 'temp float' to ",
        "'temp int'\n2 errors generated.\n"]


@inside_glslc_testsuite('OptionStd')
class TestMissingVersionButHavingStd(expect.ValidObjectFile):
    """Tests that correct -std fixes missing #version."""

    shader = FileShader(core_frag_shader_without_version(), '.frag')
    glslc_args = ['-c', '-std=450core', shader]


@inside_glslc_testsuite('OptionStd')
class TestMissingVersionAndWrongStd(expect.ErrorMessage):
    """Tests missing #version and wrong -std results in errors."""

    shader = FileShader(core_frag_shader_without_version(), '.frag')
    glslc_args = ['-c', '-std=310es', shader]
    expected_error = [
        shader, ":1: error: 'gl_SampleID' : required extension not requested: "
        'GL_OES_sample_variables\n1 error generated.\n']


@inside_glslc_testsuite('OptionStd')
class TestConflictingVersionAndStd(expect.ValidObjectFileWithWarning):
    """Tests that with both #version and -std, -std takes precedence."""

    # Wrong #version here on purpose.
    shader = FileShader(
        '#version 310 es\n' + core_frag_shader_without_version(), '.frag')
    # -std overwrites the wrong #version.
    glslc_args = ['-c', '-std=450core', shader]

    expected_warning = [
        shader, ': warning: (version, profile) forced to be (450, core), while '
        'in source code it is (310, es)\n1 warning generated.\n']


@inside_glslc_testsuite('OptionStd')
class TestMultipleStd(expect.ValidObjectFile):
    """Tests that for multiple -std, the last one takes effect."""

    shader = FileShader(core_frag_shader_without_version(), '.frag')
{'fraction_non_alphanumeric': 0.1258337609030272, 'fraction_numerical': 0.011929194458696767, 'mean_word_length': 4.311307901907357, 'pattern_counts': {'":': 7, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2065584', 'n_tokens_mistral': 2476, 'n_tokens_neox': 2357, 'n_words': 710}