class TestDashCapMSingleInputAbsolutePathNoInclude(DependencyInfoStdoutMatch): """Tests -M with single input file which doesn't contain #include and is represented in absolute path. e.g. glslc -M /usr/local/shader.vert => shader.vert.spv: /usr/local/shader.vert """ shader = FileShader(MINIMAL_SHADER, '.vert') glslc_args = ['-M', shader] dependency_rules_expected = [{'target': shader, 'target_extension': '.spv', 'dependency': {shader}}]
class TestSpaceAroundVersion(expect.ValidObjectFileWithWarning): """Tests that space around #version is correctly handled.""" shader = FileShader( '\t \t # \t \f\f version \v \t\t 310 \v\v \t es \n' + core_vert_shader_without_version(), '.vert') 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']
class HlslFTextureBindingBaseOptionRespected(expect.ValidAssemblyFileWithSubstr ): """Tests that -ftexture-binding-base sets binding base for textures in HLSL compilation.""" shader = FileShader(HLSL_SHADER_WITHOUT_BINDINGS, '.frag') glslc_args = [ '-S', '-x', 'hlsl', '-fhlsl-iomap', shader, '-ftexture-binding-base', '100' ] expected_assembly_substr = "OpDecorate %t6 Binding 116"
class TestSpacesAroundPSS(expect.ValidObjectFile): """Tests that spaces around #pragma shader_stage() works.""" shader = FileShader( """#version 310 es # pragma shader_stage ( vertex ) void main() { gl_Position = vec4(1.); } """, '.glsl') glslc_args = ['-c', shader]
class FImageBindingBaseForVertOptionIgnoredOnImageCompileAsFrag( expect.ValidAssemblyFileWithSubstr): """Tests that -fimage-binding-base with vert stage value is ignored when cmopiled as fragment.""" shader = FileShader(GLSL_SHADER_WITH_UNIFORMS_WITHOUT_BINDINGS, '.frag') glslc_args = [ '-S', shader, '-fauto-bind-uniforms', '-fimage-binding-base', 'vert', '44' ] expected_assembly_substr = "OpDecorate %my_img Binding 2"
class FSsboBindingBaseForFragOptionIgnoredOnSsboCompileAsVert( expect.ValidAssemblyFileWithSubstr): """Tests that -fssbo-binding-base with frag stage value is ignored on SSBOs when compiling as a vertex shader.""" shader = FileShader(GLSL_SHADER_WITH_UNIFORMS_WITHOUT_BINDINGS, '.vert') glslc_args = [ '-S', shader, '-fauto-bind-uniforms', '-fssbo-binding-base', 'frag', '100' ] expected_assembly_substr = "OpDecorate %my_ssbo Binding 5"
class TestShaderStageWithAssemblyFile(expect.ErrorMessage): """Tests that assembly files don't work with -fshader-stage""" shader = FileShader(empty_main_assembly(), '.spvasm') glslc_args = ['-c', '-fshader-stage=vertex', shader] expected_error = [ shader, ": error: #version: Desktop shaders for Vulkan SPIR-V require " "version 140 or higher\n", shader, ":2: error: '' : syntax error\n", '2 errors generated.\n' ]
class TestCommentBeforeVersion(expect.ValidObjectFileWithWarning): """Tests that comments before #version (same line) is correctly handled.""" shader = FileShader( '/* some comment */ #version 150\n' + core_vert_shader_without_version(), '.vert') glslc_args = ['-c', '-std=450', shader] expected_warning = [ shader, ': warning: (version, profile) forced to be (450, none), while ' 'in source code it is (150, none)\n1 warning generated.\n']
class HlslFSamplerBindingBaseForFragOptionRespected( expect.ValidAssemblyFileWithSubstr): """Tests that -fsampler-binding-base for frag sets binding base for samplers in HLSL compilation.""" shader = FileShader(HLSL_SHADER_WITHOUT_BINDINGS, '.frag') glslc_args = [ '-S', '-x', 'hlsl', '-fhlsl-iomap', shader, '-fsampler-binding-base', 'frag', '100' ] expected_assembly_substr = "OpDecorate %s2 Binding 102"
class HlslFSamplerBindingBaseForComputeOptionIgnoredWhenCompilingAsFrag( expect.ValidAssemblyFileWithSubstr): """Tests that -fsampler-binding-base for compute is ignored when compiling as a fragment shader.""" shader = FileShader(HLSL_SHADER_WITHOUT_BINDINGS, '.frag') glslc_args = [ '-S', '-x', 'hlsl', '-fhlsl-iomap', shader, '-fsampler-binding-base', 'compute', '100' ] expected_assembly_substr = "OpDecorate %s2 Binding 2"
class SuppressedWarningOnLine(expect.SuccessfulReturn): """Tests that a warning message with a file/line number is suppressed in the presence of -w.""" shader = FileShader( """#version 400 layout(location = 0) attribute float x; void main() { } """, '.vert') glslc_args = ['-c', shader, '-w']
class FailureToMakeOutputFileAsCurrentDirIsErrorWithNoOutputFile( expect.NoNamedOutputFiles, expect.NoOutputOnStdout, expect.ErrorMessageSubstr): """Tests that if we fail to make an output file because it is the current directory, then no file is generated, and we have certain error messages.""" shader = FileShader('#version 150\nvoid main() {}', '.frag') bad_file = '.' # Current directory glslc_args = ['-c', shader, '-o', bad_file] expected_output_filenames = [bad_file] expected_error_substr = ['cannot open output file']
class TestTabsAroundPSS(expect.ValidObjectFile): """Tests that tabs around #pragma shader_stage() works.""" shader = FileShader( """#version 310 es \t\t#\tpragma\t\t\tshader_stage\t\t(\t\t\t\tvertex\t\t)\t\t\t\t void main() { gl_Position = vec4(1.); } """, '.glsl') glslc_args = ['-c', shader]
class TestDashCapDWithDashE(expect.ReturnCodeIsZero, expect.StdoutMatch): """Tests -E outputs expanded -D macros.""" shader = FileShader(""" void main(){Y} """, '.vert') glslc_args = ['-DY=return 3;', '-E', '-std=450core', shader] expected_stdout = [""" void main(){ return 3;} """]
class TestDashCapDReservedMacro(expect.WarningMessage): """Tests that we cannot -D GLSL's predefined macros.""" shader = FileShader('void main(){}', '.vert') # Consecutive underscores are banned anywhere in the name. glslc_args = [ '-D__LINE__=1', '-Dmid__dle', '-Dend__', '-D_single_is_valid_', shader ] w = 'glslc: warning: names containing consecutive underscores are reserved: ' expected_warning = [w, '-D__LINE__=1\n', w, '-Dmid__dle\n', w, '-Dend__\n']
class TestCommentAfterVersion(expect.ValidObjectFileWithWarning): """Tests that multiple-line comments after #version is correctly handled.""" shader = FileShader( '#version 150 compatibility ' + '/* start \n second line \n end */\n' + core_vert_shader_without_version(), '.vert') glslc_args = ['-c', '-std=450core', shader] expected_warning = [ shader, ': warning: (version, profile) forced to be (450, core), while ' 'in source code it is (150, compatibility)\n1 warning generated.\n']
class TestDashCapDWithDashENestedMacro(expect.ReturnCodeIsZero, expect.StdoutMatch): """Tests -E processes referencing -D options correctly.""" shader = FileShader(""" void main(){ return X;} """, '.vert') glslc_args = ['-DY=4', '-DX=Y', '-E', '-std=450core', shader] expected_stdout = [""" void main(){ return 4;} """]
class FailureToMakeOutputFileIsErrorWithNoOutputFile(expect.NoNamedOutputFiles, expect.NoOutputOnStdout, expect.ErrorMessageSubstr ): """Tests that if we fail to make an output file, no file is generated, and we have certain error messages.""" shader = FileShader('#version 150\nvoid main() {}', '.frag') bad_file = '/file/should/not/exist/today' glslc_args = ['-c', shader, '-o', bad_file] expected_output_filenames = [bad_file] expected_error_substr = ['cannot open output file']
class TestDashCapDWithDashEFunctionMacro(expect.ReturnCodeIsZero, expect.StdoutMatch): """Tests -E processes -D function macros correctly.""" shader = FileShader(""" void main(){ return FOO(3);} """, '.vert') glslc_args = ['-DFOO(x)=(2*x+1)*x*x', '-E', '-std=450core', shader] expected_stdout = [""" void main(){ return(2 * 3 + 1)* 3 * 3;} """]
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']
class TestOSSOverridePSS(expect.ValidObjectFile): """Tests that -fshader-stage overrides #pragma shader_stage().""" # wrong pragma and wrong file extension shader = FileShader( """#version 310 es #pragma shader_stage(fragment) void main() { gl_Position = vec4(1.); }""", '.frag') # -fshader-stage to the rescue! ^.^ glslc_args = ['-c', '-fshader-stage=vertex', shader]
class GlobalWarning(expect.WarningMessage): """Tests that a warning message without file/line number is emitted.""" shader = FileShader( """#version 550 void main() { } """, '.vert') glslc_args = ['-c', shader] expected_warning = [ shader, ': warning: version 550 is unknown.\n1 warning generated.\n']
class TestShaderStageWithAssemblyFile(expect.ErrorMessage): """Tests that assembly files don't work with -fshader-stage""" shader = FileShader(empty_main_assembly(), '.spvasm') glslc_args = ['-c', '-fshader-stage=vertex', shader] expected_error = [ shader, ": error: #version: Desktop shaders for Vulkan SPIR-V require " "version 140 or higher\n", shader, ":2: error: 'extraneous semicolon' :", " not supported for this version or the enabled extensions\n", shader, ":2: error: '' : syntax error, unexpected IDENTIFIER\n", '3 errors generated.\n']
class GlobalWarningAsError(expect.ErrorMessage): """Tests that with -Werror an error warning message without file/line number is emitted instead of a warning.""" shader = FileShader( """#version 550 void main() { } """, '.vert') glslc_args = ['-c', shader, '-Werror'] expected_error= [ shader, ': error: version 550 is unknown.\n1 error generated.\n']
class GlobalWarning(expect.WarningMessage): """Tests that a warning message without file/line number is emitted.""" shader = FileShader( """#version 550 void main() { } """, '.vert') glslc_args = ['-c', '-std=400', shader] expected_warning = [ shader, ': warning: (version, profile) forced to be (400, none),' ' while in source code it is (550, none)\n1 warning generated.\n']
class TestVersionInsideSlashStarComment(expect.ValidObjectFileWithWarning): """Tests that -std substitutes the correct #version string.""" # The second #version string should be substituted and this shader # should compile successfully with -std=450core. shader = FileShader( '/* #version 310 es */\n#version 310 es\n' + core_vert_shader_without_version(), '.vert') 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']
class TestDashCapDWithVersion(expect.ErrorMessage): """Tests -D works well when #version is present.""" shader = FileShader( """#version 310 es void main(){X} void foo(){Y}""", '.vert') glslc_args = ['-DX=', '-DY=return 3;', shader] expected_error = [ shader, ":3: error: 'return' : void function cannot return a value\n", '1 error generated.\n' ]
class WarningOnLine(expect.WarningMessage): """Tests that a warning message with a file/line number is emitted.""" shader = FileShader( """#version 140 attribute float x; void main() { } """, '.vert') glslc_args = ['-c', shader] expected_warning = [ shader, ':2: warning: attribute deprecated in version 130; ', 'may be removed in future release\n1 warning generated.\n']
class TestDashCapEOutputFile(expect.SuccessfulReturn, expect.ValidFileContents): """Tests to make sure -E works with output files.""" shader = FileShader('''#version 140 void function() { } ''', '.vert') expected_file_contents = '''#version 140 void function(){ } ''' target_filename = 'foo' glslc_args = ['-E', shader, '-ofoo']
class GlobalWarningAsError(expect.ErrorMessage): """Tests that with -Werror an error warning message without file/line number is emitted instead of a warning.""" shader = FileShader( """#version 550 void main() { } """, '.vert') glslc_args = ['-c', '-std=400', shader, '-Werror'] expected_error = [ shader, ': error: (version, profile) forced to be (400, none),' ' while in source code it is (550, none)\n1 error generated.\n']