Bug 1482496 - Support list values in wptmanifest conditionals, r=ato
authorJames Graham <james@hoppipolla.co.uk>
Thu, 16 Aug 2018 09:43:27 +0000
changeset 486992 ae52877671adab5f4a00e7887c6806dc26aa7cfa
parent 486991 5a18b9c9a5a610cded246291c1c80498eba9dcfb
child 486993 aae2db09d0b1cbd0a27abc764f27471cdae8bc07
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1482496
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1482496 - Support list values in wptmanifest conditionals, r=ato We were previously considering the grammar for conditionals in wpt manifests to be something like: "if " expr ":" string This excluded the possibilty of complex values on the RHS. Here we change it to the more obvious (and intended) "if " expr ":" value MozReview-Commit-ID: G6YWscW9dJS Differential Revision: https://phabricator.services.mozilla.com/D3127
testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py
testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/parser.py
testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_parser.py
testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_serializer.py
--- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py
+++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py
@@ -43,8 +43,21 @@ def test_metadata_inherit():
                                                     url_base="")
 
     test = tests[0][2].pop()
     test_obj = wpttest.from_manifest(test, inherit_metadata, test_metadata.get_test(test.id))
     assert test_obj.max_assertion_count == 3
     assert test_obj.min_assertion_count == 1
     assert test_obj.prefs == {"b": "c", "c": "d"}
     assert test_obj.tags == {"a", "dir:a"}
+
+
+def test_conditional():
+    tests = make_mock_manifest(("test", "a", 10), ("test", "a/b", 10),
+                               ("test", "c", 10))
+    test_metadata = manifestexpected.static.compile(BytesIO(test_0),
+                                                    {},
+                                                    data_cls_getter=manifestexpected.data_cls_getter,
+                                                    test_path="a",
+                                                    url_base="")
+    test_obj = wpttest.from_manifest(test, [], test_metadata.get_test(test.id))
+    assert test_obj.prefs == {"a": "b", "c": "d"}
+    assert test_obj.expected() == "FAIL"
--- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/parser.py
+++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/parser.py
@@ -207,16 +207,30 @@ class Tokenizer(object):
         elif c == eol:
             self.next_state = self.expr_or_value_state
             self.state = self.eol_state
         elif c == "[":
             self.state = self.list_start_state
         else:
             self.state = self.value_state
 
+    def after_expr_state(self):
+        self.skip_whitespace()
+        c = self.char()
+        if c == "#":
+            self.next_state = self.after_expr_state
+            self.state = self.comment_state
+        elif c == eol:
+            self.next_state = self.after_expr_state
+            self.state = self.eol_state
+        elif c == "[":
+            self.state = self.list_start_state
+        else:
+            self.state = self.value_state
+
     def list_start_state(self):
         yield (token_types.list_start, "[")
         self.consume()
         self.state = self.list_value_start_state
 
     def list_value_start_state(self):
         self.skip_whitespace()
         if self.char() == "]":
@@ -373,17 +387,17 @@ class Tokenizer(object):
         elif c in "'\"":
             self.consume()
             yield (token_types.string, self.consume_string(c))
         elif c == "#":
             raise ParseError(self.filename, self.line_number, "Comment before end of expression")
         elif c == ":":
             yield (token_types.separator, c)
             self.consume()
-            self.state = self.value_state
+            self.state = self.after_expr_state
         elif c in parens:
             self.consume()
             yield (token_types.paren, c)
         elif c in ("!", "="):
             self.state = self.operator_state
         elif c in digits:
             self.state = self.digit_state
         else:
@@ -581,20 +595,17 @@ class Parser(object):
         self.tree.pop()
 
     def expression_values(self):
         while self.token == (token_types.ident, "if"):
             self.consume()
             self.tree.append(ConditionalNode())
             self.expr_start()
             self.expect(token_types.separator)
-            if self.token[0] == token_types.string:
-                self.value()
-            else:
-                raise ParseError
+            self.value_block()
             self.tree.pop()
 
     def value(self):
         self.tree.append(ValueNode(self.token[1]))
         self.consume()
         self.tree.pop()
 
     def atom(self):
--- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_parser.py
+++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_parser.py
@@ -58,18 +58,56 @@ key:
                         ["VariableNode", "x", []]
                         ]],
                        ["VariableNode", "y", []]
                     ]],
                      ["ValueNode", "value", []],
                   ]]]]]]
         )
 
+    def test_expr_2(self):
+        self.compare(
+            """
+key:
+  if x == 1 : [value1, value2]""",
+            ["DataNode", None,
+             [["KeyValueNode", "key",
+               [["ConditionalNode", None,
+                 [["BinaryExpressionNode", None,
+                   [["BinaryOperatorNode", "==", []],
+                    ["VariableNode", "x", []],
+                       ["NumberNode", "1", []]
+                    ]],
+                     ["ListNode", None,
+                      [["ValueNode", "value1", []],
+                       ["ValueNode", "value2", []],
+                      ]],
+                  ]]]]]]
+        )
+
+    def test_expr_3(self):
+        self.compare(
+            """
+key:
+  if x == 1: if b: value""",
+            ["DataNode", None,
+             [["KeyValueNode", "key",
+               [["ConditionalNode", None,
+                 [["BinaryExpressionNode", None,
+                   [["BinaryOperatorNode", "==", []],
+                    ["VariableNode", "x", []],
+                       ["NumberNode", "1", []]
+                    ]],
+                     ["ValueNode", "if b: value", []],
+                  ]]]]]]
+        )
+
     def test_atom_0(self):
         with self.assertRaises(parser.ParseError):
             self.parse("key: @Unknown")
 
     def test_atom_1(self):
         with self.assertRaises(parser.ParseError):
             self.parse("key: @true")
 
+
 if __name__ == "__main__":
     unittest.main()
--- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_serializer.py
+++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_serializer.py
@@ -220,8 +220,13 @@ class TokenizerTest(unittest.TestCase):
 
     def test_atom_3(self):
         self.compare(r"""key: @Reset
 """)
 
     def test_atom_4(self):
         self.compare(r"""key: [a, @Reset, b]
 """)
+
+    def test_conditional_1(self):
+        self.compare("""foo:
+  if a or b: [1, 2]
+""")