Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/glslc/test/option_dash_E.py
1560 views
1
# 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
15
import expect
16
from glslc_test_framework import inside_glslc_testsuite
17
from placeholder import FileShader, StdinShader
18
19
20
@inside_glslc_testsuite('OptionCapE')
21
class TestDashCapENoDefs(expect.StdoutMatch):
22
"""Tests -E without any defines."""
23
24
shader = FileShader('#version 140\nvoid main(){}', '.vert')
25
expected_stdout = '#version 140\nvoid main() { }\n'
26
glslc_args = ['-E', shader]
27
28
29
@inside_glslc_testsuite('OptionCapE')
30
class TestDashCapEGlslFileAccepted(expect.StdoutMatch):
31
"""Tests -E if we provide a .glsl file without an explicit stage."""
32
33
shader = FileShader('#version 140\nvoid main(){}', '.glsl')
34
expected_stdout = '#version 140\nvoid main() { }\n'
35
glslc_args = ['-E', shader]
36
37
38
@inside_glslc_testsuite('OptionCapE')
39
class TestDashCapESingleDefine(expect.StdoutMatch):
40
"""Tests -E with command-line define."""
41
42
shader = FileShader('#version 140\nvoid main(){ int a = X; }', '.vert')
43
expected_stdout = '#version 140\nvoid main() { int a = 4; }\n'
44
glslc_args = ['-DX=4', '-E', shader]
45
46
47
@inside_glslc_testsuite('OptionCapE')
48
class TestDashCapEExpansion(expect.StdoutMatch):
49
"""Tests -E with macro expansion."""
50
51
shader = FileShader('''#version 140
52
#define X 4
53
void main() {
54
int a = X;
55
}
56
''', '.vert')
57
58
expected_stdout = '''#version 140
59
60
void main() {
61
int a = 4;
62
}
63
'''
64
glslc_args = ['-E', shader]
65
66
67
@inside_glslc_testsuite('OptionCapE')
68
class TestDashCapEFunctionMacro(expect.StdoutMatch):
69
"""Tests -E with function-style macro expansion."""
70
71
shader = FileShader('''#version 140
72
#define X(A) 4+A
73
void main() {
74
int a = X(1);
75
}
76
''', '.vert')
77
78
expected_stdout = '''#version 140
79
80
void main() {
81
int a = 4 + 1;
82
}
83
'''
84
glslc_args = ['-E', shader]
85
86
87
@inside_glslc_testsuite('OptionCapE')
88
class TestDashCapEPragma(expect.StdoutMatch):
89
"""Tests -E to make sure pragmas get retained."""
90
91
shader = FileShader('''#version 140
92
#pragma optimize(off)
93
void main() {
94
}
95
''', '.vert')
96
97
expected_stdout = '''#version 140
98
#pragma optimize(off)
99
void main() {
100
}
101
'''
102
glslc_args = ['-E', shader]
103
104
105
@inside_glslc_testsuite('OptionCapE')
106
class TestDashCapEExtension(expect.StdoutMatch):
107
"""Tests -E to make sure extensions get retained."""
108
109
shader = FileShader('''#version 140
110
#extension foo: require
111
void main() {
112
}
113
''', '.vert')
114
115
expected_stdout = '''#version 140
116
#extension foo : require
117
void main() {
118
}
119
'''
120
glslc_args = ['-E', shader]
121
122
123
@inside_glslc_testsuite('OptionCapE')
124
class TestDashCapELine(expect.StdoutMatch):
125
"""Tests -E to make sure line numbers get retained."""
126
127
shader = FileShader('''#version 140
128
#define X 4
129
#line X
130
131
#line 2 3
132
133
void main() {
134
}
135
''', '.vert')
136
137
expected_stdout = '''#version 140
138
139
#line 4
140
141
#line 2 3
142
143
void main() {
144
}
145
'''
146
glslc_args = ['-E', shader]
147
148
149
@inside_glslc_testsuite('OptionCapE')
150
class TestDashCapEError(expect.ErrorMessage):
151
"""Tests -E to make sure #errors get retained."""
152
153
shader = FileShader('''#version 140
154
#if 1
155
#error This is an error
156
#endif
157
158
void main() {
159
}
160
''', '.vert')
161
162
expected_error = [
163
shader, ':3: error: \'#error\' : This is an error\n',
164
'1 error generated.\n']
165
166
glslc_args = ['-E', shader]
167
168
169
@inside_glslc_testsuite('OptionCapE')
170
class TestDashCapEStdin(expect.StdoutMatch):
171
"""Tests to make sure -E works with stdin."""
172
173
shader = StdinShader('''#version 140
174
void main() {
175
}
176
''')
177
178
expected_stdout = '''#version 140
179
void main() {
180
}
181
'''
182
glslc_args = ['-E', '-fshader-stage=vertex', shader]
183
184
185
@inside_glslc_testsuite('OptionCapE')
186
class TestDashCapEStdinDoesNotRequireShaderStage(expect.StdoutMatch):
187
"""Tests to make sure -E works with stdin even when no shader-stage
188
is specified."""
189
190
shader = StdinShader('''#version 140
191
void main() {
192
}
193
''')
194
195
expected_stdout = '''#version 140
196
void main() {
197
}
198
'''
199
glslc_args = ['-E', shader]
200
201
202
@inside_glslc_testsuite('OptionCapE')
203
class TestDashCapEMultipleFiles(expect.StdoutMatch):
204
"""Tests to make sure -E works with multiple files."""
205
206
shader = StdinShader('''#version 140
207
void main() {
208
}
209
''')
210
shader2 = FileShader('''#version 140
211
void function() {
212
}
213
''', '.vert')
214
expected_stdout = '''#version 140
215
void main() {
216
}
217
#version 140
218
void function() {
219
}
220
'''
221
glslc_args = ['-E', '-fshader-stage=vertex', shader, shader2]
222
223
224
@inside_glslc_testsuite('OptionCapE')
225
class TestDashCapEMultipleFilesWithoutStage(expect.StdoutMatch):
226
"""Tests to make sure -E works with multiple files even if we do not
227
specify a stage."""
228
229
shader = StdinShader('''#version 140
230
void main() {
231
}
232
''')
233
shader2 = FileShader('''#version 140
234
void function() {
235
}
236
''', '.glsl')
237
expected_stdout = '''#version 140
238
void main() {
239
}
240
#version 140
241
void function() {
242
}
243
'''
244
glslc_args = ['-E', shader, shader2]
245
246
247
@inside_glslc_testsuite('OptionCapE')
248
class TestDashCapEOutputFile(expect.SuccessfulReturn, expect.ValidFileContents):
249
"""Tests to make sure -E works with output files."""
250
251
shader = FileShader('''#version 140
252
void function() {
253
}
254
''', '.vert')
255
expected_file_contents = '''#version 140
256
void function() {
257
}
258
'''
259
target_filename = 'foo'
260
glslc_args = ['-E', shader, '-ofoo']
261
262
263
@inside_glslc_testsuite('OptionCapE')
264
class TestDashCapEWithS(expect.StdoutMatch):
265
"""Tests -E in the presence of -S."""
266
267
shader = FileShader('#version 140\nvoid main(){}', '.vert')
268
expected_stdout = '#version 140\nvoid main() { }\n'
269
glslc_args = ['-E', '-S', shader]
270
271
272
@inside_glslc_testsuite('OptionCapE')
273
class TestMultipileDashCapE(expect.StdoutMatch):
274
"""Tests that using -E multiple times works."""
275
276
shader = FileShader('#version 140\nvoid main(){}', '.vert')
277
expected_stdout = '#version 140\nvoid main() { }\n'
278
glslc_args = ['-E', '-E', shader, '-E']
279
280
281
@inside_glslc_testsuite('OptionCapE')
282
class TestDashCapEAfterFile(expect.StdoutMatch):
283
"""Tests that using -E after the filename also works."""
284
285
shader = FileShader('#version 140\nvoid main(){}', '.vert')
286
expected_stdout = '#version 140\nvoid main() { }\n'
287
glslc_args = [shader, '-E']
288
289
290
@inside_glslc_testsuite('OptionCapE')
291
class TestDashCapEWithDashC(expect.StdoutMatch):
292
"""Tests to make sure -E works in the presence of -c."""
293
294
shader = FileShader('''#version 140
295
void main() {
296
}
297
''', '.vert')
298
shader2 = FileShader('''#version 140
299
void function() {
300
}
301
''', '.vert')
302
expected_stdout = '''#version 140
303
void main() {
304
}
305
#version 140
306
void function() {
307
}
308
'''
309
glslc_args = ['-E', '-c', shader, shader2]
310
311
312
@inside_glslc_testsuite('OptionCapE')
313
class TestDashCapEWithPPErrors(expect.ErrorMessage):
314
"""Tests to make sure -E outputs error messages for preprocessing errors."""
315
316
shader = FileShader('''#version 310 es
317
#extension s enable // missing :
318
#defin A // Bad define
319
#if X // In glsl X must be defined for X to work.
320
// Lack of endif.
321
void main() {
322
}
323
''', '.vert')
324
expected_error = [
325
shader, ':2: error: \'#extension\' : \':\' missing after extension',
326
' name\n',
327
shader, ':3: error: \'#\' : invalid directive: defin\n',
328
shader, ':4: error: \'preprocessor evaluation\' : undefined macro in',
329
' expression not allowed in es profile X\n',
330
shader, ':8: error: \'\' : missing #endif\n',
331
'4 errors generated.\n']
332
glslc_args = ['-E', shader]
333
334
335
@inside_glslc_testsuite('OptionCapE')
336
class TestDashCapEStdinErrors(expect.ErrorMessage):
337
"""Tests that -E outputs error messages correctly for stdin input."""
338
339
shader = StdinShader('''#version 310 es
340
#extension s enable // missing :
341
void main() {
342
}
343
''')
344
expected_error = [
345
'<stdin>:2: error: \'#extension\' : \':\' missing after extension',
346
' name\n',
347
'1 error generated.\n']
348
glslc_args = ['-E', shader]
349
350