diff options
author | Eric Blake <eblake@redhat.com> | 2015-05-04 09:05:04 -0600 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2015-05-05 18:39:00 +0200 |
commit | cf3935907b5df16f667d54ad6761c7e937dcf425 (patch) | |
tree | ac11b4cc953cc0d7a605eb589e13128f15cf5803 /tests/qapi-schema | |
parent | ad11dbb93752ffd4bd1d5f31da7e2d9c40a68e8a (diff) |
qapi: Better error messages for bad enums
The previous commit demonstrated that the generator had several
flaws with less-than-perfect enums:
- an enum that listed the same string twice (or two variant
strings that map to the same C enumerator) ended up generating
an invalid C enum
- because the generator adds a _MAX terminator to each enum,
the use of an enum member 'max' can also cause this clash
- if an enum omits 'data', the generator left a python stack
trace rather than a graceful message
- an enum that used a non-array 'data' was silently accepted by
the parser
- an enum that used non-string members in the 'data' member
was silently accepted by the parser
Add check_enum to cover these situations, and update testcases
to match. While valid .json files won't trigger any of these
cases, we might as well be nicer to developers that make a typo
while trying to add new QAPI code.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/qapi-schema')
-rw-r--r-- | tests/qapi-schema/enum-clash-member.err | 1 | ||||
-rw-r--r-- | tests/qapi-schema/enum-clash-member.exit | 2 | ||||
-rw-r--r-- | tests/qapi-schema/enum-clash-member.json | 2 | ||||
-rw-r--r-- | tests/qapi-schema/enum-clash-member.out | 3 | ||||
-rw-r--r-- | tests/qapi-schema/enum-dict-member.err | 1 | ||||
-rw-r--r-- | tests/qapi-schema/enum-dict-member.exit | 2 | ||||
-rw-r--r-- | tests/qapi-schema/enum-dict-member.json | 2 | ||||
-rw-r--r-- | tests/qapi-schema/enum-dict-member.out | 3 | ||||
-rw-r--r-- | tests/qapi-schema/enum-max-member.err | 1 | ||||
-rw-r--r-- | tests/qapi-schema/enum-max-member.exit | 2 | ||||
-rw-r--r-- | tests/qapi-schema/enum-max-member.json | 2 | ||||
-rw-r--r-- | tests/qapi-schema/enum-max-member.out | 3 | ||||
-rw-r--r-- | tests/qapi-schema/enum-missing-data.err | 7 | ||||
-rw-r--r-- | tests/qapi-schema/enum-missing-data.json | 2 | ||||
-rw-r--r-- | tests/qapi-schema/enum-wrong-data.err | 1 | ||||
-rw-r--r-- | tests/qapi-schema/enum-wrong-data.exit | 2 | ||||
-rw-r--r-- | tests/qapi-schema/enum-wrong-data.json | 2 | ||||
-rw-r--r-- | tests/qapi-schema/enum-wrong-data.out | 3 |
18 files changed, 14 insertions, 27 deletions
diff --git a/tests/qapi-schema/enum-clash-member.err b/tests/qapi-schema/enum-clash-member.err index e69de29bb2..48bd1360e7 100644 --- a/tests/qapi-schema/enum-clash-member.err +++ b/tests/qapi-schema/enum-clash-member.err @@ -0,0 +1 @@ +tests/qapi-schema/enum-clash-member.json:2: Enum 'MyEnum' member 'ONE' clashes with 'one' diff --git a/tests/qapi-schema/enum-clash-member.exit b/tests/qapi-schema/enum-clash-member.exit index 573541ac97..d00491fd7e 100644 --- a/tests/qapi-schema/enum-clash-member.exit +++ b/tests/qapi-schema/enum-clash-member.exit @@ -1 +1 @@ -0 +1 diff --git a/tests/qapi-schema/enum-clash-member.json b/tests/qapi-schema/enum-clash-member.json index 99d442a978..b7dc02a28d 100644 --- a/tests/qapi-schema/enum-clash-member.json +++ b/tests/qapi-schema/enum-clash-member.json @@ -1,2 +1,2 @@ -# FIXME: we should reject enums where members will clash when mapped to C enum +# we reject enums where members will clash when mapped to C enum { 'enum': 'MyEnum', 'data': [ 'one', 'ONE' ] } diff --git a/tests/qapi-schema/enum-clash-member.out b/tests/qapi-schema/enum-clash-member.out index 0814459721..e69de29bb2 100644 --- a/tests/qapi-schema/enum-clash-member.out +++ b/tests/qapi-schema/enum-clash-member.out @@ -1,3 +0,0 @@ -[OrderedDict([('enum', 'MyEnum'), ('data', ['one', 'ONE'])])] -[{'enum_name': 'MyEnum', 'enum_values': ['one', 'ONE']}] -[] diff --git a/tests/qapi-schema/enum-dict-member.err b/tests/qapi-schema/enum-dict-member.err index e69de29bb2..7e966a8aae 100644 --- a/tests/qapi-schema/enum-dict-member.err +++ b/tests/qapi-schema/enum-dict-member.err @@ -0,0 +1 @@ +tests/qapi-schema/enum-dict-member.json:2: Enum 'MyEnum' member 'OrderedDict([('value', 'str')])' is not a string diff --git a/tests/qapi-schema/enum-dict-member.exit b/tests/qapi-schema/enum-dict-member.exit index 573541ac97..d00491fd7e 100644 --- a/tests/qapi-schema/enum-dict-member.exit +++ b/tests/qapi-schema/enum-dict-member.exit @@ -1 +1 @@ -0 +1 diff --git a/tests/qapi-schema/enum-dict-member.json b/tests/qapi-schema/enum-dict-member.json index de4d6bf777..79672e0f09 100644 --- a/tests/qapi-schema/enum-dict-member.json +++ b/tests/qapi-schema/enum-dict-member.json @@ -1,2 +1,2 @@ -# FIXME: we should reject any enum member that is not a string +# we reject any enum member that is not a string { 'enum': 'MyEnum', 'data': [ { 'value': 'str' } ] } diff --git a/tests/qapi-schema/enum-dict-member.out b/tests/qapi-schema/enum-dict-member.out index 8b293f85c5..e69de29bb2 100644 --- a/tests/qapi-schema/enum-dict-member.out +++ b/tests/qapi-schema/enum-dict-member.out @@ -1,3 +0,0 @@ -[OrderedDict([('enum', 'MyEnum'), ('data', [OrderedDict([('value', 'str')])])])] -[{'enum_name': 'MyEnum', 'enum_values': [OrderedDict([('value', 'str')])]}] -[] diff --git a/tests/qapi-schema/enum-max-member.err b/tests/qapi-schema/enum-max-member.err index e69de29bb2..f77837fb45 100644 --- a/tests/qapi-schema/enum-max-member.err +++ b/tests/qapi-schema/enum-max-member.err @@ -0,0 +1 @@ +tests/qapi-schema/enum-max-member.json:3: Enum 'MyEnum' member 'max' clashes with '(automatic)' diff --git a/tests/qapi-schema/enum-max-member.exit b/tests/qapi-schema/enum-max-member.exit index 573541ac97..d00491fd7e 100644 --- a/tests/qapi-schema/enum-max-member.exit +++ b/tests/qapi-schema/enum-max-member.exit @@ -1 +1 @@ -0 +1 diff --git a/tests/qapi-schema/enum-max-member.json b/tests/qapi-schema/enum-max-member.json index 1519541344..4bcda0bf07 100644 --- a/tests/qapi-schema/enum-max-member.json +++ b/tests/qapi-schema/enum-max-member.json @@ -1,3 +1,3 @@ -# FIXME: we should reject user-supplied 'max' for clashing with implicit enum end +# we reject user-supplied 'max' for clashing with implicit enum end # TODO: should we instead munge the implicit value to avoid the clash? { 'enum': 'MyEnum', 'data': [ 'max' ] } diff --git a/tests/qapi-schema/enum-max-member.out b/tests/qapi-schema/enum-max-member.out index c933044c69..e69de29bb2 100644 --- a/tests/qapi-schema/enum-max-member.out +++ b/tests/qapi-schema/enum-max-member.out @@ -1,3 +0,0 @@ -[OrderedDict([('enum', 'MyEnum'), ('data', ['max'])])] -[{'enum_name': 'MyEnum', 'enum_values': ['max']}] -[] diff --git a/tests/qapi-schema/enum-missing-data.err b/tests/qapi-schema/enum-missing-data.err index 814ab2613d..b8ccae071b 100644 --- a/tests/qapi-schema/enum-missing-data.err +++ b/tests/qapi-schema/enum-missing-data.err @@ -1,6 +1 @@ -Traceback (most recent call last): - File "tests/qapi-schema/test-qapi.py", line 19, in <module> - exprs = parse_schema(sys.argv[1]) - File "scripts/qapi.py", line 334, in parse_schema - add_enum(expr['enum'], expr['data']) -KeyError: 'data' +tests/qapi-schema/enum-missing-data.json:2: Enum 'MyEnum' requires an array for 'data' diff --git a/tests/qapi-schema/enum-missing-data.json b/tests/qapi-schema/enum-missing-data.json index 01f3f32e70..558fd35e93 100644 --- a/tests/qapi-schema/enum-missing-data.json +++ b/tests/qapi-schema/enum-missing-data.json @@ -1,2 +1,2 @@ -# FIXME: we should require that all QAPI enums have a data array +# we require that all QAPI enums have a data array { 'enum': 'MyEnum' } diff --git a/tests/qapi-schema/enum-wrong-data.err b/tests/qapi-schema/enum-wrong-data.err index e69de29bb2..11b43471cf 100644 --- a/tests/qapi-schema/enum-wrong-data.err +++ b/tests/qapi-schema/enum-wrong-data.err @@ -0,0 +1 @@ +tests/qapi-schema/enum-wrong-data.json:2: Enum 'MyEnum' requires an array for 'data' diff --git a/tests/qapi-schema/enum-wrong-data.exit b/tests/qapi-schema/enum-wrong-data.exit index 573541ac97..d00491fd7e 100644 --- a/tests/qapi-schema/enum-wrong-data.exit +++ b/tests/qapi-schema/enum-wrong-data.exit @@ -1 +1 @@ -0 +1 diff --git a/tests/qapi-schema/enum-wrong-data.json b/tests/qapi-schema/enum-wrong-data.json index 61d25ec427..7b3e255c14 100644 --- a/tests/qapi-schema/enum-wrong-data.json +++ b/tests/qapi-schema/enum-wrong-data.json @@ -1,2 +1,2 @@ -# FIXME: we should require that all qapi enums have an array for data +# we require that all qapi enums have an array for data { 'enum': 'MyEnum', 'data': { 'value': 'str' } } diff --git a/tests/qapi-schema/enum-wrong-data.out b/tests/qapi-schema/enum-wrong-data.out index 28d22116d0..e69de29bb2 100644 --- a/tests/qapi-schema/enum-wrong-data.out +++ b/tests/qapi-schema/enum-wrong-data.out @@ -1,3 +0,0 @@ -[OrderedDict([('enum', 'MyEnum'), ('data', OrderedDict([('value', 'str')]))])] -[{'enum_name': 'MyEnum', 'enum_values': OrderedDict([('value', 'str')])}] -[] |