From 4cfd6537e42b108441852b34fc15933fc66628a1 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 17 Sep 2021 16:31:12 +0200 Subject: qapi: Tidy up unusual line breaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Break lines between members instead of within members. Signed-off-by: Markus Armbruster Reviewed-by: Marc-André Lureau Message-Id: <20210917143134.412106-2-armbru@redhat.com> --- tests/qapi-schema/doc-good.json | 4 ++-- tests/qapi-schema/enum-if-invalid.json | 4 ++-- tests/qapi-schema/qapi-schema-test.json | 28 ++++++++++++++-------------- 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'tests/qapi-schema') diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.json index e0027e4..cbf5c56 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -60,8 +60,8 @@ # # @two is undocumented ## -{ 'enum': 'Enum', 'data': - [ { 'name': 'one', 'if': 'IFONE' }, 'two' ], +{ 'enum': 'Enum', + 'data': [ { 'name': 'one', 'if': 'IFONE' }, 'two' ], 'features': [ 'enum-feat' ], 'if': 'IFCOND' } diff --git a/tests/qapi-schema/enum-if-invalid.json b/tests/qapi-schema/enum-if-invalid.json index 60bd0ef..6bd2004 100644 --- a/tests/qapi-schema/enum-if-invalid.json +++ b/tests/qapi-schema/enum-if-invalid.json @@ -1,3 +1,3 @@ # check invalid 'if' type -{ 'enum': 'TestIfEnum', 'data': - [ 'foo', { 'name' : 'bar', 'if': { 'val': 'foo' } } ] } +{ 'enum': 'TestIfEnum', + 'data': [ 'foo', { 'name' : 'bar', 'if': { 'val': 'foo' } } ] } diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json index b6c36a9..3c43e14 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -220,27 +220,27 @@ # test 'if' condition handling -{ 'struct': 'TestIfStruct', 'data': - { 'foo': 'int', - 'bar': { 'type': 'int', 'if': 'TEST_IF_STRUCT_BAR'} }, +{ 'struct': 'TestIfStruct', + 'data': { 'foo': 'int', + 'bar': { 'type': 'int', 'if': 'TEST_IF_STRUCT_BAR'} }, 'if': 'TEST_IF_STRUCT' } -{ 'enum': 'TestIfEnum', 'data': - [ 'foo', { 'name' : 'bar', 'if': 'TEST_IF_ENUM_BAR' } ], +{ 'enum': 'TestIfEnum', + 'data': [ 'foo', { 'name' : 'bar', 'if': 'TEST_IF_ENUM_BAR' } ], 'if': 'TEST_IF_ENUM' } -{ 'union': 'TestIfUnion', 'data': - { 'foo': 'TestStruct', - 'bar': { 'type': 'str', 'if': 'TEST_IF_UNION_BAR'} }, +{ 'union': 'TestIfUnion', + 'data': { 'foo': 'TestStruct', + 'bar': { 'type': 'str', 'if': 'TEST_IF_UNION_BAR'} }, 'if': { 'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } } { 'command': 'test-if-union-cmd', 'data': { 'union-cmd-arg': 'TestIfUnion' }, 'if': { 'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } } -{ 'alternate': 'TestIfAlternate', 'data': - { 'foo': 'int', - 'bar': { 'type': 'TestStruct', 'if': 'TEST_IF_ALT_BAR'} }, +{ 'alternate': 'TestIfAlternate', + 'data': { 'foo': 'int', + 'bar': { 'type': 'TestStruct', 'if': 'TEST_IF_ALT_BAR'} }, 'if': { 'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT'] } } { 'command': 'test-if-alternate-cmd', @@ -256,9 +256,9 @@ { 'command': 'test-cmd-return-def-three', 'returns': 'UserDefThree' } -{ 'event': 'TEST_IF_EVENT', 'data': - { 'foo': 'TestIfStruct', - 'bar': { 'type': ['TestIfEnum'], 'if': 'TEST_IF_EVT_BAR' } }, +{ 'event': 'TEST_IF_EVENT', + 'data': { 'foo': 'TestIfStruct', + 'bar': { 'type': ['TestIfEnum'], 'if': 'TEST_IF_EVT_BAR' } }, 'if': { 'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT'] } } { 'event': 'TEST_IF_EVENT2', 'data': {}, -- cgit v1.1 From 8ebc3120e161424911ba6d8725e77da32fbb25e5 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 17 Sep 2021 16:31:13 +0200 Subject: qapi: Stop enforcing "type name should not end in 'Kind' I'm about to convert simple unions to flat unions, then drop simple union support. The conversion involves making the implict enum types explicit. To reduce churn, I'd like to name them exactly like the implicit types they replace. However, these names are reserved for the generator's use. They won't be once simple unions are gone. Stop enforcing this naming rule now rather than then. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20210917143134.412106-3-armbru@redhat.com> --- tests/qapi-schema/meson.build | 1 - tests/qapi-schema/reserved-type-kind.err | 2 -- tests/qapi-schema/reserved-type-kind.json | 2 -- tests/qapi-schema/reserved-type-kind.out | 0 4 files changed, 5 deletions(-) delete mode 100644 tests/qapi-schema/reserved-type-kind.err delete mode 100644 tests/qapi-schema/reserved-type-kind.json delete mode 100644 tests/qapi-schema/reserved-type-kind.out (limited to 'tests/qapi-schema') diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index 6b2a4ce..0798e94 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -168,7 +168,6 @@ schemas = [ 'reserved-member-q.json', 'reserved-member-u.json', 'reserved-member-underscore.json', - 'reserved-type-kind.json', 'reserved-type-list.json', 'returns-alternate.json', 'returns-array-bad.json', diff --git a/tests/qapi-schema/reserved-type-kind.err b/tests/qapi-schema/reserved-type-kind.err deleted file mode 100644 index d8fb769..0000000 --- a/tests/qapi-schema/reserved-type-kind.err +++ /dev/null @@ -1,2 +0,0 @@ -reserved-type-kind.json: In enum 'UnionKind': -reserved-type-kind.json:2: enum name should not end in 'Kind' diff --git a/tests/qapi-schema/reserved-type-kind.json b/tests/qapi-schema/reserved-type-kind.json deleted file mode 100644 index 9ecaba1..0000000 --- a/tests/qapi-schema/reserved-type-kind.json +++ /dev/null @@ -1,2 +0,0 @@ -# we reject types that would conflict with implicit union enum -{ 'enum': 'UnionKind', 'data': [ 'oops' ] } diff --git a/tests/qapi-schema/reserved-type-kind.out b/tests/qapi-schema/reserved-type-kind.out deleted file mode 100644 index e69de29..0000000 -- cgit v1.1 From dffd8ff9e6ab7efff941966ecc5d0b9a65f61e51 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 17 Sep 2021 16:31:22 +0200 Subject: tests/qapi-schema: Prepare for simple union UserDefListUnion removal Simple unions predate flat unions. Having both complicates the QAPI schema language and the QAPI generator. We haven't been using simple unions in new code for a long time, because they are less flexible and somewhat awkward on the wire. To prepare for their removal, simple union UserDefListUnion has to go. It is used to cover arrays. The next few commits will eliminate its uses, and then it gets deleted. As a first step, provide struct ArrayStruct for the tests to be rewritten. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20210917143134.412106-12-armbru@redhat.com> --- tests/qapi-schema/qapi-schema-test.json | 16 ++++++++++++++++ tests/qapi-schema/qapi-schema-test.out | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'tests/qapi-schema') diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json index 3c43e14..b2d795c 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -140,6 +140,22 @@ 'sizes': ['size'], 'any': ['any'], 'user': ['Status'] } } # intentional forward ref. to sub-module +{ 'struct': 'ArrayStruct', + 'data': { 'integer': ['int'], + 's8': ['int8'], + 's16': ['int16'], + 's32': ['int32'], + 's64': ['int64'], + 'u8': ['uint8'], + 'u16': ['uint16'], + 'u32': ['uint32'], + 'u64': ['uint64'], + 'number': ['number'], + 'boolean': ['bool'], + 'string': ['str'], + '*sz': ['size'], + '*any': ['any'], + '*user': ['Status'] } } # intentional forward ref. to sub-module # for testing sub-modules { 'include': 'include/sub-module.json' } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out index d557fe2..7a488c1 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -189,6 +189,22 @@ object UserDefListUnion case sizes: q_obj_sizeList-wrapper case any: q_obj_anyList-wrapper case user: q_obj_StatusList-wrapper +object ArrayStruct + member integer: intList optional=False + member s8: int8List optional=False + member s16: int16List optional=False + member s32: int32List optional=False + member s64: int64List optional=False + member u8: uint8List optional=False + member u16: uint16List optional=False + member u32: uint32List optional=False + member u64: uint64List optional=False + member number: numberList optional=False + member boolean: boolList optional=False + member string: strList optional=False + member sz: sizeList optional=True + member any: anyList optional=True + member user: StatusList optional=True include include/sub-module.json command user-def-cmd None -> None gen=True success_response=True boxed=False oob=False preconfig=False -- cgit v1.1 From 1e65e16ca3c7a41d15c8b80f922d68fabc0b96b8 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 17 Sep 2021 16:31:26 +0200 Subject: tests/qapi-schema: Wean off UserDefListUnion Command boxed-union uses simple union UserDefListUnion to cover unions. Use UserDefFlatUnion instead. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20210917143134.412106-16-armbru@redhat.com> --- tests/qapi-schema/qapi-schema-test.json | 2 +- tests/qapi-schema/qapi-schema-test.out | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/qapi-schema') diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json index b2d795c..a4b4405 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -175,7 +175,7 @@ 'returns': 'int' } { 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' } { 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' } -{ 'command': 'boxed-union', 'data': 'UserDefListUnion', 'boxed': true } +{ 'command': 'boxed-union', 'data': 'UserDefFlatUnion', 'boxed': true } { 'command': 'boxed-empty', 'boxed': true, 'data': 'Empty1' } # Smoke test on out-of-band and allow-preconfig-test diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out index 7a488c1..f120f10 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -232,7 +232,7 @@ command guest-sync q_obj_guest-sync-arg -> any gen=True success_response=True boxed=False oob=False preconfig=False command boxed-struct UserDefZero -> None gen=True success_response=True boxed=True oob=False preconfig=False -command boxed-union UserDefListUnion -> None +command boxed-union UserDefFlatUnion -> None gen=True success_response=True boxed=True oob=False preconfig=False command boxed-empty Empty1 -> None gen=True success_response=True boxed=True oob=False preconfig=False -- cgit v1.1 From def1d1f57188b6e5523042f3a6ae2ab61065d075 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 17 Sep 2021 16:31:27 +0200 Subject: tests/qapi-schema: Simple union UserDefListUnion is now unused, drop Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20210917143134.412106-17-armbru@redhat.com> --- tests/qapi-schema/qapi-schema-test.json | 17 --------- tests/qapi-schema/qapi-schema-test.out | 64 --------------------------------- 2 files changed, 81 deletions(-) (limited to 'tests/qapi-schema') diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json index a4b4405..eae43f4 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -123,23 +123,6 @@ # for testing use of 'str' within alternates { 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } } -# for testing lists -{ 'union': 'UserDefListUnion', - 'data': { 'integer': ['int'], - 's8': ['int8'], - 's16': ['int16'], - 's32': ['int32'], - 's64': ['int64'], - 'u8': ['uint8'], - 'u16': ['uint16'], - 'u32': ['uint32'], - 'u64': ['uint64'], - 'number': ['number'], - 'boolean': ['bool'], - 'string': ['str'], - 'sizes': ['size'], - 'any': ['any'], - 'user': ['Status'] } } # intentional forward ref. to sub-module { 'struct': 'ArrayStruct', 'data': { 'integer': ['int'], 's8': ['int8'], diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out index f120f10..e43073d 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -125,70 +125,6 @@ alternate AltStrObj tag type case s: str case o: TestStruct -object q_obj_intList-wrapper - member data: intList optional=False -object q_obj_int8List-wrapper - member data: int8List optional=False -object q_obj_int16List-wrapper - member data: int16List optional=False -object q_obj_int32List-wrapper - member data: int32List optional=False -object q_obj_int64List-wrapper - member data: int64List optional=False -object q_obj_uint8List-wrapper - member data: uint8List optional=False -object q_obj_uint16List-wrapper - member data: uint16List optional=False -object q_obj_uint32List-wrapper - member data: uint32List optional=False -object q_obj_uint64List-wrapper - member data: uint64List optional=False -object q_obj_numberList-wrapper - member data: numberList optional=False -object q_obj_boolList-wrapper - member data: boolList optional=False -object q_obj_strList-wrapper - member data: strList optional=False -object q_obj_sizeList-wrapper - member data: sizeList optional=False -object q_obj_anyList-wrapper - member data: anyList optional=False -object q_obj_StatusList-wrapper - member data: StatusList optional=False -enum UserDefListUnionKind - member integer - member s8 - member s16 - member s32 - member s64 - member u8 - member u16 - member u32 - member u64 - member number - member boolean - member string - member sizes - member any - member user -object UserDefListUnion - member type: UserDefListUnionKind optional=False - tag type - case integer: q_obj_intList-wrapper - case s8: q_obj_int8List-wrapper - case s16: q_obj_int16List-wrapper - case s32: q_obj_int32List-wrapper - case s64: q_obj_int64List-wrapper - case u8: q_obj_uint8List-wrapper - case u16: q_obj_uint16List-wrapper - case u32: q_obj_uint32List-wrapper - case u64: q_obj_uint64List-wrapper - case number: q_obj_numberList-wrapper - case boolean: q_obj_boolList-wrapper - case string: q_obj_strList-wrapper - case sizes: q_obj_sizeList-wrapper - case any: q_obj_anyList-wrapper - case user: q_obj_StatusList-wrapper object ArrayStruct member integer: intList optional=False member s8: int8List optional=False -- cgit v1.1 From 54501863376eff16973648523afeed76d4d28106 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 17 Sep 2021 16:31:28 +0200 Subject: tests/qapi-schema: Rewrite simple union TestIfUnion to be flat Simple unions predate flat unions. Having both complicates the QAPI schema language and the QAPI generator. We haven't been using simple unions in new code for a long time, because they are less flexible and somewhat awkward on the wire. To prepare for their removal, rewrite TestIfUnion to be flat. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20210917143134.412106-18-armbru@redhat.com> --- tests/qapi-schema/qapi-schema-test.json | 4 +++- tests/qapi-schema/qapi-schema-test.out | 16 ++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'tests/qapi-schema') diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json index eae43f4..ef17ab1 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -229,8 +229,10 @@ 'if': 'TEST_IF_ENUM' } { 'union': 'TestIfUnion', + 'base': { 'type': 'TestIfEnum' }, + 'discriminator': 'type', 'data': { 'foo': 'TestStruct', - 'bar': { 'type': 'str', 'if': 'TEST_IF_UNION_BAR'} }, + 'bar': { 'type': 'UserDefZero', 'if': 'TEST_IF_ENUM_BAR'} }, 'if': { 'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } } { 'command': 'test-if-union-cmd', diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out index e43073d..07e4161 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -257,19 +257,15 @@ enum TestIfEnum member bar if TEST_IF_ENUM_BAR if TEST_IF_ENUM -object q_obj_TestStruct-wrapper - member data: TestStruct optional=False -enum TestIfUnionKind - member foo - member bar - if TEST_IF_UNION_BAR +object q_obj_TestIfUnion-base + member type: TestIfEnum optional=False if {'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT']} object TestIfUnion - member type: TestIfUnionKind optional=False + base q_obj_TestIfUnion-base tag type - case foo: q_obj_TestStruct-wrapper - case bar: q_obj_str-wrapper - if TEST_IF_UNION_BAR + case foo: TestStruct + case bar: UserDefZero + if TEST_IF_ENUM_BAR if {'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT']} object q_obj_test-if-union-cmd-arg member union-cmd-arg: TestIfUnion optional=False -- cgit v1.1 From bb5821dd8194ed8b50f36a45ecffeac87045937d Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 17 Sep 2021 16:31:30 +0200 Subject: tests/qapi-schema: Drop simple union __org.qemu_x-Union1 Replace simple union __org.qemu_x-Union1 with flat union __org.qemu_x-Union2, except drop it from __org.qemu_x-command, because there it's only used to pull it into QMP. Now drop the unused -Union1, and rename -Union2 to -Union. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20210917143134.412106-20-armbru@redhat.com> --- tests/qapi-schema/qapi-schema-test.json | 8 +++----- tests/qapi-schema/qapi-schema-test.out | 18 +++++------------- 2 files changed, 8 insertions(+), 18 deletions(-) (limited to 'tests/qapi-schema') diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json index ef17ab1..20f4cc0 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -202,11 +202,10 @@ 'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } } { 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base', 'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } } -{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } } { 'alternate': '__org.qemu_x-Alt1', 'data': { '__org.qemu_x-branch': 'str' } } { 'struct': '__org.qemu_x-Struct2', - 'data': { 'array': ['__org.qemu_x-Union1'] } } -{ 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base', + 'data': { 'array': ['__org.qemu_x-Union'] } } +{ 'union': '__org.qemu_x-Union', 'base': '__org.qemu_x-Base', 'discriminator': '__org.qemu_x-member1', 'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } } { 'alternate': '__org.qemu_x-Alt', @@ -214,8 +213,7 @@ { 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' } { 'command': '__org.qemu_x-command', 'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'], - 'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' }, - 'returns': '__org.qemu_x-Union1' } + 'c': '__org.qemu_x-Union', 'd': '__org.qemu_x-Alt' } } # test 'if' condition handling diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out index 07e4161..9337adc 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -215,21 +215,13 @@ object __org.qemu_x-Struct base __org.qemu_x-Base member __org.qemu_x-member2: str optional=False member wchar-t: int optional=True -object q_obj_str-wrapper - member data: str optional=False -enum __org.qemu_x-Union1Kind - member __org.qemu_x-branch -object __org.qemu_x-Union1 - member type: __org.qemu_x-Union1Kind optional=False - tag type - case __org.qemu_x-branch: q_obj_str-wrapper alternate __org.qemu_x-Alt1 tag type case __org.qemu_x-branch: str -array __org.qemu_x-Union1List __org.qemu_x-Union1 +array __org.qemu_x-UnionList __org.qemu_x-Union object __org.qemu_x-Struct2 - member array: __org.qemu_x-Union1List optional=False -object __org.qemu_x-Union2 + member array: __org.qemu_x-UnionList optional=False +object __org.qemu_x-Union base __org.qemu_x-Base tag __org.qemu_x-member1 case __org.qemu_x-value: __org.qemu_x-Struct2 @@ -243,9 +235,9 @@ array __org.qemu_x-StructList __org.qemu_x-Struct object q_obj___org.qemu_x-command-arg member a: __org.qemu_x-EnumList optional=False member b: __org.qemu_x-StructList optional=False - member c: __org.qemu_x-Union2 optional=False + member c: __org.qemu_x-Union optional=False member d: __org.qemu_x-Alt optional=False -command __org.qemu_x-command q_obj___org.qemu_x-command-arg -> __org.qemu_x-Union1 +command __org.qemu_x-command q_obj___org.qemu_x-command-arg -> None gen=True success_response=True boxed=False oob=False preconfig=False object TestIfStruct member foo: int optional=False -- cgit v1.1 From 76432d988b67d95006d0aa66dce2aa5999868d29 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 17 Sep 2021 16:31:31 +0200 Subject: tests/qapi-schema: Purge simple unions from tests Drop tests that are specifically about simple unions: * SugaredUnion in doc-good: flat unions are covered by @Object. * union-branch-case and union-clash-branches: branch naming for flat unions is enforced for the tag enum instead, which is covered by enum-member-case and enum-clash-member. * union-empty: empty flat unions are covered by flat-union-empty. Rewrite the remainder to use flat unions: args-union, bad-base, flat-union-base-union, union-branch-invalid-dict, union-unknown. Except drop union-optional-branch. because converting this one is not worth the trouble; we don't explicitly check names beginning with '*' in other places, either. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20210917143134.412106-21-armbru@redhat.com> --- tests/qapi-schema/args-union.err | 2 +- tests/qapi-schema/args-union.json | 8 +++++++- tests/qapi-schema/bad-base.err | 2 +- tests/qapi-schema/bad-base.json | 8 +++++++- tests/qapi-schema/doc-good.json | 9 --------- tests/qapi-schema/doc-good.out | 22 ---------------------- tests/qapi-schema/doc-good.txt | 20 -------------------- tests/qapi-schema/flat-union-base-union.err | 2 +- tests/qapi-schema/flat-union-base-union.json | 3 +++ tests/qapi-schema/meson.build | 4 ---- tests/qapi-schema/union-branch-case.err | 2 -- tests/qapi-schema/union-branch-case.json | 2 -- tests/qapi-schema/union-branch-case.out | 0 tests/qapi-schema/union-branch-invalid-dict.err | 2 +- tests/qapi-schema/union-branch-invalid-dict.json | 4 ++++ tests/qapi-schema/union-clash-branches.err | 2 -- tests/qapi-schema/union-clash-branches.json | 7 ------- tests/qapi-schema/union-clash-branches.out | 0 tests/qapi-schema/union-empty.err | 2 -- tests/qapi-schema/union-empty.json | 2 -- tests/qapi-schema/union-empty.out | 0 tests/qapi-schema/union-optional-branch.err | 2 -- tests/qapi-schema/union-optional-branch.json | 2 -- tests/qapi-schema/union-optional-branch.out | 0 tests/qapi-schema/union-unknown.err | 2 +- tests/qapi-schema/union-unknown.json | 5 ++++- 26 files changed, 30 insertions(+), 84 deletions(-) delete mode 100644 tests/qapi-schema/union-branch-case.err delete mode 100644 tests/qapi-schema/union-branch-case.json delete mode 100644 tests/qapi-schema/union-branch-case.out delete mode 100644 tests/qapi-schema/union-clash-branches.err delete mode 100644 tests/qapi-schema/union-clash-branches.json delete mode 100644 tests/qapi-schema/union-clash-branches.out delete mode 100644 tests/qapi-schema/union-empty.err delete mode 100644 tests/qapi-schema/union-empty.json delete mode 100644 tests/qapi-schema/union-empty.out delete mode 100644 tests/qapi-schema/union-optional-branch.err delete mode 100644 tests/qapi-schema/union-optional-branch.json delete mode 100644 tests/qapi-schema/union-optional-branch.out (limited to 'tests/qapi-schema') diff --git a/tests/qapi-schema/args-union.err b/tests/qapi-schema/args-union.err index 4bf4955..4b80a99 100644 --- a/tests/qapi-schema/args-union.err +++ b/tests/qapi-schema/args-union.err @@ -1,2 +1,2 @@ args-union.json: In command 'oops': -args-union.json:3: command's 'data' can take union type 'Uni' only with 'boxed': true +args-union.json:9: command's 'data' can take union type 'Uni' only with 'boxed': true diff --git a/tests/qapi-schema/args-union.json b/tests/qapi-schema/args-union.json index 2fcaeaa..aabb159 100644 --- a/tests/qapi-schema/args-union.json +++ b/tests/qapi-schema/args-union.json @@ -1,3 +1,9 @@ # use of union arguments requires 'boxed':true -{ 'union': 'Uni', 'data': { 'case1': 'int', 'case2': 'str' } } +{ 'enum': 'Enum', 'data': [ 'case1', 'case2' ] } +{ 'struct': 'Case1', 'data': { 'data': 'int' } } +{ 'struct': 'Case2', 'data': { 'data': 'str' } } +{ 'union': 'Uni', + 'base': { 'type': 'Enum' }, + 'discriminator': 'type', + 'data': { 'case1': 'Case1', 'case2': 'Case2' } } { 'command': 'oops', 'data': 'Uni' } diff --git a/tests/qapi-schema/bad-base.err b/tests/qapi-schema/bad-base.err index 61a1efc..1fad63e 100644 --- a/tests/qapi-schema/bad-base.err +++ b/tests/qapi-schema/bad-base.err @@ -1,2 +1,2 @@ bad-base.json: In struct 'MyType': -bad-base.json:3: 'base' requires a struct type, union type 'Union' isn't +bad-base.json:9: 'base' requires a struct type, union type 'Union' isn't diff --git a/tests/qapi-schema/bad-base.json b/tests/qapi-schema/bad-base.json index a634331..8c773ff 100644 --- a/tests/qapi-schema/bad-base.json +++ b/tests/qapi-schema/bad-base.json @@ -1,3 +1,9 @@ # we reject a base that is not a struct -{ 'union': 'Union', 'data': { 'a': 'int', 'b': 'str' } } +{ 'enum': 'Enum', 'data': [ 'a', 'b' ] } +{ 'struct': 'Int', 'data': { 'data': 'int' } } +{ 'struct': 'Str', 'data': { 'data': 'str' } } +{ 'union': 'Union', + 'base': { 'type': 'Enum' }, + 'discriminator': 'type', + 'data': { 'a': 'Int', 'b': 'Str' } } { 'struct': 'MyType', 'base': 'Union', 'data': { 'c': 'int' } } diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.json index cbf5c56..a20acff 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -108,15 +108,6 @@ 'if': { 'any': ['IFONE', 'IFTWO'] } } } } ## -# @SugaredUnion: -# Features: -# @union-feat2: a feature -## -{ 'union': 'SugaredUnion', - 'features': [ 'union-feat2' ], - 'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' } } } - -## # @Alternate: # @i: an integer # @b is undocumented diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 478fe6f..5a324e2 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -32,21 +32,6 @@ object Object case two: Variant2 if {'any': ['IFONE', 'IFTWO']} feature union-feat1 -object q_obj_Variant1-wrapper - member data: Variant1 optional=False -object q_obj_Variant2-wrapper - member data: Variant2 optional=False -enum SugaredUnionKind - member one - member two - if IFTWO -object SugaredUnion - member type: SugaredUnionKind optional=False - tag type - case one: q_obj_Variant1-wrapper - case two: q_obj_Variant2-wrapper - if IFTWO - feature union-feat2 alternate Alternate tag type case i: int @@ -149,13 +134,6 @@ doc symbol=Object feature=union-feat1 a feature -doc symbol=SugaredUnion - body= - - arg=type - - feature=union-feat2 -a feature doc symbol=Alternate body= diff --git a/tests/qapi-schema/doc-good.txt b/tests/qapi-schema/doc-good.txt index 0c59d75..701402e 100644 --- a/tests/qapi-schema/doc-good.txt +++ b/tests/qapi-schema/doc-good.txt @@ -130,26 +130,6 @@ Features a feature -"SugaredUnion" (Object) ------------------------ - - -Members -~~~~~~~ - -"type" - One of "one", "two" - -"data": "Variant1" when "type" is ""one"" -"data": "Variant2" when "type" is ""two"" (**If: **"IFTWO") - -Features -~~~~~~~~ - -"union-feat2" - a feature - - "Alternate" (Alternate) ----------------------- diff --git a/tests/qapi-schema/flat-union-base-union.err b/tests/qapi-schema/flat-union-base-union.err index 3b00872..3563e87 100644 --- a/tests/qapi-schema/flat-union-base-union.err +++ b/tests/qapi-schema/flat-union-base-union.err @@ -1,2 +1,2 @@ flat-union-base-union.json: In union 'TestUnion': -flat-union-base-union.json:14: 'base' requires a struct type, union type 'UnionBase' isn't +flat-union-base-union.json:17: 'base' requires a struct type, union type 'UnionBase' isn't diff --git a/tests/qapi-schema/flat-union-base-union.json b/tests/qapi-schema/flat-union-base-union.json index 98b4eba..82d4c96 100644 --- a/tests/qapi-schema/flat-union-base-union.json +++ b/tests/qapi-schema/flat-union-base-union.json @@ -8,7 +8,10 @@ 'data': { 'string': 'str' } } { 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } +{ 'enum': 'Enum', 'data': [ 'kind1', 'kind2' ] } { 'union': 'UnionBase', + 'base': { 'type': 'Enum' }, + 'discriminator': 'type', 'data': { 'kind1': 'TestTypeA', 'kind2': 'TestTypeB' } } { 'union': 'TestUnion', diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index 0798e94..85d3de1 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -192,14 +192,10 @@ schemas = [ 'unclosed-string.json', 'union-base-empty.json', 'union-base-no-discriminator.json', - 'union-branch-case.json', 'union-branch-if-invalid.json', 'union-branch-invalid-dict.json', - 'union-clash-branches.json', - 'union-empty.json', 'union-invalid-base.json', 'union-invalid-data.json', - 'union-optional-branch.json', 'union-unknown.json', 'unknown-escape.json', 'unknown-expr-key.json', diff --git a/tests/qapi-schema/union-branch-case.err b/tests/qapi-schema/union-branch-case.err deleted file mode 100644 index d2d5cb8..0000000 --- a/tests/qapi-schema/union-branch-case.err +++ /dev/null @@ -1,2 +0,0 @@ -union-branch-case.json: In union 'Uni': -union-branch-case.json:2: name of 'data' member 'Branch' must not use uppercase or '_' diff --git a/tests/qapi-schema/union-branch-case.json b/tests/qapi-schema/union-branch-case.json deleted file mode 100644 index b7894b7..0000000 --- a/tests/qapi-schema/union-branch-case.json +++ /dev/null @@ -1,2 +0,0 @@ -# Branch names should be 'lower-case' -{ 'union': 'Uni', 'data': { 'Branch': 'int' } } diff --git a/tests/qapi-schema/union-branch-case.out b/tests/qapi-schema/union-branch-case.out deleted file mode 100644 index e69de29..0000000 diff --git a/tests/qapi-schema/union-branch-invalid-dict.err b/tests/qapi-schema/union-branch-invalid-dict.err index 8137c5a..001cdec 100644 --- a/tests/qapi-schema/union-branch-invalid-dict.err +++ b/tests/qapi-schema/union-branch-invalid-dict.err @@ -1,2 +1,2 @@ union-branch-invalid-dict.json: In union 'UnionInvalidBranch': -union-branch-invalid-dict.json:2: 'data' member 'integer' misses key 'type' +union-branch-invalid-dict.json:4: 'data' member 'integer' misses key 'type' diff --git a/tests/qapi-schema/union-branch-invalid-dict.json b/tests/qapi-schema/union-branch-invalid-dict.json index 9778598..c7c81c0 100644 --- a/tests/qapi-schema/union-branch-invalid-dict.json +++ b/tests/qapi-schema/union-branch-invalid-dict.json @@ -1,4 +1,8 @@ # Long form of member must have a value member 'type' +{ 'enum': 'TestEnum', + 'data': [ 'integer', 's8' ] } { 'union': 'UnionInvalidBranch', + 'base': { 'type': 'TestEnum' }, + 'discriminator': 'type', 'data': { 'integer': { 'if': 'foo'}, 's8': 'int8' } } diff --git a/tests/qapi-schema/union-clash-branches.err b/tests/qapi-schema/union-clash-branches.err deleted file mode 100644 index ef53645..0000000 --- a/tests/qapi-schema/union-clash-branches.err +++ /dev/null @@ -1,2 +0,0 @@ -union-clash-branches.json: In union 'TestUnion': -union-clash-branches.json:6: name of 'data' member 'a_b' must not use uppercase or '_' diff --git a/tests/qapi-schema/union-clash-branches.json b/tests/qapi-schema/union-clash-branches.json deleted file mode 100644 index 7bdda0b..0000000 --- a/tests/qapi-schema/union-clash-branches.json +++ /dev/null @@ -1,7 +0,0 @@ -# Union branch name collision -# Naming rules make collision impossible (even with the pragma). If -# that wasn't the case, then we'd get collisions in generated C: two -# union members a_b, and two enum members TEST_UNION_A_B. -{ 'pragma': { 'member-name-exceptions': [ 'TestUnion' ] } } -{ 'union': 'TestUnion', - 'data': { 'a-b': 'int', 'a_b': 'str' } } diff --git a/tests/qapi-schema/union-clash-branches.out b/tests/qapi-schema/union-clash-branches.out deleted file mode 100644 index e69de29..0000000 diff --git a/tests/qapi-schema/union-empty.err b/tests/qapi-schema/union-empty.err deleted file mode 100644 index 59788c9..0000000 --- a/tests/qapi-schema/union-empty.err +++ /dev/null @@ -1,2 +0,0 @@ -union-empty.json: In union 'Union': -union-empty.json:2: union has no branches diff --git a/tests/qapi-schema/union-empty.json b/tests/qapi-schema/union-empty.json deleted file mode 100644 index df3e5e6..0000000 --- a/tests/qapi-schema/union-empty.json +++ /dev/null @@ -1,2 +0,0 @@ -# simple unions cannot be empty -{ 'union': 'Union', 'data': { } } diff --git a/tests/qapi-schema/union-empty.out b/tests/qapi-schema/union-empty.out deleted file mode 100644 index e69de29..0000000 diff --git a/tests/qapi-schema/union-optional-branch.err b/tests/qapi-schema/union-optional-branch.err deleted file mode 100644 index b33f111..0000000 --- a/tests/qapi-schema/union-optional-branch.err +++ /dev/null @@ -1,2 +0,0 @@ -union-optional-branch.json: In union 'Union': -union-optional-branch.json:2: 'data' member '*a' has an invalid name diff --git a/tests/qapi-schema/union-optional-branch.json b/tests/qapi-schema/union-optional-branch.json deleted file mode 100644 index 591615f..0000000 --- a/tests/qapi-schema/union-optional-branch.json +++ /dev/null @@ -1,2 +0,0 @@ -# union branches cannot be optional -{ 'union': 'Union', 'data': { '*a': 'int', 'b': 'str' } } diff --git a/tests/qapi-schema/union-optional-branch.out b/tests/qapi-schema/union-optional-branch.out deleted file mode 100644 index e69de29..0000000 diff --git a/tests/qapi-schema/union-unknown.err b/tests/qapi-schema/union-unknown.err index 7aba9f9..dad79be 100644 --- a/tests/qapi-schema/union-unknown.err +++ b/tests/qapi-schema/union-unknown.err @@ -1,2 +1,2 @@ union-unknown.json: In union 'Union': -union-unknown.json:2: union uses unknown type 'MissingType' +union-unknown.json:3: branch 'unknown' uses unknown type 'MissingType' diff --git a/tests/qapi-schema/union-unknown.json b/tests/qapi-schema/union-unknown.json index 64d3666..4736f1a 100644 --- a/tests/qapi-schema/union-unknown.json +++ b/tests/qapi-schema/union-unknown.json @@ -1,3 +1,6 @@ # we reject a union with unknown type in branch +{ 'enum': 'Enum', 'data': [ 'unknown' ] } { 'union': 'Union', - 'data': { 'unknown': ['MissingType'] } } + 'base': { 'type': 'Enum' }, + 'discriminator': 'type', + 'data': { 'unknown': 'MissingType' } } -- cgit v1.1 From 4e99f4b12c0e47898e8358a5c8fa54267bb16185 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 17 Sep 2021 16:31:32 +0200 Subject: qapi: Drop simple unions Simple unions predate flat unions. Having both complicates the QAPI schema language and the QAPI generator. We haven't been using simple unions in new code for a long time, because they are less flexible and somewhat awkward on the wire. The previous commits eliminated simple union from the tree. Now drop them from the QAPI schema language entirely, and update mentions of "flat union" to just "union". Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20210917143134.412106-22-armbru@redhat.com> --- tests/qapi-schema/flat-union-array-branch.json | 2 +- tests/qapi-schema/flat-union-empty.json | 2 +- tests/qapi-schema/flat-union-int-branch.json | 2 +- tests/qapi-schema/flat-union-no-base.err | 2 +- tests/qapi-schema/flat-union-no-base.json | 2 +- tests/qapi-schema/qapi-schema-test.json | 2 +- tests/qapi-schema/reserved-member-u.json | 2 +- tests/qapi-schema/union-base-empty.json | 2 +- tests/qapi-schema/union-base-no-discriminator.err | 2 +- tests/qapi-schema/union-base-no-discriminator.json | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) (limited to 'tests/qapi-schema') diff --git a/tests/qapi-schema/flat-union-array-branch.json b/tests/qapi-schema/flat-union-array-branch.json index 0b98820..6dda7ec 100644 --- a/tests/qapi-schema/flat-union-array-branch.json +++ b/tests/qapi-schema/flat-union-array-branch.json @@ -1,4 +1,4 @@ -# we require flat union branches to be a struct +# we require union branches to be a struct { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } { 'struct': 'Base', diff --git a/tests/qapi-schema/flat-union-empty.json b/tests/qapi-schema/flat-union-empty.json index 83e1cc7..584ed60 100644 --- a/tests/qapi-schema/flat-union-empty.json +++ b/tests/qapi-schema/flat-union-empty.json @@ -1,4 +1,4 @@ -# flat union discriminator cannot be empty +# union discriminator enum cannot be empty { 'enum': 'Empty', 'data': [ ] } { 'struct': 'Base', 'data': { 'type': 'Empty' } } { 'union': 'Union', 'base': 'Base', 'discriminator': 'type', 'data': { } } diff --git a/tests/qapi-schema/flat-union-int-branch.json b/tests/qapi-schema/flat-union-int-branch.json index 9370c34..567043d 100644 --- a/tests/qapi-schema/flat-union-int-branch.json +++ b/tests/qapi-schema/flat-union-int-branch.json @@ -1,4 +1,4 @@ -# we require flat union branches to be a struct +# we require union branches to be a struct { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } { 'struct': 'Base', diff --git a/tests/qapi-schema/flat-union-no-base.err b/tests/qapi-schema/flat-union-no-base.err index 5167565..c60482f 100644 --- a/tests/qapi-schema/flat-union-no-base.err +++ b/tests/qapi-schema/flat-union-no-base.err @@ -1,2 +1,2 @@ flat-union-no-base.json: In union 'TestUnion': -flat-union-no-base.json:8: 'discriminator' requires 'base' +flat-union-no-base.json:8: union misses key 'base' diff --git a/tests/qapi-schema/flat-union-no-base.json b/tests/qapi-schema/flat-union-no-base.json index 327877b..f6fe12d 100644 --- a/tests/qapi-schema/flat-union-no-base.json +++ b/tests/qapi-schema/flat-union-no-base.json @@ -1,4 +1,4 @@ -# flat unions require a base +# unions require a base { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } { 'struct': 'TestTypeB', diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json index 20f4cc0..2ec5010 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -30,7 +30,7 @@ { 'struct': 'Empty1', 'data': { } } { 'struct': 'Empty2', 'base': 'Empty1', 'data': { } } -# Likewise for an empty flat union +# Likewise for an empty union { 'union': 'Union', 'base': { 'type': 'EnumOne' }, 'discriminator': 'type', 'data': { } } diff --git a/tests/qapi-schema/reserved-member-u.json b/tests/qapi-schema/reserved-member-u.json index 2bfb8f5..d982ab5 100644 --- a/tests/qapi-schema/reserved-member-u.json +++ b/tests/qapi-schema/reserved-member-u.json @@ -2,6 +2,6 @@ # We reject use of 'u' as a member name, to allow it for internal use in # putting union branch members in a separate namespace from QMP members. # This is true even for non-unions, because it is possible to convert a -# struct to flat union while remaining backwards compatible in QMP. +# struct to union while remaining backwards compatible in QMP. # TODO - we could munge the member name to 'q_u' to avoid the collision { 'struct': 'Oops', 'data': { '*u': 'str' } } diff --git a/tests/qapi-schema/union-base-empty.json b/tests/qapi-schema/union-base-empty.json index d1843d3..6f8ef00 100644 --- a/tests/qapi-schema/union-base-empty.json +++ b/tests/qapi-schema/union-base-empty.json @@ -1,4 +1,4 @@ -# Flat union with empty base and therefore without discriminator +# Union with empty base and therefore without discriminator { 'struct': 'Empty', 'data': { } } diff --git a/tests/qapi-schema/union-base-no-discriminator.err b/tests/qapi-schema/union-base-no-discriminator.err index 9cd5d11..a730b7f 100644 --- a/tests/qapi-schema/union-base-no-discriminator.err +++ b/tests/qapi-schema/union-base-no-discriminator.err @@ -1,2 +1,2 @@ union-base-no-discriminator.json: In union 'TestUnion': -union-base-no-discriminator.json:11: 'base' requires 'discriminator' +union-base-no-discriminator.json:11: union misses key 'discriminator' diff --git a/tests/qapi-schema/union-base-no-discriminator.json b/tests/qapi-schema/union-base-no-discriminator.json index 1409cf5..2e7cae9 100644 --- a/tests/qapi-schema/union-base-no-discriminator.json +++ b/tests/qapi-schema/union-base-no-discriminator.json @@ -1,4 +1,4 @@ -# we reject simple unions with a base (or flat unions without discriminator) +# we reject unions without discriminator { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -- cgit v1.1 From 8b3b3a16dfca57b7c4e7b8af215aec96880153d7 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 17 Sep 2021 16:31:33 +0200 Subject: tests/qapi-schema: Rename flat-union-* test cases to union-* Signed-off-by: Markus Armbruster Message-Id: <20210917143134.412106-23-armbru@redhat.com> Reviewed-by: Eric Blake Date: Wed, 22 Sep 2021 14:56:18 +0200 Subject: tests/qapi-schema: Use Python OSError instead of outmoded IOError MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://docs.python.org/3.6/library/exceptions.html has Changed in version 3.3: EnvironmentError, IOError, WindowsError, socket.error, select.error and mmap.error have been merged into OSError, and the constructor may return a subclass. and The following exceptions are kept for compatibility with previous versions; starting from Python 3.3, they are aliases of OSError. exception EnvironmentError exception IOError exception WindowsError Only available on Windows. Switch to the preferred name. Signed-off-by: Markus Armbruster Message-Id: <20210922125619.670673-2-armbru@redhat.com> Reviewed-by: John Snow Reviewed-by: Philippe Mathieu-Daudé [Details added to commit message] --- tests/qapi-schema/test-qapi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/qapi-schema') diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 73cffae..2e384f5 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -154,7 +154,7 @@ def test_and_diff(test_name, dir_name, update): errfp = open(os.path.join(dir_name, test_name + '.err'), mode) expected_out = outfp.readlines() expected_err = errfp.readlines() - except IOError as err: + except OSError as err: print("%s: can't open '%s': %s" % (sys.argv[0], err.filename, err.strerror), file=sys.stderr) @@ -180,7 +180,7 @@ def test_and_diff(test_name, dir_name, update): errfp.truncate(0) errfp.seek(0) errfp.writelines(actual_err) - except IOError as err: + except OSError as err: print("%s: can't write '%s': %s" % (sys.argv[0], err.filename, err.strerror), file=sys.stderr) -- cgit v1.1 From f333681c6e277004796b0bed808697da1280d140 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 22 Sep 2021 14:56:19 +0200 Subject: tests/qapi-schema: Make test-qapi.py -u work when files are absent test-qapi.py -u updates the expected files. Since it fails when they are absent, users have to create them manually before they can use test-qapi.py to fill in the contents, say for a new test. Silly. Improve -u to create them. Signed-off-by: Markus Armbruster Message-Id: <20210922125619.670673-3-armbru@redhat.com> Reviewed-by: John Snow --- tests/qapi-schema/test-qapi.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'tests/qapi-schema') diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 2e384f5..c717a7a 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -132,6 +132,17 @@ def test_frontend(fname): print(' section=%s\n%s' % (section.name, section.text)) +def open_test_result(dir_name, file_name, update): + mode = 'r+' if update else 'r' + try: + fp = open(os.path.join(dir_name, file_name), mode) + except FileNotFoundError: + if not update: + raise + fp = open(os.path.join(dir_name, file_name), 'w+') + return fp + + def test_and_diff(test_name, dir_name, update): sys.stdout = StringIO() try: @@ -148,10 +159,9 @@ def test_and_diff(test_name, dir_name, update): sys.stdout.close() sys.stdout = sys.__stdout__ - mode = 'r+' if update else 'r' try: - outfp = open(os.path.join(dir_name, test_name + '.out'), mode) - errfp = open(os.path.join(dir_name, test_name + '.err'), mode) + outfp = open_test_result(dir_name, test_name + '.out', update) + errfp = open_test_result(dir_name, test_name + '.err', update) expected_out = outfp.readlines() expected_err = errfp.readlines() except OSError as err: -- cgit v1.1