Wenchao Xia <xiaw...@linux.vnet.ibm.com> writes: > δΊ 2014/2/13 23:14, Markus Armbruster ει: >> Wenchao Xia <xiaw...@linux.vnet.ibm.com> writes: >> >>> It is bad that same key was specified twice, especially when a union have >>> two branches with same condition. This patch can prevent it. >>> >>> Signed-off-by: Wenchao Xia <xiaw...@linux.vnet.ibm.com> >>> Reviewed-by: Eric Blake <ebl...@redhat.com> >>> --- >>> 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 != ':': >>> raise QAPISchemaError(self, 'Expected ":"') >>> self.accept() >>> + if key in expr: >>> + raise QAPISchemaError(self, 'Duplicated key "%s"' % key) >>> expr[key] = self.get_expr(True) >>> if self.tok == '}': >>> self.accept() >> >> All errors should have a test in tests/qapi-schema/. I can try to add >> tests for you when I rebase your 09/10. >> > 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 <arm...@redhat.com> 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 <arm...@redhat.com> --- 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] = self.get_expr(True) if self.tok == '}': 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 += tests/qom-test$(EXESUF) check-qtest-xtensaeb-y = $(check-qtest-xtensa-y) check-qapi-schema-y := $(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/duplicate-key.err new file mode 100644 index 0000000..0801c6a --- /dev/null +++ b/tests/qapi-schema/duplicate-key.err @@ -0,0 +1 @@ +<stdin>:2:10: Duplicate key "key" diff --git a/tests/qapi-schema/duplicate-key.exit b/tests/qapi-schema/duplicate-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/duplicate-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/duplicate-key.out new file mode 100644 index 0000000..e69de29 -- 1.8.1.4