qapi: Reject section heading in the middle of a doc comment
authorMarkus Armbruster <armbru@redhat.com>
Fri, 16 Feb 2024 14:58:33 +0000 (15:58 +0100)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 26 Feb 2024 09:43:56 +0000 (10:43 +0100)
docs/devel/qapi-code-gen.txt claims "A heading line must be the first
line of the documentation comment block" since commit
55ec69f8b16 (docs/devel/qapi-code-gen.txt: Update to new rST backend
conventions).  Not true, we have code to make it work anywhere in a
free-form doc comment: commit dcdc07a97cb (qapi: Make section headings
start a new doc comment block).

Make it true, for simplicity's sake.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20240216145841.2099240-10-armbru@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
scripts/qapi/parser.py
tests/qapi-schema/doc-good.json
tests/qapi-schema/doc-non-first-section.err [new file with mode: 0644]
tests/qapi-schema/doc-non-first-section.json [new file with mode: 0644]
tests/qapi-schema/doc-non-first-section.out [new file with mode: 0644]

index cc69f4f7703f213f707fa2f09e8055b3ade2a8ee..3aefec1c2b214a2c9bb5129fc7dbd50a57e3c06c 100644 (file)
@@ -440,9 +440,9 @@ class QAPISchemaParser:
                         self,
                         "unexpected '=' markup in definition documentation")
                 if cur_doc.body.text:
-                    cur_doc.end_comment()
-                    docs.append(cur_doc)
-                    cur_doc = QAPIDoc(self, info)
+                    raise QAPIParseError(
+                        self,
+                        "'=' heading must come first in a comment block")
             cur_doc.append(self.val)
             self.accept(False)
 
index 24a84fe6d7a3f0c8a71fcdeb69b5f0d2d578965b..0479d16a011e7774f5e87af4032b98156a0bcb03 100644 (file)
@@ -9,7 +9,9 @@
 
 ##
 # = Section
-#
+##
+
+##
 # == Subsection
 #
 # *with emphasis*
diff --git a/tests/qapi-schema/doc-non-first-section.err b/tests/qapi-schema/doc-non-first-section.err
new file mode 100644 (file)
index 0000000..eeced2b
--- /dev/null
@@ -0,0 +1 @@
+doc-non-first-section.json:5:1: '=' heading must come first in a comment block
diff --git a/tests/qapi-schema/doc-non-first-section.json b/tests/qapi-schema/doc-non-first-section.json
new file mode 100644 (file)
index 0000000..1590876
--- /dev/null
@@ -0,0 +1,6 @@
+# = section must be first line
+
+##
+#
+# = Not first
+##
diff --git a/tests/qapi-schema/doc-non-first-section.out b/tests/qapi-schema/doc-non-first-section.out
new file mode 100644 (file)
index 0000000..e69de29