[Piglit] [PATCH 3/3] glsl_parser_test.py: Limit keys to known keys

Dylan Baker baker.dylan.c at gmail.com
Tue Jun 24 16:54:17 PDT 2014


This disallows keys that are unknown from being added.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/glsl_parser_test.py             | 15 +++++++++++++--
 framework/tests/glsl_parser_test_tests.py | 12 ++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index a71c167..c268d06 100644
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -80,6 +80,10 @@ class GLSLParserTest(PiglitTest):
                 .tesc, .tese, .geom or .frag
 
     """
+    # A list of valid keys for the config section
+    _CONFIG_KEYS = set(['expect_result', 'glsl_version',
+                        'require_extensions'])
+
     def __init__(self, filepath):
         # Text of config section.
         text_io = StringIO()
@@ -87,11 +91,18 @@ class GLSLParserTest(PiglitTest):
 
         def add_line(line):
             """ Add line to the stringio, and validate the keys """
-            # Ensure that this is the only instance of this key
             split = line.split(':')[0]
+
+            # If the line is '\n' then we got a blank newline, go on
+            if split == '\n':
+                return  # this is effectively 'continue'
+            assert split in self._CONFIG_KEYS, 'Unexpected key: "{0}"'.format(
+                split)
+
             assert split not in found_keys, 'Duplicate key: "{0}"'.format(
                 split)
             found_keys.add(split)
+
             text_io.write(line)
 
         os.stat(filepath)
@@ -131,10 +142,10 @@ class GLSLParserTest(PiglitTest):
                 # it into the StringIO
                 elif line[:2] in ['//', '/*', '*/']:
                     add_line(line[2:].lstrip() + '\n')
+                # If we have just * then we're in the middle of a C style
                 # comment, do like above
                 elif line[:1] == '*':
                     add_line(line[1:].lstrip() + '\n')
-                # If we have just * then we're in the middle of a C style
                 else:
                     raise GLSLParserException(
                         "The config section is malformed."
diff --git a/framework/tests/glsl_parser_test_tests.py b/framework/tests/glsl_parser_test_tests.py
index ebfa0ce..6227727 100644
--- a/framework/tests/glsl_parser_test_tests.py
+++ b/framework/tests/glsl_parser_test_tests.py
@@ -204,3 +204,15 @@ def test_duplicate_entries():
             ''.join(x[1] for x in content), value)
 
         yield check_no_duplicates, test
+
+
+ at nt.raises(AssertionError)
+def test_bad_section_name():
+    """ A section name not in the _CONFIG_KEYS name raises an error """
+    content = ('// [config]\n'
+               '// expect_result: pass\n'
+               '// glsl_version: 1.00\n'
+               '// new_awesome_key: foo\n'
+               '// [end config]\n')
+
+    _check_config(content)
-- 
2.0.0



More information about the Piglit mailing list