diff options
author | Eric Blake <eblake@redhat.com> | 2015-12-01 22:20:57 -0700 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2015-12-17 08:21:29 +0100 |
commit | 893e1f2c5170d54316f1dcf3fefae679175622fc (patch) | |
tree | 1c689f3a0462a4dc76b337c175ec305c5749dfbe /tests/qapi-schema | |
parent | 93bda4dd461358b4fc05dfd8e2d6419cdd574789 (diff) | |
download | qemu-893e1f2c5170d54316f1dcf3fefae679175622fc.zip qemu-893e1f2c5170d54316f1dcf3fefae679175622fc.tar.gz qemu-893e1f2c5170d54316f1dcf3fefae679175622fc.tar.bz2 |
qapi: Enforce (or whitelist) case conventions on qapi members
We document that members of enums and objects should be
'lower-case', although we were not enforcing it. We have to
whitelist a few pre-existing entities that violate the norms.
Add three new tests to expose the new error message, each of
which first uses the whitelisted name 'UuidInfo' to prove the
whitelist works, then triggers the failure (this is the same
pattern used in the existing returns-whitelist.json test).
Note that by adding this check, we have effectively forbidden
an entity with a case-insensitive clash of member names, for
any entity that is not on the whitelist (although there is
still the possibility to clash via '-' vs. '_').
Not done here: a future patch should also add naming convention
support and whitelist exceptions for command, event, and type
names.
The additions to QAPISchemaMember.check_clash() check whether
info['name'] is in the whitelist (the top-most entity name at
the point 'info' tracks), rather than self.owner (the type,
possibly implicit, that directly owns the member), because it
is easier to maintain the whitelist by the names actually in
the user's .json file, rather than worrying about the names
of implicit types.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1449033659-25497-14-git-send-email-eblake@redhat.com>
[Simplified a bit as per discussion with Eric]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/qapi-schema')
-rw-r--r-- | tests/qapi-schema/args-member-case.err | 1 | ||||
-rw-r--r-- | tests/qapi-schema/args-member-case.exit | 1 | ||||
-rw-r--r-- | tests/qapi-schema/args-member-case.json | 2 | ||||
-rw-r--r-- | tests/qapi-schema/args-member-case.out | 0 | ||||
-rw-r--r-- | tests/qapi-schema/enum-member-case.err | 1 | ||||
-rw-r--r-- | tests/qapi-schema/enum-member-case.exit | 1 | ||||
-rw-r--r-- | tests/qapi-schema/enum-member-case.json | 3 | ||||
-rw-r--r-- | tests/qapi-schema/enum-member-case.out | 0 | ||||
-rw-r--r-- | tests/qapi-schema/union-branch-case.err | 1 | ||||
-rw-r--r-- | tests/qapi-schema/union-branch-case.exit | 1 | ||||
-rw-r--r-- | tests/qapi-schema/union-branch-case.json | 2 | ||||
-rw-r--r-- | tests/qapi-schema/union-branch-case.out | 0 |
12 files changed, 13 insertions, 0 deletions
diff --git a/tests/qapi-schema/args-member-case.err b/tests/qapi-schema/args-member-case.err new file mode 100644 index 0000000..19c4426 --- /dev/null +++ b/tests/qapi-schema/args-member-case.err @@ -0,0 +1 @@ +tests/qapi-schema/args-member-case.json:2: 'Arg' (parameter of no-way-this-will-get-whitelisted) should not use uppercase diff --git a/tests/qapi-schema/args-member-case.exit b/tests/qapi-schema/args-member-case.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/qapi-schema/args-member-case.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/args-member-case.json b/tests/qapi-schema/args-member-case.json new file mode 100644 index 0000000..93439be --- /dev/null +++ b/tests/qapi-schema/args-member-case.json @@ -0,0 +1,2 @@ +# Member names should be 'lower-case' unless the struct/command is whitelisted +{ 'command': 'no-way-this-will-get-whitelisted', 'data': { 'Arg': 'int' } } diff --git a/tests/qapi-schema/args-member-case.out b/tests/qapi-schema/args-member-case.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/qapi-schema/args-member-case.out diff --git a/tests/qapi-schema/enum-member-case.err b/tests/qapi-schema/enum-member-case.err new file mode 100644 index 0000000..b652e9a --- /dev/null +++ b/tests/qapi-schema/enum-member-case.err @@ -0,0 +1 @@ +tests/qapi-schema/enum-member-case.json:3: 'Value' (member of NoWayThisWillGetWhitelisted) should not use uppercase diff --git a/tests/qapi-schema/enum-member-case.exit b/tests/qapi-schema/enum-member-case.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/qapi-schema/enum-member-case.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/enum-member-case.json b/tests/qapi-schema/enum-member-case.json new file mode 100644 index 0000000..2096b35 --- /dev/null +++ b/tests/qapi-schema/enum-member-case.json @@ -0,0 +1,3 @@ +# Member names should be 'lower-case' unless the enum is whitelisted +{ 'enum': 'UuidInfo', 'data': [ 'Value' ] } # UuidInfo is whitelisted +{ 'enum': 'NoWayThisWillGetWhitelisted', 'data': [ 'Value' ] } diff --git a/tests/qapi-schema/enum-member-case.out b/tests/qapi-schema/enum-member-case.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/qapi-schema/enum-member-case.out diff --git a/tests/qapi-schema/union-branch-case.err b/tests/qapi-schema/union-branch-case.err new file mode 100644 index 0000000..1152190 --- /dev/null +++ b/tests/qapi-schema/union-branch-case.err @@ -0,0 +1 @@ +tests/qapi-schema/union-branch-case.json:2: 'Branch' (branch of NoWayThisWillGetWhitelisted) should not use uppercase diff --git a/tests/qapi-schema/union-branch-case.exit b/tests/qapi-schema/union-branch-case.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/qapi-schema/union-branch-case.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/union-branch-case.json b/tests/qapi-schema/union-branch-case.json new file mode 100644 index 0000000..e6565dc --- /dev/null +++ b/tests/qapi-schema/union-branch-case.json @@ -0,0 +1,2 @@ +# Branch names should be 'lower-case' unless the union is whitelisted +{ 'union': 'NoWayThisWillGetWhitelisted', 'data': { 'Branch': 'int' } } diff --git a/tests/qapi-schema/union-branch-case.out b/tests/qapi-schema/union-branch-case.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/qapi-schema/union-branch-case.out |