Skip to content

Commit

Permalink
add tests for working-directory option: 1) abs input, rel output, 2) …
Browse files Browse the repository at this point in the history
…abs input, abs output, 3) rel input, abs output
  • Loading branch information
Qining committed Feb 2, 2016
1 parent 0cca769 commit 9a07fe4
Showing 1 changed file with 54 additions and 19 deletions.
73 changes: 54 additions & 19 deletions glslc/test/working_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import expect
from environment import File, Directory
from glslc_test_framework import inside_glslc_testsuite
from placeholder import FileShader
from placeholder import FileShader, TempFileName


@inside_glslc_testsuite('WorkDir')
Expand Down Expand Up @@ -149,15 +149,22 @@ class TestWorkDirEqInArg(expect.ValidNamedObjectFile):
expected_object_filenames = ('a.spv',)


class WorkDirAffectsNotLinkedFile(expect.SuccessfulReturn,
expect.CorrectObjectFilePreamble):
@inside_glslc_testsuite('WorkDir')
class TestWorkDirCompileInputAbsolutePath(expect.SuccessfulReturn,
expect.CorrectObjectFilePreamble):
"""Tests -working-directory=<dir> when compiling input file with absolute
path without -o option. The output location should refer to the working
directory"""

shader1 = FileShader('void main() {}', '.vert')
shader2 = FileShader('void main() {}', '.vert')
environment = Directory('.', [
Directory('subdir', []),
])
glslc_args = ['-c', '-working-directory=subdir', shader1, shader2]

def check_output_in_subdir(self, status):
if hasattr(self, 'expected_object_filenames'):
input_filenames_to_verify = self.expected_object_filenames
else:
input_filenames_to_verify = status.input_filenames
for input_filename in input_filenames_to_verify:
for input_filename in status.input_filenames:
object_filename = expect.get_object_filename(
os.path.basename(input_filename))
success, message = self.verify_object_file_preamble(
Expand All @@ -168,30 +175,58 @@ def check_output_in_subdir(self, status):


@inside_glslc_testsuite('WorkDir')
class TestWorkDirCompileFileAbsolutePath(WorkDirAffectsNotLinkedFile):
"""Tests -working-directory=<dir> when compiling input file with absolute
path. The output location should refer to the working directory"""
class TestWorkDirAbsoluteInputRelativeOutput(expect.SuccessfulReturn,
expect.CorrectObjectFilePreamble):
"""Tests -working-directory=<dir> when the input file is provided as absolute
path and -o specifies a relative path for output. The output location should
refer to the working directory"""

shader1 = FileShader('void main() {}', '.vert')
shader2 = FileShader('void foo() {}', '.vert')
shader = FileShader('void main() {}', '.vert')
environment = Directory('.', [
Directory('subdir', []),
])
glslc_args = ['-c', '-working-directory=subdir', shader1, shader2]
glslc_args = ['-c', '-working-directory=subdir',
shader, '-o', 'output.spv']

def check_output_in_subdir(self, status):
output_name = os.path.join(status.directory, 'subdir', 'output.spv')
return self.verify_object_file_preamble(output_name)


@inside_glslc_testsuite('WorkDir')
class TestWorkDirCompileFileAbsolutePathWithOutputName(WorkDirAffectsNotLinkedFile):
"""Tests -working-directory=<dir> when compiling input file with absolute
path. The output location should refer to the working directory"""
class TestWorkDirRelativeInputAbsoluteOutput(expect.SuccessfulReturn,
expect.CorrectObjectFilePreamble):
"""Tests -working-directory=<dir> the input file is given by relative path,
and output file is given by absolute path, we should refer to -working-directory
to resolve the input file, but ignore it for output."""

environment = Directory('.', [EMPTY_SHADER_IN_SUBDIR])
output_file = TempFileName('output.spv')
glslc_args = ['-c', '-working-directory=subdir',
'shader.vert', '-o', output_file]

def checkout_output(self, status):
output_name = os.path.join(status.directory, 'output.spv')
return self.verify_object_file_preamble(output_name)


@inside_glslc_testsuite('WorkDir')
class TestWorkDirAbsoluteInputAbsoluteOutput(expect.SuccessfulReturn,
expect.CorrectObjectFilePreamble):
"""Tests -working-directory=<dir> when both input file and output file are
provided as absolute paths, we should ignore -working-directory."""

shader = FileShader('void main() {}', '.vert')
environment = Directory('.', [
Directory('subdir', []),
])
output_file = TempFileName('output.spv')
glslc_args = ['-c', '-working-directory=subdir',
shader, '-o', 'output.spv']
expected_object_filenames = ('output.spv',)
shader, '-o', output_file]

def checkout_output(self, status):
output_name = os.path.join(status.directory, 'output.spv')
return self.verify_object_file_preamble(output_name)


# The -working-directory flag should not affect the placement of the link file.
Expand Down

0 comments on commit 9a07fe4

Please sign in to comment.