From cd346bdc46eb2046d7f744135a7e3d740490d166 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 14 Sep 2019 17:34:50 +0200 Subject: tests/qapi-schema: Demonstrate misleading optional tag error Test flat-union-optional-discriminator declares its union tag as '*switch': 'Enum', and points to it with 'discriminator': '*switch'. This gets rejected as "discriminator of flat union 'MyUnion' uses invalid name '*switch'". Correct; member 'discriminator' doesn't accept a '*' prefix. However, this merely tests name validity checking, which we already cover elsewhere. More interesting is testing the valid name 'switch'. This reports "discriminator 'switch' is not a member of base struct 'Base'", which is misleading. Copy the existing 'discriminator': '*switch' test to flat-union-discriminator-bad-name, and rewrite its comment. Change flat-union-optional-discriminator to test 'discriminator': 'switch', and mark it FIXME. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-4-armbru@redhat.com> Reviewed-by: Eric Blake --- tests/Makefile.include | 1 + tests/qapi-schema/flat-union-discriminator-bad-name.err | 1 + tests/qapi-schema/flat-union-discriminator-bad-name.exit | 1 + tests/qapi-schema/flat-union-discriminator-bad-name.json | 11 +++++++++++ tests/qapi-schema/flat-union-discriminator-bad-name.out | 0 tests/qapi-schema/flat-union-optional-discriminator.err | 2 +- tests/qapi-schema/flat-union-optional-discriminator.json | 3 ++- 7 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/qapi-schema/flat-union-discriminator-bad-name.err create mode 100644 tests/qapi-schema/flat-union-discriminator-bad-name.exit create mode 100644 tests/qapi-schema/flat-union-discriminator-bad-name.json create mode 100644 tests/qapi-schema/flat-union-discriminator-bad-name.out diff --git a/tests/Makefile.include b/tests/Makefile.include index 0c862dbc42..7553616069 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -388,6 +388,7 @@ qapi-schema += flat-union-bad-discriminator.json qapi-schema += flat-union-base-any.json qapi-schema += flat-union-base-union.json qapi-schema += flat-union-clash-member.json +qapi-schema += flat-union-discriminator-bad-name.json qapi-schema += flat-union-empty.json qapi-schema += flat-union-inline.json qapi-schema += flat-union-inline-invalid-dict.json diff --git a/tests/qapi-schema/flat-union-discriminator-bad-name.err b/tests/qapi-schema/flat-union-discriminator-bad-name.err new file mode 100644 index 0000000000..7238d126ca --- /dev/null +++ b/tests/qapi-schema/flat-union-discriminator-bad-name.err @@ -0,0 +1 @@ +tests/qapi-schema/flat-union-discriminator-bad-name.json:7: Discriminator of flat union 'MyUnion' does not allow optional name '*switch' diff --git a/tests/qapi-schema/flat-union-discriminator-bad-name.exit b/tests/qapi-schema/flat-union-discriminator-bad-name.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/flat-union-discriminator-bad-name.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/flat-union-discriminator-bad-name.json b/tests/qapi-schema/flat-union-discriminator-bad-name.json new file mode 100644 index 0000000000..66376084fc --- /dev/null +++ b/tests/qapi-schema/flat-union-discriminator-bad-name.json @@ -0,0 +1,11 @@ +# discriminator '*switch' isn't a member of base, 'switch' is +# reports "does not allow optional name", which is good enough +{ 'enum': 'Enum', 'data': [ 'one', 'two' ] } +{ 'struct': 'Base', + 'data': { '*switch': 'Enum' } } +{ 'struct': 'Branch', 'data': { 'name': 'str' } } +{ 'union': 'MyUnion', + 'base': 'Base', + 'discriminator': '*switch', + 'data': { 'one': 'Branch', + 'two': 'Branch' } } diff --git a/tests/qapi-schema/flat-union-discriminator-bad-name.out b/tests/qapi-schema/flat-union-discriminator-bad-name.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/flat-union-optional-discriminator.err b/tests/qapi-schema/flat-union-optional-discriminator.err index aaabedb3bd..8b4a4ba847 100644 --- a/tests/qapi-schema/flat-union-optional-discriminator.err +++ b/tests/qapi-schema/flat-union-optional-discriminator.err @@ -1 +1 @@ -tests/qapi-schema/flat-union-optional-discriminator.json:6: Discriminator of flat union 'MyUnion' does not allow optional name '*switch' +tests/qapi-schema/flat-union-optional-discriminator.json:7: Discriminator 'switch' is not a member of base struct 'Base' diff --git a/tests/qapi-schema/flat-union-optional-discriminator.json b/tests/qapi-schema/flat-union-optional-discriminator.json index 08a8f7ef8b..143ab23a0d 100644 --- a/tests/qapi-schema/flat-union-optional-discriminator.json +++ b/tests/qapi-schema/flat-union-optional-discriminator.json @@ -1,10 +1,11 @@ # we require the discriminator to be non-optional +# FIXME reports "discriminator 'switch' is not a member of base struct 'Base'" { 'enum': 'Enum', 'data': [ 'one', 'two' ] } { 'struct': 'Base', 'data': { '*switch': 'Enum' } } { 'struct': 'Branch', 'data': { 'name': 'str' } } { 'union': 'MyUnion', 'base': 'Base', - 'discriminator': '*switch', + 'discriminator': 'switch', 'data': { 'one': 'Branch', 'two': 'Branch' } } -- cgit v1.2.3