diff options
-rw-r--r-- | scripts/qapi.py | 8 | ||||
-rw-r--r-- | tests/Makefile.include | 1 | ||||
-rw-r--r-- | tests/qapi-schema/flat-union-incomplete-branch.err | 1 | ||||
-rw-r--r-- | tests/qapi-schema/flat-union-incomplete-branch.exit | 1 | ||||
-rw-r--r-- | tests/qapi-schema/flat-union-incomplete-branch.json | 9 | ||||
-rw-r--r-- | tests/qapi-schema/flat-union-incomplete-branch.out | 0 |
6 files changed, 20 insertions, 0 deletions
diff --git a/scripts/qapi.py b/scripts/qapi.py index b13ae47899..0635bbb0c3 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -612,6 +612,14 @@ def check_union(expr, expr_info): "enum '%s'" % (key, enum_define["enum_name"])) + # If discriminator is user-defined, ensure all values are covered + if enum_define: + for value in enum_define['enum_values']: + if value not in members.keys(): + raise QAPIExprError(expr_info, + "Union '%s' data missing '%s' branch" + % (name, value)) + def check_alternate(expr, expr_info): name = expr['alternate'] diff --git a/tests/Makefile.include b/tests/Makefile.include index 2010b11b6c..a04c1991bb 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -326,6 +326,7 @@ 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-empty.json +qapi-schema += flat-union-incomplete-branch.json qapi-schema += flat-union-inline.json qapi-schema += flat-union-int-branch.json qapi-schema += flat-union-invalid-branch-key.json diff --git a/tests/qapi-schema/flat-union-incomplete-branch.err b/tests/qapi-schema/flat-union-incomplete-branch.err new file mode 100644 index 0000000000..e826bf0789 --- /dev/null +++ b/tests/qapi-schema/flat-union-incomplete-branch.err @@ -0,0 +1 @@ +tests/qapi-schema/flat-union-incomplete-branch.json:6: Union 'TestUnion' data missing 'value2' branch diff --git a/tests/qapi-schema/flat-union-incomplete-branch.exit b/tests/qapi-schema/flat-union-incomplete-branch.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/flat-union-incomplete-branch.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/flat-union-incomplete-branch.json b/tests/qapi-schema/flat-union-incomplete-branch.json new file mode 100644 index 0000000000..25a411bc83 --- /dev/null +++ b/tests/qapi-schema/flat-union-incomplete-branch.json @@ -0,0 +1,9 @@ +# we require all branches of the union to be covered +{ 'enum': 'TestEnum', + 'data': [ 'value1', 'value2' ] } +{ 'struct': 'TestTypeA', + 'data': { 'string': 'str' } } +{ 'union': 'TestUnion', + 'base': { 'type': 'TestEnum' }, + 'discriminator': 'type', + 'data': { 'value1': 'TestTypeA' } } diff --git a/tests/qapi-schema/flat-union-incomplete-branch.out b/tests/qapi-schema/flat-union-incomplete-branch.out new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/qapi-schema/flat-union-incomplete-branch.out |