1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
|
# 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 SpecializedString
from environment import File, Directory
@inside_glslc_testsuite('Include')
class VerifyIncludeOneSibling(expect.StdoutMatch):
"""Tests #including a sibling file."""
environment = Directory('.', [
File('a.vert', '#version 140\ncontent a\n#include "b"\n'),
File('b', 'content b\n')])
glslc_args = ['-E', 'a.vert']
expected_stdout = \
"""#version 140
#extension GL_GOOGLE_include_directive : enable
#line 0 "a.vert"
content a
#line 0 "b"
content b
#line 3 "a.vert"
"""
@inside_glslc_testsuite('Include')
class VerifyIncludeNotFound(expect.ErrorMessage):
"""Tests #including a not existing sibling file."""
environment = Directory('.', [
File('a.vert', '#version 140\ncontent a\n#include "b"\n')])
glslc_args = ['-E', 'a.vert']
expected_error = [
"a.vert:3: error: '#include' : Cannot find or open include file. for header name: b\n",
'1 error generated.\n'
]
@inside_glslc_testsuite('Include')
class VerifyCompileIncludeOneSibling(expect.ValidObjectFile):
"""Tests #including a sibling file via full compilation."""
environment = Directory('.', [
File('a.vert', '#version 140\nvoid foo(){}\n#include "b"\n'),
File('b', 'void main(){foo();}\n')])
glslc_args = ['a.vert']
@inside_glslc_testsuite('Include')
class VerifyIncludeWithoutNewline(expect.ErrorMessageSubstr):
"""Tests a #include without a newline."""
environment = Directory('.', [
File('a.vert', '#version 140\n#include "b"'),
File('b', 'content b\n')])
glslc_args = ['-E', 'a.vert']
expected_error_substr = 'expected newline after header name: b'
@inside_glslc_testsuite('Include')
class VerifyCompileIncludeWithoutNewline(expect.ValidObjectFile):
"""Tests a #include without a newline via full compilation."""
environment = Directory('.', [
File('a.vert',
"""#version 140
void main
#include "b"
"""),
File('b',
"""#define PAR ()
PAR{}
""")])
glslc_args = ['a.vert']
@inside_glslc_testsuite('Include')
class VerifyIncludeTwoSiblings(expect.StdoutMatch):
"""Tests #including two sibling files."""
environment = Directory('.', [
File('b.vert', '#version 140\n#include "a"\ncontent b\n#include "c"\n'),
File('a', 'content a\n'),
File('c', 'content c\n')])
glslc_args = ['-E', 'b.vert']
expected_stdout = \
"""#version 140
#extension GL_GOOGLE_include_directive : enable
#line 0 "b.vert"
#line 0 "a"
content a
#line 2 "b.vert"
content b
#line 0 "c"
content c
#line 4 "b.vert"
"""
@inside_glslc_testsuite('Include')
class VerifyCompileIncludeTwoSiblings(expect.ValidObjectFile):
"""Tests #including two sibling files via full compilation."""
environment = Directory('.', [
File('b.vert',
"""#version 140
#include "a"
void bfun(){afun();}
#include "c"
"""),
File('a',
"""void afun(){}
#define BODY {}
"""),
File('c', 'void main() BODY\n')])
glslc_args = ['b.vert']
@inside_glslc_testsuite('Include')
class VerifyNestedIncludeAmongSiblings(expect.StdoutMatch):
"""Tests #include inside #included sibling files."""
environment = Directory('.', [
File('a.vert', '#version 140\n#include "b"\ncontent a\n'),
File('b', 'content b\n#include "c"\n'),
File('c', 'content c\n')])
glslc_args = ['-E', 'a.vert']
expected_stdout = \
"""#version 140
#extension GL_GOOGLE_include_directive : enable
#line 0 "a.vert"
#line 0 "b"
content b
#line 0 "c"
content c
#line 2 "b"
#line 2 "a.vert"
content a
"""
@inside_glslc_testsuite('Include')
class VerifyCompileNestedIncludeAmongSiblings(expect.ValidObjectFile):
"""Tests #include inside #included sibling files via full compilation."""
environment = Directory('.', [
File('a.vert',
"""#version 140
#define BODY {}
#include "b"
void main(){cfun();}
"""),
File('b',
"""void bfun() BODY
#include "c"
"""),
File('c',
"""#define BF bfun()
void cfun(){BF;}
""")])
glslc_args = ['a.vert']
@inside_glslc_testsuite('Include')
class VerifyIncludeSubdir(expect.StdoutMatch):
"""Tests #including a file from a subdirectory."""
environment = Directory('.', [
File('a.vert', '#version 140\ncontent a1\n#include "subdir/a"\ncontent a2\n'),
Directory('subdir', [File('a', 'content suba\n')])])
glslc_args = ['-E', 'a.vert']
expected_stdout = \
"""#version 140
#extension GL_GOOGLE_include_directive : enable
#line 0 "a.vert"
content a1
#line 0 "subdir/a"
content suba
#line 3 "a.vert"
content a2
"""
@inside_glslc_testsuite('Include')
class VerifyCompileIncludeSubdir(expect.ValidObjectFile):
"""Tests #including a file from a subdirectory via full compilation."""
environment = Directory('.', [
File('a.vert',
"""#version 140
#define BODY {}
#include "subdir/a"
void afun()BODY
"""),
Directory('subdir', [File('a', 'void main() BODY\n')])])
glslc_args = ['a.vert']
@inside_glslc_testsuite('Include')
class VerifyIncludeDeepSubdir(expect.StdoutMatch):
"""Tests #including a file from a subdirectory nested a few levels down."""
environment = Directory('.', [
File('a.vert',
'#version 140\ncontent a1\n#include "dir/subdir/subsubdir/a"\ncontent a2\n'),
Directory('dir', [
Directory('subdir', [
Directory('subsubdir', [File('a', 'content incl\n')])])])])
glslc_args = ['-E', 'a.vert']
expected_stdout = \
"""#version 140
#extension GL_GOOGLE_include_directive : enable
#line 0 "a.vert"
content a1
#line 0 "dir/subdir/subsubdir/a"
content incl
#line 3 "a.vert"
content a2
"""
@inside_glslc_testsuite('Include')
class VerifyCompileIncludeDeepSubdir(expect.ValidObjectFile):
"""Tests #including a file from a subdirectory nested a few levels down
via full compilation."""
environment = Directory('.', [
File('a.vert',
"""#version 140
#define BODY {}
#include "dir/subdir/subsubdir/a"
void afun()BODY
"""),
Directory('dir', [
Directory('subdir', [
Directory('subsubdir', [File('a', 'void main() BODY\n')])])])])
glslc_args = ['a.vert']
@inside_glslc_testsuite('Include')
class TestWrongPoundVersionInIncludingFile(expect.ValidObjectFileWithWarning):
"""Tests that warning message for #version directive in the including file
has the correct filename."""
environment = Directory('.', [
File('a.vert', '#version 100000000\n#include "b.glsl"\n'),
File('b.glsl', 'void main() {}\n')])
glslc_args = ['-c', '-std=400', 'a.vert']
expected_warning = [
'a.vert: warning: (version, profile) forced to be (400, none),'
' while in source code it is (100000000, none)\n'
'1 warning generated.\n'
]
# TODO(antiagainst): now #version in included files results in an error.
# Fix this after #version in included files are supported.
# TODO(dneto): I'm not sure what the expected result should be.
@inside_glslc_testsuite('Include')
class TestWrongPoundVersionInIncludedFile(expect.ErrorMessage):
"""Tests that warning message for #version directive in the included file
has the correct filename."""
environment = Directory('.', [
File('a.vert', '#version 140\n#include "b.glsl"\nvoid main() {}'),
File('b.glsl', '#version 10000000\n')])
glslc_args = ['-E', 'a.vert']
expected_error = [
"b.glsl:1: error: '#version' : must occur first in shader\n",
'1 error generated.\n'
]
@inside_glslc_testsuite('Include')
class VerifyRelativeInclude(expect.StdoutMatch):
"""Tests #including a relative sibling."""
environment = Directory('.', [
File('a.vert', '#version 140\ncontent a\n#include "foo/b.glsl"\n'),
Directory('foo', [
File('b.glsl', '#include "c.glsl"\ncontent b\n'),
File('c.glsl', 'content c\n')
])])
glslc_args = ['-E', 'a.vert']
expected_stdout = \
"""#version 140
#extension GL_GOOGLE_include_directive : enable
#line 0 "a.vert"
content a
#line 0 "foo/b.glsl"
#line 0 "foo/c.glsl"
content c
#line 1 "foo/b.glsl"
content b
#line 3 "a.vert"
"""
@inside_glslc_testsuite('Include')
class VerifyNestedRelativeInclude(expect.StdoutMatch):
"""Tests #including a relative child file."""
environment = Directory('.', [
File('a.vert', '#version 140\ncontent a\n#include "foo/b.glsl"\n'),
Directory('foo', [
File('b.glsl', '#include "bar/c.glsl"\ncontent b\n'),
Directory('bar', [
File('c.glsl', 'content c\n')
])
])
])
glslc_args = ['-E', 'a.vert']
expected_stdout = \
"""#version 140
#extension GL_GOOGLE_include_directive : enable
#line 0 "a.vert"
content a
#line 0 "foo/b.glsl"
#line 0 "foo/bar/c.glsl"
content c
#line 1 "foo/b.glsl"
content b
#line 3 "a.vert"
"""
@inside_glslc_testsuite('Include')
class VerifyRelativeIncludeWithDashI(expect.StdoutMatch):
"""Tests #including a relative file from a -I directory."""
environment = Directory('.', [
File('a.vert', '#version 140\ncontent a\n#include "bar/b.glsl"\n'),
Directory('foo', [
Directory('bar', [
File('b.glsl', '#include "c.glsl"\ncontent b\n'),
]),
File('c.glsl', 'content c\n')
])
])
glslc_args = ['-E', 'a.vert', '-Ifoo']
expected_stdout = \
"""#version 140
#extension GL_GOOGLE_include_directive : enable
#line 0 "a.vert"
content a
#line 0 "foo/bar/b.glsl"
#line 0 "foo/c.glsl"
content c
#line 1 "foo/bar/b.glsl"
content b
#line 3 "a.vert"
"""
@inside_glslc_testsuite('Include')
class VerifyRelativeOverridesDashI(expect.StdoutMatch):
"""Tests that relative includes override -I parameters."""
environment = Directory('.', [
File('a.vert', '#version 140\ncontent a\n#include "b.glsl"\n'),
File('b.glsl', 'content base_b\n'),
Directory('foo', [
File('b.glsl', '#include "c.glsl"\ncontent b\n'),
File('c.glsl', 'content c\n')
])
])
glslc_args = ['-E', 'a.vert', '-Ifoo']
expected_stdout = \
"""#version 140
#extension GL_GOOGLE_include_directive : enable
#line 0 "a.vert"
content a
#line 0 "b.glsl"
content base_b
#line 3 "a.vert"
"""
@inside_glslc_testsuite('Include')
class VerifyRelativeParent(expect.StdoutMatch):
"""Tests #including a parent file."""
environment = Directory('.', [
File('a.vert', '#version 140\ncontent a\n#include "b.glsl"\n'),
File('c.glsl', 'content c\n'),
Directory('foo', [
File('b.glsl', '#include "../c.glsl"\ncontent b\n')
])
])
glslc_args = ['-E', 'a.vert', '-Ifoo']
expected_stdout = \
"""#version 140
#extension GL_GOOGLE_include_directive : enable
#line 0 "a.vert"
content a
#line 0 "foo/b.glsl"
#line 0 "foo/../c.glsl"
content c
#line 1 "foo/b.glsl"
content b
#line 3 "a.vert"
"""
@inside_glslc_testsuite('Include')
class VerifyRelativeNeighbourDirectory(expect.StdoutMatch):
"""Tests #including a relative file in a neighbour directory."""
environment = Directory('.', [
File('a.vert', '#version 140\ncontent a\n#include "foo/b.glsl"\n'),
Directory('foo', [
File('b.glsl', '#include "../bar/c.glsl"\ncontent b\n')
]),
Directory('bar', [
File('c.glsl', 'content c\n')
])
])
glslc_args = ['-E', 'a.vert']
expected_stdout = \
"""#version 140
#extension GL_GOOGLE_include_directive : enable
#line 0 "a.vert"
content a
#line 0 "foo/b.glsl"
#line 0 "foo/../bar/c.glsl"
content c
#line 1 "foo/b.glsl"
content b
#line 3 "a.vert"
"""
@inside_glslc_testsuite('Include')
class VerifyRelativeOnlyToSelf(expect.ErrorMessage):
"""Tests that a relative includes are only relative to yourself."""
environment = Directory('.', [
File('a.vert', '#version 140\ncontent a\n#include "foo/b.glsl"\n'),
File('c.glsl', 'content c\n'),
Directory('foo', [
File('b.glsl', '#include "c.glsl"\ncontent b\n')
]),
])
glslc_args = ['-E', 'a.vert']
expected_error = [
"foo/b.glsl:1: error: '#include' : "
'Cannot find or open include file. for header name: c.glsl\n',
'1 error generated.\n'
]
@inside_glslc_testsuite('Include')
class VerifyRelativeFromAbsolutePath(expect.StdoutMatch):
"""Tests that absolute files can relatively include."""
environment = Directory('.', [
File('a.vert', '#version 140\ncontent a\n#include "b.glsl"\n'),
File('b.glsl', 'content b\n')
])
glslc_args = ['-E', SpecializedString('$directory/a.vert')]
expected_stdout = SpecializedString(
"""#version 140
#extension GL_GOOGLE_include_directive : enable
#line 0 "$directory/a.vert"
content a
#line 0 "$directory/b.glsl"
content b
#line 3 "$directory/a.vert"
""")
@inside_glslc_testsuite('Include')
class VerifyDashIAbsolutePath(expect.StdoutMatch):
"""Tests that -I parameters can be absolute paths."""
environment = Directory('.', [
File('a.vert', '#version 140\ncontent a\n#include "b.glsl"\n'),
Directory('foo', {
File('b.glsl', 'content b\n')
})
])
glslc_args = ['-E', 'a.vert', '-I', SpecializedString('$directory/foo')]
expected_stdout = SpecializedString(
"""#version 140
#extension GL_GOOGLE_include_directive : enable
#line 0 "a.vert"
content a
#line 0 "$directory/foo/b.glsl"
content b
#line 3 "a.vert"
""")
|