tests/qapi-schema: Test for reserved names, empty struct
Add some testsuite coverage to ensure future patches are on the right track: Our current C representation of qapi arrays is done by appending 'List' to the element name; but we are not preventing the creation of an object type with the same name. Add reserved-type-list.json to test this. Then rename enum-union-clash.json to reserved-type-kind.json to cover the reservation that we DO detect, and shorten it to match the fact that the name is reserved even if there is no clash. We are failing to detect a collision between a dictionary member and the implicit 'has_*' flag for another optional member. The easiest fix would be for a future patch to reserve the entire "has[-_]" namespace for member names (the collision is also possible for branch names within flat unions, but only as long as branch names can collide with (non-variant) members; however, since future patches are about to remove that, it is not worth testing here). Add reserved-member-has.json to test this. A similar collision exists between a dictionary member where c_name() munges what might otherwise be a reserved name to start with 'q_', and another member explicitly starts with "q[-_]". Again, the easiest solution for a future patch will be reserving the entire namespace, but here for commands as well as members. Add reserved-member-q.json and reserved-command-q.json to test this; separate tests since arguably our munging of command 'unix' to 'qmp_q_unix()' could be done without a q_, which is different than the munging of a member 'unix' to 'foo.q_unix'. Finally, our testsuite does not have any compilation coverage of struct inheritance with empty qapi structs. Update qapi-schema-test.json to test this. Note that there is currently no technical reason to forbid type name patterns from member names, or member name patterns from types, since the two are not in the same namespace in C and won't collide; but it's not worth adding positive tests of these corner cases at this time, especially while there is other churn pending in patches that rearrange which collisions actually happen. Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1445898903-12082-2-git-send-email-eblake@redhat.com> [Commit message tweaked slightly] Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
2ea1793bd9
commit
1976708321
@ -265,7 +265,6 @@ qapi-schema += enum-dict-member.json
|
||||
qapi-schema += enum-int-member.json
|
||||
qapi-schema += enum-max-member.json
|
||||
qapi-schema += enum-missing-data.json
|
||||
qapi-schema += enum-union-clash.json
|
||||
qapi-schema += enum-wrong-data.json
|
||||
qapi-schema += escape-outside-string.json
|
||||
qapi-schema += escape-too-big.json
|
||||
@ -316,6 +315,11 @@ qapi-schema += redefined-builtin.json
|
||||
qapi-schema += redefined-command.json
|
||||
qapi-schema += redefined-event.json
|
||||
qapi-schema += redefined-type.json
|
||||
qapi-schema += reserved-command-q.json
|
||||
qapi-schema += reserved-member-has.json
|
||||
qapi-schema += reserved-member-q.json
|
||||
qapi-schema += reserved-type-kind.json
|
||||
qapi-schema += reserved-type-list.json
|
||||
qapi-schema += returns-alternate.json
|
||||
qapi-schema += returns-array-bad.json
|
||||
qapi-schema += returns-dict.json
|
||||
|
@ -1 +0,0 @@
|
||||
tests/qapi-schema/enum-union-clash.json:2: enum 'UnionKind' should not end in 'Kind'
|
@ -11,6 +11,10 @@
|
||||
# An empty enum, although unusual, is currently acceptable
|
||||
{ 'enum': 'MyEnum', 'data': [ ] }
|
||||
|
||||
# Likewise for an empty struct, including an empty base
|
||||
{ 'struct': 'Empty1', 'data': { } }
|
||||
{ 'struct': 'Empty2', 'base': 'Empty1', 'data': { } }
|
||||
|
||||
# for testing override of default naming heuristic
|
||||
{ 'enum': 'QEnumTwo',
|
||||
'prefix': 'QENUM_TWO',
|
||||
|
@ -81,6 +81,9 @@ event EVENT_A None
|
||||
event EVENT_B None
|
||||
event EVENT_C :obj-EVENT_C-arg
|
||||
event EVENT_D :obj-EVENT_D-arg
|
||||
object Empty1
|
||||
object Empty2
|
||||
base Empty1
|
||||
enum EnumOne ['value1', 'value2', 'value3']
|
||||
object EventStructOne
|
||||
member struct1: UserDefOne optional=False
|
||||
|
1
tests/qapi-schema/reserved-command-q.exit
Normal file
1
tests/qapi-schema/reserved-command-q.exit
Normal file
@ -0,0 +1 @@
|
||||
0
|
7
tests/qapi-schema/reserved-command-q.json
Normal file
7
tests/qapi-schema/reserved-command-q.json
Normal file
@ -0,0 +1,7 @@
|
||||
# C entity name collision
|
||||
# FIXME - This parses, but fails to compile, because it attempts to declare
|
||||
# two 'qmp_q_unix' functions (one for 'q-unix', the other because c_name()
|
||||
# munges 'unix' to 'q_unix' to avoid reserved word collisions). We should
|
||||
# reject attempts to explicitly use 'q_' names, to reserve it for qapi.
|
||||
{ 'command': 'unix' }
|
||||
{ 'command': 'q-unix' }
|
5
tests/qapi-schema/reserved-command-q.out
Normal file
5
tests/qapi-schema/reserved-command-q.out
Normal file
@ -0,0 +1,5 @@
|
||||
object :empty
|
||||
command q-unix None -> None
|
||||
gen=True success_response=True
|
||||
command unix None -> None
|
||||
gen=True success_response=True
|
0
tests/qapi-schema/reserved-member-has.err
Normal file
0
tests/qapi-schema/reserved-member-has.err
Normal file
1
tests/qapi-schema/reserved-member-has.exit
Normal file
1
tests/qapi-schema/reserved-member-has.exit
Normal file
@ -0,0 +1 @@
|
||||
0
|
6
tests/qapi-schema/reserved-member-has.json
Normal file
6
tests/qapi-schema/reserved-member-has.json
Normal file
@ -0,0 +1,6 @@
|
||||
# C member name collision
|
||||
# FIXME - This parses, but fails to compile, because the C struct is given
|
||||
# two 'has_a' members, one from the flag for optional 'a', and the other
|
||||
# from member 'has-a'. Either reject this at parse time, or munge the C
|
||||
# names to avoid the collision.
|
||||
{ 'command': 'oops', 'data': { '*a': 'str', 'has-a': 'str' } }
|
6
tests/qapi-schema/reserved-member-has.out
Normal file
6
tests/qapi-schema/reserved-member-has.out
Normal file
@ -0,0 +1,6 @@
|
||||
object :empty
|
||||
object :obj-oops-arg
|
||||
member a: str optional=True
|
||||
member has-a: str optional=False
|
||||
command oops :obj-oops-arg -> None
|
||||
gen=True success_response=True
|
0
tests/qapi-schema/reserved-member-q.err
Normal file
0
tests/qapi-schema/reserved-member-q.err
Normal file
1
tests/qapi-schema/reserved-member-q.exit
Normal file
1
tests/qapi-schema/reserved-member-q.exit
Normal file
@ -0,0 +1 @@
|
||||
0
|
6
tests/qapi-schema/reserved-member-q.json
Normal file
6
tests/qapi-schema/reserved-member-q.json
Normal file
@ -0,0 +1,6 @@
|
||||
# C member name collision
|
||||
# FIXME - This parses, but fails to compile, because it attempts to declare
|
||||
# two 'q_unix' members (one for 'q-unix', the other because c_name()
|
||||
# munges 'unix' to 'q_unix' to avoid reserved word collisions). We should
|
||||
# reject attempts to explicitly use 'q_' names, to reserve it for qapi.
|
||||
{ 'struct': 'Foo', 'data': { 'unix':'int', 'q-unix':'bool' } }
|
4
tests/qapi-schema/reserved-member-q.out
Normal file
4
tests/qapi-schema/reserved-member-q.out
Normal file
@ -0,0 +1,4 @@
|
||||
object :empty
|
||||
object Foo
|
||||
member unix: int optional=False
|
||||
member q-unix: bool optional=False
|
1
tests/qapi-schema/reserved-type-kind.err
Normal file
1
tests/qapi-schema/reserved-type-kind.err
Normal file
@ -0,0 +1 @@
|
||||
tests/qapi-schema/reserved-type-kind.json:2: enum 'UnionKind' should not end in 'Kind'
|
@ -1,4 +1,2 @@
|
||||
# we reject types that would conflict with implicit union enum
|
||||
{ 'enum': 'UnionKind', 'data': [ 'oops' ] }
|
||||
{ 'union': 'Union',
|
||||
'data': { 'a': 'int' } }
|
0
tests/qapi-schema/reserved-type-kind.out
Normal file
0
tests/qapi-schema/reserved-type-kind.out
Normal file
0
tests/qapi-schema/reserved-type-list.err
Normal file
0
tests/qapi-schema/reserved-type-list.err
Normal file
1
tests/qapi-schema/reserved-type-list.exit
Normal file
1
tests/qapi-schema/reserved-type-list.exit
Normal file
@ -0,0 +1 @@
|
||||
0
|
5
tests/qapi-schema/reserved-type-list.json
Normal file
5
tests/qapi-schema/reserved-type-list.json
Normal file
@ -0,0 +1,5 @@
|
||||
# Potential C name collision
|
||||
# FIXME - This parses and compiles on its own, but prevents the user from
|
||||
# creating a type named 'Foo' and using ['Foo'] for an array. We should
|
||||
# reject the use of any type names ending in 'List'.
|
||||
{ 'struct': 'FooList', 'data': { 's': 'str' } }
|
3
tests/qapi-schema/reserved-type-list.out
Normal file
3
tests/qapi-schema/reserved-type-list.out
Normal file
@ -0,0 +1,3 @@
|
||||
object :empty
|
||||
object FooList
|
||||
member s: str optional=False
|
Loading…
Reference in New Issue
Block a user