qapi: Better error messages for bad enums
commitcf3935907b5df16f667d54ad6761c7e937dcf425
authorEric Blake <eblake@redhat.com>
Mon, 4 May 2015 15:05:04 +0000 (4 09:05 -0600)
committerMarkus Armbruster <armbru@redhat.com>
Tue, 5 May 2015 16:39:00 +0000 (5 18:39 +0200)
treeac11b4cc953cc0d7a605eb589e13128f15cf5803
parentad11dbb93752ffd4bd1d5f31da7e2d9c40a68e8a
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>
19 files changed:
scripts/qapi.py
tests/qapi-schema/enum-clash-member.err
tests/qapi-schema/enum-clash-member.exit
tests/qapi-schema/enum-clash-member.json
tests/qapi-schema/enum-clash-member.out
tests/qapi-schema/enum-dict-member.err
tests/qapi-schema/enum-dict-member.exit
tests/qapi-schema/enum-dict-member.json
tests/qapi-schema/enum-dict-member.out
tests/qapi-schema/enum-max-member.err
tests/qapi-schema/enum-max-member.exit
tests/qapi-schema/enum-max-member.json
tests/qapi-schema/enum-max-member.out
tests/qapi-schema/enum-missing-data.err
tests/qapi-schema/enum-missing-data.json
tests/qapi-schema/enum-wrong-data.err
tests/qapi-schema/enum-wrong-data.exit
tests/qapi-schema/enum-wrong-data.json
tests/qapi-schema/enum-wrong-data.out