blob: 9b353a7c425f93f4eba0453a64b1bf193e312393 [file] [log] [blame]
Andrew Woloszyne549e7b2015-07-16 11:07:40 -04001# Copyright 2015 The Shaderc Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import expect
16import os.path
17from glslc_test_framework import inside_glslc_testsuite
18from placeholder import FileShader, StdinShader, TempFileName
19
20
21@inside_glslc_testsuite('File')
22class SimpleFileCompiled(expect.ValidObjectFile):
23 """Tests whether or not a simple glsl file compiles."""
24
25 shader = FileShader('#version 310 es\nvoid main() {}', '.frag')
26 glslc_args = ['-c', shader]
27
28
29@inside_glslc_testsuite('File')
30class NotSpecifyingOutputName(expect.SuccessfulReturn,
31 expect.CorrectObjectFilePreamble):
32 """Tests that when there is no -o and -E/-S/-c specified, output as a.spv."""
33
34 shader = FileShader('void main() {}', '.frag')
35 glslc_args = [shader]
36
37 def check_output_a_spv(self, status):
38 output_name = os.path.join(status.directory, 'a.spv')
39 return self.verify_object_file_preamble(output_name)
40
41
42@inside_glslc_testsuite('Parameters')
43class HelpParameters(
44 expect.ReturnCodeIsZero, expect.StdoutMatch, expect.StderrMatch):
45 """Tests the --help flag outputs correctly and does not produce and error."""
46
47 glslc_args = ['--help']
48
49 expected_stdout = '''Usage: glslc [options] file...
50
51An input file of - represents standard input.
52
53Options:
54 -c Only run preprocess, compile, and assemble steps.
55 -Dmacro[=defn] Add an implicit macro definition.
56 -E Outputs only the results of the preprocessing step.
57 Output defaults to standard out.
58 -fshader-stage=<stage>
59 Treat subsequent input files as having stage <stage>.
60 Valid stages are vertex, fragment, tesscontrol, tesseval,
61 geometry, and compute.
62 -g Generate source-level debug information.
63 Currently this option has no effect.
64 --help Display available options.
65 -I <value> Add directory to include search path.
66 -o <file> Write output to <file>.
67 A file name of '-' represents standard output.
68 -std=<value> Version and profile for input files. Possible values
69 are concatenations of version and profile, e.g. 310es,
70 450core, etc.
71 -S Only run preprocess and compilation steps.
qiningf6d83742016-01-28 16:05:11 -050072 --target-env=<environment>
73 Set the target shader environment, and the semantics
74 of warnings and errors. Valid values are 'opengl',
75 'opengl_compat' and 'vulkan'. The default value is 'vulkan'.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040076 -w Suppresses all warning messages.
77 -Werror Treat all warnings as errors.
Lei Zhangf23e1bd2015-08-07 18:08:15 -040078 -working-directory <dir>
79 Resolve file paths relative to the specified directory.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040080 -x <language> Treat subsequent input files as having type <language>.
81 The only supported language is glsl.
82'''
83
84 expected_stderr = ''
85
86
87@inside_glslc_testsuite('Parameters')
88class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns):
89 """Tests that --help output is not too wide."""
90
91 glslc_args = ['--help']
92
93
94@inside_glslc_testsuite('Parameters')
95class UnknownSingleLetterArgument(expect.ErrorMessage):
96 """Tests that an unknown argument triggers an error message."""
97
98 glslc_args = ['-a']
99 expected_error = ["glslc: error: unknown argument: '-a'\n"]
100
101
102@inside_glslc_testsuite('Parameters')
103class UnknownMultiLetterArgument(expect.ErrorMessage):
104 """Tests that an unknown argument triggers an error message."""
105
106 glslc_args = ['-zzz']
107 expected_error = ["glslc: error: unknown argument: '-zzz'\n"]
108
109
110@inside_glslc_testsuite('Parameters')
111class UnsupportedOption(expect.ErrorMessage):
112 """Tests that an unsupported option triggers an error message."""
113
114 glslc_args = ['--unsupported-option']
115 expected_error = [
116 "glslc: error: unsupported option: '--unsupported-option'\n"]
117
118
119@inside_glslc_testsuite('File')
120class FileNotFound(expect.ErrorMessage):
121 """Tests the error message if a file cannot be found."""
122
123 blabla_file = TempFileName('blabla.frag')
124 glslc_args = [blabla_file]
125 expected_error = [
126 "glslc: error: cannot open input file: '", blabla_file,
127 "': No such file or directory\n"]
128
129
130@inside_glslc_testsuite('Unsupported')
131class LinkingNotSupported(expect.ErrorMessage):
132 """Tests the error message generated by linking not supported yet."""
133
134 shader1 = FileShader('void main() {}', '.vert')
135 shader2 = FileShader('void main() {}', '.frag')
136 glslc_args = [shader1, shader2]
137 expected_error = [
138 'glslc: error: linking multiple files is not supported yet. ',
139 'Use -c to compile files individually.\n']
140
141
142@inside_glslc_testsuite('Unsupported')
143class MultipleStdinUnsupported(expect.ErrorMessage):
144 """Tests the error message generated by having more than one - input."""
145
146 glslc_args = ['-c', '-fshader-stage=vertex', '-', '-']
147 expected_error = [
148 'glslc: error: specifying standard input "-" as input more'
149 ' than once is not allowed.\n']
150
151
152@inside_glslc_testsuite('Parameters')
153class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch):
154 """Tests that you must use -fshader-stage when specifying - as input."""
155 shader = StdinShader(
156 """
157 int a() {
158 }
159 void main() {
160 int x = a();
161 }
162 """)
163 glslc_args = [shader]
164
165 expected_stdout = ''
166 expected_stderr = [
167 "glslc: error: '-': -fshader-stage required when input is from "
168 'standard input "-"\n']