From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFJZA-000116-TL for qemu-devel@nongnu.org; Mon, 17 Feb 2014 03:28:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WFJZ5-0008HB-Gj for qemu-devel@nongnu.org; Mon, 17 Feb 2014 03:28:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40326) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFJZ5-0008H5-7q for qemu-devel@nongnu.org; Mon, 17 Feb 2014 03:28:35 -0500 From: Markus Armbruster References: <1392068921-3327-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1392068921-3327-3-git-send-email-xiawenc@linux.vnet.ibm.com> <87y51fujrp.fsf@blackfin.pond.sub.org> <52FD7667.3070309@linux.vnet.ibm.com> Date: Mon, 17 Feb 2014 09:28:30 +0100 In-Reply-To: <52FD7667.3070309@linux.vnet.ibm.com> (Wenchao Xia's message of "Fri, 14 Feb 2014 09:50:31 +0800") Message-ID: <878uta2le9.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH V6 02/10] qapi script: add check for duplicated key List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenchao Xia Cc: kwolf@redhat.com, mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org, lcapitulino@redhat.com Wenchao Xia writes: > =E4=BA=8E 2014/2/13 23:14, Markus Armbruster =E5=86=99=E9=81=93: >> Wenchao Xia writes: >>=20 >>> It is bad that same key was specified twice, especially when a union ha= ve >>> two branches with same condition. This patch can prevent it. >>> >>> Signed-off-by: Wenchao Xia >>> Reviewed-by: Eric Blake >>> --- >>> scripts/qapi.py | 2 ++ >>> 1 files changed, 2 insertions(+), 0 deletions(-) >>> >>> diff --git a/scripts/qapi.py b/scripts/qapi.py >>> index aec6bbb..cf34768 100644 >>> --- a/scripts/qapi.py >>> +++ b/scripts/qapi.py >>> @@ -116,6 +116,8 @@ class QAPISchema: >>> if self.tok !=3D ':': >>> raise QAPISchemaError(self, 'Expected ":"') >>> self.accept() >>> + if key in expr: >>> + raise QAPISchemaError(self, 'Duplicated key "%s"' % ke= y) >>> expr[key] =3D self.get_expr(True) >>> if self.tok =3D=3D '}': >>> self.accept() >>=20 >> All errors should have a test in tests/qapi-schema/. I can try to add >> tests for you when I rebase your 09/10. >>=20 > I considered error path test before but didn't find a good place to > go. It would be great if you can add one. Here's the test for your commit, feel free to squash it into yours. >>From ce842b83cd999ee76e4221e24313a5c447e40bac Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 14 Feb 2014 13:15:46 +0100 Subject: [PATCH] qapi: Polish error message for duplicate key, and add test Signed-off-by: Markus Armbruster --- scripts/qapi.py | 2 +- tests/Makefile | 4 ++-- tests/qapi-schema/duplicate-key.err | 1 + tests/qapi-schema/duplicate-key.exit | 1 + tests/qapi-schema/duplicate-key.json | 2 ++ tests/qapi-schema/duplicate-key.out | 0 6 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 tests/qapi-schema/duplicate-key.err create mode 100644 tests/qapi-schema/duplicate-key.exit create mode 100644 tests/qapi-schema/duplicate-key.json create mode 100644 tests/qapi-schema/duplicate-key.out diff --git a/scripts/qapi.py b/scripts/qapi.py index 0663c2e..3732fe1 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -117,7 +117,7 @@ class QAPISchema: raise QAPISchemaError(self, 'Expected ":"') self.accept() if key in expr: - raise QAPISchemaError(self, 'Duplicated key "%s"' % key) + raise QAPISchemaError(self, 'Duplicate key "%s"' % key) expr[key] =3D self.get_expr(True) if self.tok =3D=3D '}': self.accept() diff --git a/tests/Makefile b/tests/Makefile index fd36eee..e3ddbcc 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -119,8 +119,8 @@ check-qtest-xtensa-y +=3D tests/qom-test$(EXESUF) check-qtest-xtensaeb-y =3D $(check-qtest-xtensa-y) =20 check-qapi-schema-y :=3D $(addprefix tests/qapi-schema/, \ - comments.json empty.json funny-char.json indented-expr.json \ - missing-colon.json missing-comma-list.json \ + comments.json duplicate-key.json empty.json funny-char.json \ + indented-expr.json missing-colon.json missing-comma-list.json \ missing-comma-object.json non-objects.json \ qapi-schema-test.json quoted-structural-chars.json \ trailing-comma-list.json trailing-comma-object.json \ diff --git a/tests/qapi-schema/duplicate-key.err b/tests/qapi-schema/duplic= ate-key.err new file mode 100644 index 0000000..0801c6a --- /dev/null +++ b/tests/qapi-schema/duplicate-key.err @@ -0,0 +1 @@ +:2:10: Duplicate key "key" diff --git a/tests/qapi-schema/duplicate-key.exit b/tests/qapi-schema/dupli= cate-key.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/qapi-schema/duplicate-key.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/duplicate-key.json b/tests/qapi-schema/dupli= cate-key.json new file mode 100644 index 0000000..1b55d88 --- /dev/null +++ b/tests/qapi-schema/duplicate-key.json @@ -0,0 +1,2 @@ +{ 'key': 'value', + 'key': 'value' } diff --git a/tests/qapi-schema/duplicate-key.out b/tests/qapi-schema/duplic= ate-key.out new file mode 100644 index 0000000..e69de29 --=20 1.8.1.4