Skip to content

Commit

Permalink
qapi: Check feature documentation against the schema
Browse files Browse the repository at this point in the history
Commit f3ed93d "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 <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
Markus Armbruster committed Oct 29, 2019
1 parent e4def78 commit e151941
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 51 deletions.
31 changes: 22 additions & 9 deletions scripts/qapi/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,18 +555,31 @@ def connect_member(self, member):
self.args[member.name] = QAPIDoc.ArgSection(member.name)
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):
if self.has_section('Returns') and 'command' not in expr:
raise QAPISemError(self.info,
"'Returns:' is only valid for commands")

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 changes: 2 additions & 0 deletions scripts/qapi/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def check(self, schema):
seen = {}
for f in self.features:
f.check_clash(self.info, seen)
if self.doc:
self.doc.connect_feature(f)

self._checked = True

Expand Down
1 change: 1 addition & 0 deletions tests/qapi-schema/doc-bad-feature.err
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc-bad-feature.json:3: documented member 'a' does not exist
1 change: 0 additions & 1 deletion tests/qapi-schema/doc-bad-feature.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Features listed in the doc comment must exist in the actual schema
# BUG: nonexistent @a is not rejected

##
# @foo:
Expand Down
19 changes: 0 additions & 19 deletions tests/qapi-schema/doc-bad-feature.out
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions tests/qapi-schema/doc-undoc-feature.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
doc-undoc-feature.json: In command 'foo':
doc-undoc-feature.json:9: feature 'undoc' lacks documentation
1 change: 0 additions & 1 deletion tests/qapi-schema/doc-undoc-feature.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Doc comment must cover all features
# BUG: missing documentation for @undoc not caught

##
# @foo:
Expand Down
21 changes: 0 additions & 21 deletions tests/qapi-schema/doc-undoc-feature.out
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e151941

Please sign in to comment.