Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/glslc/test/option_dash_D.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
18
19
20
@inside_glslc_testsuite('OptionCapD')
21
class TestDashCapDNoArg(expect.ErrorMessage):
22
"""Tests -D without macroname."""
23
24
glslc_args = ['-D']
25
expected_error = [
26
"glslc: error: argument to '-D' is missing\n",
27
'glslc: error: no input files\n']
28
29
30
@inside_glslc_testsuite('OptionCapD')
31
class TestDashCapDXeqY(expect.ValidObjectFile):
32
"""Tests -DX=Y."""
33
34
shader = FileShader('#version 150\nvoid main(){X=vec4(1.);}', '.vert')
35
glslc_args = ['-c', '-DX=gl_Position', shader]
36
37
38
@inside_glslc_testsuite('OptionCapD')
39
class TestDashCapDXeq(expect.ValidObjectFile):
40
"""Tests -DX=."""
41
42
shader = FileShader('#version 150\nvoid main(){X}', '.vert')
43
glslc_args = ['-c', '-DX=', shader]
44
45
46
@inside_glslc_testsuite('OptionCapD')
47
class TestDashCapDX(expect.ValidObjectFile):
48
"""Tests -DX."""
49
50
shader = FileShader('#version 150\nvoid main(){X}', '.vert')
51
glslc_args = ['-c', '-DX', shader]
52
53
54
@inside_glslc_testsuite('OptionCapD')
55
class TestDashCapDeq(expect.ErrorMessage):
56
"""Tests -D=.
57
58
This is actually allowed by clang, though the resulting #define
59
causes a preprocessing error.
60
"""
61
62
shader = FileShader('#version 150\nvoid main(){}', '.vert')
63
glslc_args = ['-c', '-D=', shader]
64
# TODO(antiagainst): figure out what should we report as the line number
65
# for errors in predefined macros and fix here.
66
expected_error = [
67
"<command line>:2: error: '#define' : must be followed by macro name\n",
68
'1 error generated.\n']
69
70
71
@inside_glslc_testsuite('OptionCapD')
72
class TestMultipleDashCapD(expect.ValidObjectFile):
73
"""Tests multiple -D occurrences."""
74
75
shader = FileShader('#version 150\nvoid main(){X Y a=Z;}', '.vert')
76
glslc_args = ['-c', '-DX', '-DY=int', '-DZ=(1+2)', shader]
77
78
79
@inside_glslc_testsuite('OptionCapD')
80
class TestMultipleDashCapDOfSameName(expect.ValidObjectFile):
81
"""Tests multiple -D occurrences with same macro name."""
82
83
shader = FileShader('#version 150\nvoid main(){X Y a=Z;}', '.vert')
84
glslc_args = ['-c', '-DX=main', '-DY=int', '-DZ=(1+2)', '-DX', shader]
85
86
87
@inside_glslc_testsuite('OptionCapD')
88
class TestDashCapDGL_(expect.ErrorMessage):
89
"""Tests that we cannot -D macros beginning with GL_."""
90
91
shader = FileShader('#version 150\nvoid main(){}', '.vert')
92
glslc_args = ['-DGL_ES=1', shader]
93
expected_error = [
94
"glslc: error: names beginning with 'GL_' cannot be "
95
'defined: -DGL_ES=1\n']
96
97
98
@inside_glslc_testsuite('OptionCapD')
99
class TestDashCapDReservedMacro(expect.WarningMessage):
100
"""Tests that we cannot -D GLSL's predefined macros."""
101
102
shader = FileShader('#version 150\nvoid main(){}', '.vert')
103
# Consecutive underscores are banned anywhere in the name.
104
glslc_args = [
105
'-D__LINE__=1', '-Dmid__dle', '-Dend__', '-D_single_is_valid_', shader]
106
107
w = 'glslc: warning: names containing consecutive underscores are reserved: '
108
expected_warning = [w, '-D__LINE__=1\n', w, '-Dmid__dle\n', w, '-Dend__\n']
109
110
111
@inside_glslc_testsuite('OptionCapD')
112
class TestDashCapDWithVersion(expect.ErrorMessage):
113
"""Tests -D works well when #version is present."""
114
115
shader = FileShader(
116
"""#version 310 es
117
void main(){X}
118
void foo(){Y}""", '.vert')
119
glslc_args = ['-DX=', '-DY=return 3;', shader]
120
121
expected_error = [
122
shader, ":3: error: 'return' : void function cannot return a value\n",
123
'1 error generated.\n']
124
125
126
@inside_glslc_testsuite('OptionCapD')
127
class TestDashCapDWithCommentBeforeVersion(expect.ErrorMessage):
128
"""Tests -D works well with #version preceded by comments."""
129
130
shader = FileShader(
131
"""// comment 1
132
/*
133
* comment 2
134
*/
135
#version 450 core
136
void main(){X}
137
void foo(){Y}""", '.vert')
138
glslc_args = ['-DX=', '-DY=return 3;', shader]
139
140
expected_error = [
141
shader, ":7: error: 'return' : void function cannot return a value\n",
142
'1 error generated.\n']
143
144
145
@inside_glslc_testsuite('OptionCapD')
146
class TestDashCapDWithCommentAfterVersion(expect.ErrorMessage):
147
"""Tests -D works well with #version followed by comments."""
148
149
shader = FileShader(
150
"""
151
152
#version 150 core /*
153
comment
154
*/
155
void main(){X}
156
void foo(){Y}""", '.vert')
157
glslc_args = ['-DX=', '-DY=return 3;', shader]
158
159
expected_error = [
160
shader, ":7: error: 'return' : void function cannot return a value\n",
161
'1 error generated.\n']
162
163
164
@inside_glslc_testsuite('OptionCapD')
165
class TestDashCapDWithDashStd(expect.ErrorMessageSubstr):
166
"""Tests -D works well with -std."""
167
168
shader = FileShader('void main(){X}\nvoid foo(){Y}', '.vert')
169
glslc_args = ['-DX=', '-DY=return 3;', '-std=310es', shader]
170
171
expected_error_substr = [
172
shader, ":2: error: 'return' : void function cannot return a value\n",
173
'1 error generated.\n']
174
175
176
@inside_glslc_testsuite('OptionCapD')
177
class TestDashCapDWithDashStdAndVersion(expect.ErrorMessage):
178
"""Tests -D works well with both -std and #version."""
179
180
shader = FileShader(
181
"""#version 310 es
182
void main(){X}
183
void foo(){Y}""", '.vert')
184
glslc_args = ['-DX=', '-DY=return 3;', '-std=450core', shader]
185
186
expected_error = [
187
shader, ': warning: (version, profile) forced to be (450, ',
188
'core), while in source code it is (310, es)\n',
189
shader, ":3: error: 'return' : void function cannot return a value\n",
190
'1 warning and 1 error generated.\n']
191
192
193
@inside_glslc_testsuite('OptionCapD')
194
class TestDashCapDWithDashStdAndVersionAndComments(expect.ErrorMessage):
195
"""Tests -D works well with -std, #version, and comments around it."""
196
197
shader = FileShader(
198
"""// comment before
199
200
#version 310 es /* comment after
201
*/
202
203
void main(){X}
204
void foo(){Y}""", '.vert')
205
glslc_args = ['-DX=', '-DY=return 3;', '-std=450core', shader]
206
207
expected_error = [
208
shader, ': warning: (version, profile) forced to be (450, core), while '
209
'in source code it is (310, es)\n',
210
shader, ":7: error: 'return' : void function cannot return a value\n",
211
'1 warning and 1 error generated.\n']
212
213
214
@inside_glslc_testsuite('OptionCapD')
215
class TestDashCapDWithDashE(expect.ReturnCodeIsZero,
216
expect.StdoutMatch):
217
"""Tests -E outputs expanded -D macros."""
218
219
shader = FileShader(
220
"""
221
void main(){Y}
222
""", '.vert')
223
glslc_args = ['-DY=return 3;', '-E', '-std=450core', shader]
224
225
expected_stdout = [
226
"""
227
void main() { return 3; }
228
"""]
229
230
@inside_glslc_testsuite('OptionCapD')
231
class TestDashCapDWithDashEIfDef(expect.ReturnCodeIsZero,
232
expect.StdoutMatch):
233
"""Tests -E processes -DX #ifdefs correctly."""
234
235
shader = FileShader(
236
"""
237
#ifdef X
238
void f() { }
239
#else
240
void f() { int x; }
241
#endif
242
void main(){ return 3; }
243
""", '.vert')
244
glslc_args = ['-DX', '-E', '-std=450core', shader]
245
246
expected_stdout = [
247
"""
248
249
void f() { }
250
251
252
253
void main() { return 3; }
254
"""]
255
256
@inside_glslc_testsuite('OptionCapD')
257
class TestDashCapDWithDashEIfNDef(expect.ReturnCodeIsZero,
258
expect.StdoutMatch):
259
"""Tests -E processes -DX #ifndefs correctly."""
260
261
shader = FileShader(
262
"""
263
#ifndef X
264
void f() { }
265
#else
266
void f() { int x; }
267
#endif
268
void main(){ return 3; }
269
""", '.vert')
270
glslc_args = ['-DX', '-E', '-std=450core', shader]
271
272
expected_stdout = [
273
"""
274
275
276
277
void f() { int x; }
278
279
void main() { return 3; }
280
"""]
281
282
283
@inside_glslc_testsuite('OptionCapD')
284
class TestDashCapDWithDashEEqIfDef(expect.ReturnCodeIsZero,
285
expect.StdoutMatch):
286
"""Tests -E processes -DX= #ifdefs correctly."""
287
288
shader = FileShader(
289
"""
290
#ifdef X
291
void f() { }
292
#else
293
void f() { int x; }
294
#endif
295
void main() { return 3; }
296
""", '.vert')
297
glslc_args = ['-DX=', '-E', '-std=450core', shader]
298
299
expected_stdout = [
300
"""
301
302
void f() { }
303
304
305
306
void main() { return 3; }
307
"""]
308
309
@inside_glslc_testsuite('OptionCapD')
310
class TestDashCapDWithDashEEqIfNDef(expect.ReturnCodeIsZero,
311
expect.StdoutMatch):
312
"""Tests -E processes -DX= #ifndefs correctly."""
313
314
shader = FileShader(
315
"""
316
#ifndef X
317
void f() { }
318
#else
319
void f() { int x; }
320
#endif
321
void main(){ return 3; }
322
""", '.vert')
323
glslc_args = ['-DX=', '-E', '-std=450core', shader]
324
325
expected_stdout = [
326
"""
327
328
329
330
void f() { int x; }
331
332
void main() { return 3; }
333
"""]
334
335
@inside_glslc_testsuite('OptionCapD')
336
class TestDashCapDWithDashEFunctionMacro(expect.ReturnCodeIsZero,
337
expect.StdoutMatch):
338
"""Tests -E processes -D function macros correctly."""
339
340
shader = FileShader(
341
"""
342
void main(){ return FOO(3); }
343
""", '.vert')
344
glslc_args = ['-DFOO(x)=(2*x+1)*x*x', '-E', '-std=450core', shader]
345
346
expected_stdout = [
347
"""
348
void main() { return(2 * 3 + 1) * 3 * 3; }
349
"""]
350
351
@inside_glslc_testsuite('OptionCapD')
352
class TestDashCapDWithDashENestedMacro(expect.ReturnCodeIsZero,
353
expect.StdoutMatch):
354
"""Tests -E processes referencing -D options correctly."""
355
356
shader = FileShader(
357
"""
358
void main() { return X; }
359
""", '.vert')
360
glslc_args = ['-DY=4', '-DX=Y', '-E', '-std=450core', shader]
361
362
expected_stdout = [
363
"""
364
void main() { return 4; }
365
"""]
366
367