[Piglit] [PATCH 08/12] Adds some tests for glsl_parser_tests.py

Dylan Baker baker.dylan.c at gmail.com
Tue Feb 11 18:11:13 PST 2014


Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/tests/glsl_parser_test_tests.py | 126 ++++++++++++++++++++++++++++++
 1 file changed, 126 insertions(+)
 create mode 100644 framework/tests/glsl_parser_test_tests.py

diff --git a/framework/tests/glsl_parser_test_tests.py b/framework/tests/glsl_parser_test_tests.py
new file mode 100644
index 0000000..d73879d
--- /dev/null
+++ b/framework/tests/glsl_parser_test_tests.py
@@ -0,0 +1,126 @@
+# Copyright (c) 2014 Intel Corporation
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+""" Provides tests for the shader_test module """
+
+import os
+import tempfile
+from contextlib import contextmanager
+import nose.tools as nt
+import framework.glsl_parser_test as glsl
+from framework.core import testBinDir
+
+
+ at contextmanager
+def _tempfile(data):
+    """ Create a temporary file and cleanup afterwards """
+    temp = tempfile.NamedTemporaryFile(delete=False)
+    temp.write(data)
+    temp.close()
+    yield temp.name
+    os.unlink(temp.name)
+
+
+def _check_config(content):
+    """ This is the test that actually checks the glsl config section """
+    with _tempfile(content) as tfile:
+        return glsl.glsl_parser_test(tfile), tfile
+
+
+def test_cpp_comments():
+    """ Test C++ style comments """
+    content = ('// [config]\n'
+               '// expect_result: pass\n'
+               '// glsl_version: 1.00\n'
+               '// [end config]\n')
+    test, name = _check_config(content)
+
+    nt.assert_equal(test.command, [os.path.join(testBinDir, 'glslparsertest'),
+                                   name, 'pass', '1.00'],
+                    msg="C++ style comments were not properly parsed")
+
+
+def test_c_comments():
+    """ Test C style comments """
+    content = ('/*\n'
+               ' * [config]\n'
+               ' * expect_result: pass\n'
+               ' * glsl_version: 1.00\n'
+               ' * [end config]\n'
+               ' */\n')
+    test, name = _check_config(content)
+
+    nt.assert_equal(test.command, [os.path.join(testBinDir, 'glslparsertest'),
+                                   name, 'pass', '1.00'],
+                    msg="C style comments were not properly parsed")
+
+
+ at nt.raises(glsl.GLSLParserException)
+def test_no_config_end():
+    """ end_config section is required """
+    content = ('// [config]\n'
+               '// expect_result: pass\n'
+               '// glsl_version: 1.00\n'
+               '//\n')
+    test, name = _check_config(content)
+
+
+ at nt.raises(glsl.GLSLParserException)
+def test_no_expecte_result():
+    """ expect_result section is required """
+    content = ('// [config]\n'
+               '// glsl_version: 1.00\n'
+               '//\n')
+    test, name = _check_config(content)
+
+
+ at nt.raises(glsl.GLSLParserException)
+def test_no_required_glsl_version():
+    """ glsl_version section is required """
+    content = ('//\n'
+               '// expect_result: pass\n'
+               '// [end config]\n')
+    test, name = _check_config(content)
+
+
+ at nt.raises(glsl.GLSLParserException)
+def test_no_config_start():
+    """ Config section is required """
+    content = ('//\n'
+               '// expect_result: pass\n'
+               '// glsl_version: 1.00\n'
+               '// [end config]\n')
+    test, name = _check_config(content)
+
+
+def test_blank_in_config():
+    """ C++ style comments can have uncommented newlines """
+    content = ('// [config]\n'
+               '\n'
+               '// expect_result: pass\n'
+               '// glsl_version: 1.00\n'
+               '// [end config]\n')
+
+    test, name = _check_config(content)
+
+    nt.assert_equal(test.command, [os.path.join(testBinDir, 'glslparsertest'),
+                                   name, 'pass', '1.00'],
+                    msg="A newline in a C++ style comment was not properly "
+                        "parsed.")
-- 
1.8.5.4



More information about the Piglit mailing list