瀏覽代碼

qapi: Check feature documentation against the schema

Commit f3ed93d545 "qapi: Allow documentation for features" neglected
to check documentation against the schema.  Fix that: check them the
same way we check arguments.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20191024110237.30963-20-armbru@redhat.com>
Markus Armbruster 5 年之前
父節點
當前提交
e151941d1b

+ 22 - 9
scripts/qapi/parser.py

@@ -555,18 +555,31 @@ def connect_member(self, member):
             self.args[member.name] = QAPIDoc.ArgSection(member.name)
             self.args[member.name] = QAPIDoc.ArgSection(member.name)
         self.args[member.name].connect(member)
         self.args[member.name].connect(member)
 
 
+    def connect_feature(self, feature):
+        if feature.name not in self.features:
+            raise QAPISemError(feature.info,
+                               "feature '%s' lacks documentation"
+                               % feature.name)
+            self.features[feature.name] = QAPIDoc.ArgSection(feature.name)
+        self.features[feature.name].connect(feature)
+
     def check_expr(self, expr):
     def check_expr(self, expr):
         if self.has_section('Returns') and 'command' not in expr:
         if self.has_section('Returns') and 'command' not in expr:
             raise QAPISemError(self.info,
             raise QAPISemError(self.info,
                                "'Returns:' is only valid for commands")
                                "'Returns:' is only valid for commands")
 
 
     def check(self):
     def check(self):
-        bogus = [name for name, section in self.args.items()
-                 if not section.member]
-        if bogus:
-            raise QAPISemError(
-                self.info,
-                "documented member%s '%s' %s not exist"
-                % ("s" if len(bogus) > 1 else "",
-                   "', '".join(bogus),
-                   "do" if len(bogus) > 1 else "does"))
+
+        def check_args_section(args, info, what):
+            bogus = [name for name, section in args.items()
+                     if not section.member]
+            if bogus:
+                raise QAPISemError(
+                    self.info,
+                    "documented member%s '%s' %s not exist"
+                    % ("s" if len(bogus) > 1 else "",
+                       "', '".join(bogus),
+                       "do" if len(bogus) > 1 else "does"))
+
+        check_args_section(self.args, self.info, 'members')
+        check_args_section(self.features, self.info, 'features')

+ 2 - 0
scripts/qapi/schema.py

@@ -56,6 +56,8 @@ def check(self, schema):
         seen = {}
         seen = {}
         for f in self.features:
         for f in self.features:
             f.check_clash(self.info, seen)
             f.check_clash(self.info, seen)
+            if self.doc:
+                self.doc.connect_feature(f)
 
 
         self._checked = True
         self._checked = True
 
 

+ 1 - 0
tests/qapi-schema/doc-bad-feature.err

@@ -0,0 +1 @@
+doc-bad-feature.json:3: documented member 'a' does not exist

+ 0 - 1
tests/qapi-schema/doc-bad-feature.json

@@ -1,5 +1,4 @@
 # Features listed in the doc comment must exist in the actual schema
 # Features listed in the doc comment must exist in the actual schema
-# BUG: nonexistent @a is not rejected
 
 
 ##
 ##
 # @foo:
 # @foo:

+ 0 - 19
tests/qapi-schema/doc-bad-feature.out

@@ -1,19 +0,0 @@
-module None
-object q_empty
-enum QType
-    prefix QTYPE
-    member none
-    member qnull
-    member qnum
-    member qstring
-    member qdict
-    member qlist
-    member qbool
-module doc-bad-feature.json
-command foo None -> None
-    gen=True success_response=True boxed=False oob=False preconfig=False
-doc symbol=foo
-    body=
-
-    feature=a
-a

+ 2 - 0
tests/qapi-schema/doc-undoc-feature.err

@@ -0,0 +1,2 @@
+doc-undoc-feature.json: In command 'foo':
+doc-undoc-feature.json:9: feature 'undoc' lacks documentation

+ 0 - 1
tests/qapi-schema/doc-undoc-feature.json

@@ -1,5 +1,4 @@
 # Doc comment must cover all features
 # Doc comment must cover all features
-# BUG: missing documentation for @undoc not caught
 
 
 ##
 ##
 # @foo:
 # @foo:

+ 0 - 21
tests/qapi-schema/doc-undoc-feature.out

@@ -1,21 +0,0 @@
-module None
-object q_empty
-enum QType
-    prefix QTYPE
-    member none
-    member qnull
-    member qnum
-    member qstring
-    member qdict
-    member qlist
-    member qbool
-module doc-undoc-feature.json
-command foo None -> None
-    gen=True success_response=True boxed=False oob=False preconfig=False
-    feature undoc
-    feature doc
-doc symbol=foo
-    body=
-
-    feature=doc
-documented feature