tests/qapi-schema: Improve union discriminator coverage
authorMarkus Armbruster <armbru@redhat.com>
Thu, 16 Mar 2023 07:13:20 +0000 (08:13 +0100)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 24 Apr 2023 13:21:39 +0000 (15:21 +0200)
A union's 'discriminator' must name one of the common members.
QAPISchemaVariants.check() looks it up by its c_name(), then checks
the name matches exactly (because c_name() is not injective).

Tests union-base-empty and union-invalid-discriminator both cover the
case where lookup fails.  Repurpose the latter to cover the case where
it succeeds and the name check fails.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20230316071325.492471-10-armbru@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
[Commit message typo fixed]

tests/qapi-schema/union-invalid-discriminator.err
tests/qapi-schema/union-invalid-discriminator.json

index 38efb24b98cf40245a32fdcb374f6c83f7e075cf..6bd774c15634403e73287aa775789e4d333e3580 100644 (file)
@@ -1,2 +1,2 @@
 union-invalid-discriminator.json: In union 'TestUnion':
-union-invalid-discriminator.json:10: discriminator 'enum_wrong' is not a member of 'base'
+union-invalid-discriminator.json:10: discriminator 'type_tag' is not a member of 'base'
index c4fce973621797384d2795f749d48d292062ada9..f315f36e37963bcfabbf8f611b9ee08117663996 100644 (file)
@@ -8,7 +8,7 @@
   'data': { 'integer': 'int' } }
 
 { 'union': 'TestUnion',
-  'base': { 'enum1': 'TestEnum' },
-  'discriminator': 'enum_wrong',
+  'base': { 'type-tag': 'TestEnum' },
+  'discriminator': 'type_tag',
   'data': { 'value1': 'TestTypeA',
             'value2': 'TestTypeB' } }