Commit 3d0c4829 authored by Eric Blake's avatar Eric Blake Committed by Markus Armbruster
Browse files

qapi: Add some union tests



Demonstrate that the qapi generator doesn't deal well with unions
that aren't up to par. Later patches will update the expected
reseults as the generator is made stricter.  A few tests work
as planned, but most show poor or missing error messages.

Of particular note, qapi-code-gen.txt documents 'base' only for
flat unions, but the tests here demonstrate that we currently allow
a 'base' to a simple union, although it is exercised only in the
testsuite.  Later patches will remove this undocumented feature, to
give us more flexibility in adding other future extensions to union
types.  For example, one possible extension is the idea of a
type-safe simple enum, where added fields tie the discriminator to
a user-defined enum type rather than creating an implicit enum from
the names in 'data'.  But adding such safety on top of a simple
enum with a base type could look ambiguous with a flat enum;
besides, the documentation also mentions how any simple union can
be represented by an equivalent flat union.  So it will be simpler
to just outlaw support for something we aren't using.

Signed-off-by: default avatarEric Blake <eblake@redhat.com>
Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
parent cf393590
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -217,10 +217,18 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
	qapi-schema-test.json quoted-structural-chars.json \
	trailing-comma-list.json trailing-comma-object.json \
	unclosed-list.json unclosed-object.json unclosed-string.json \
	duplicate-key.json union-invalid-base.json flat-union-no-base.json \
	flat-union-invalid-discriminator.json \
	duplicate-key.json union-invalid-base.json union-bad-branch.json \
	union-optional-branch.json union-unknown.json union-max.json \
	flat-union-optional-discriminator.json flat-union-no-base.json \
	flat-union-invalid-discriminator.json flat-union-inline.json \
	flat-union-invalid-branch-key.json flat-union-reverse-define.json \
	flat-union-string-discriminator.json \
	flat-union-string-discriminator.json union-base-no-discriminator.json \
	flat-union-bad-discriminator.json flat-union-bad-base.json \
	flat-union-base-star.json flat-union-int-branch.json \
	flat-union-base-union.json flat-union-branch-clash.json \
	alternate-nested.json alternate-unknown.json alternate-clash.json \
	alternate-good.json alternate-base.json alternate-array.json \
	alternate-conflict-string.json alternate-conflict-dict.json \
	include-simple.json include-relpath.json include-format-err.json \
	include-non-file.json include-no-file.json include-before-err.json \
	include-nested-err.json include-self-cycle.json include-cycle.json \
+0 −0

Empty file added.

+1 −0
Original line number Diff line number Diff line
0
+8 −0
Original line number Diff line number Diff line
# FIXME: we should not allow array branches in anonymous unions
# TODO: should we support this?
{ 'type': 'One',
  'data': { 'name': 'str' } }
{ 'union': 'MyUnion',
  'discriminator': {},
  'data': { 'one': 'One',
            'two': [ 'int' ] } }
+4 −0
Original line number Diff line number Diff line
[OrderedDict([('type', 'One'), ('data', OrderedDict([('name', 'str')]))]),
 OrderedDict([('union', 'MyUnion'), ('discriminator', OrderedDict()), ('data', OrderedDict([('one', 'One'), ('two', ['int'])]))])]
[{'enum_name': 'MyUnionKind', 'enum_values': None}]
[OrderedDict([('type', 'One'), ('data', OrderedDict([('name', 'str')]))])]
Loading