From: "Andreas Färber" <afaerber@suse.de>
To: Markus Armbruster <armbru@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] qdev-monitor-test: simplify using g_assert_cmpstr()
Date: Wed, 18 Dec 2013 18:49:33 +0100 [thread overview]
Message-ID: <52B1E02D.6010008@suse.de> (raw)
In-Reply-To: <87y53ixew2.fsf@blackfin.pond.sub.org>
Am 18.12.2013 18:11, schrieb Markus Armbruster:
> Stefan Hajnoczi <stefanha@redhat.com> writes:
>
>> Use g_assert_cmpstr() instead of combining g_assert() and strcmp(3).
>> This simplifies the code since we no longer have to play games to
>> distinguish NULL from "" using "(null)".
>>
>> gcc extension haters will also be happy that ?: was dropped.
>>
>> Suggested-by: Markus Armbruster <armbru@redhat.com>
>> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
>> ---
>> tests/qdev-monitor-test.c | 10 +++++-----
>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/tests/qdev-monitor-test.c b/tests/qdev-monitor-test.c
>> index ba7f9cc..eefaab8 100644
>> --- a/tests/qdev-monitor-test.c
>> +++ b/tests/qdev-monitor-test.c
>> @@ -32,8 +32,9 @@ static void test_device_add(void)
>> "}}");
>> g_assert(response);
>> error = qdict_get_qdict(response, "error");
>> - g_assert(!strcmp(qdict_get_try_str(error, "desc") ?: "",
>> - "Device needs media, but drive is empty"));
>> + g_assert_cmpstr(qdict_get_try_str(error, "desc"),
>> + ==,
>> + "Device needs media, but drive is empty");
>> QDECREF(response);
>>
>> /* Delete the drive */
>
> Outside this patch's scope, but here goes anyway: why do we test the
> value of member desc? Isn't that awfully fragile?
>
> It broke once already, in Andreas's commit 75884af "virtio-blk: Convert
> to QOM realize". Andreas, do you remember why you tossed the class ==
> GenericError check instead of the desc check?
/me points to bonzini, who rebased it on my behalf. :)
I do agree that testing error descriptions is fragile in that people may
not think of running make check on a trivial textual change, e.g. typo fix.
Andreas
>
>> @@ -42,7 +43,7 @@ static void test_device_add(void)
>> " \"command-line\": \"drive_del drive0\""
>> "}}");
>> g_assert(response);
>> - g_assert(!strcmp(qdict_get_try_str(response, "return") ?: "(null)", ""));
>> + g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "");
>> QDECREF(response);
>>
>> /* Try to re-add the drive. This fails with duplicate IDs if a leaked
>> @@ -53,8 +54,7 @@ static void test_device_add(void)
>> " \"command-line\": \"drive_add pci-addr=auto if=none,id=drive0\""
>> "}}");
>> g_assert(response);
>> - g_assert(!strcmp(qdict_get_try_str(response, "return") ?: "",
>> - "OK\r\n"));
>> + g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "OK\r\n");
>> QDECREF(response);
>>
>> qtest_end();
>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
>
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
next prev parent reply other threads:[~2013-12-18 17:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-18 16:34 [Qemu-devel] [PATCH] qdev-monitor-test: simplify using g_assert_cmpstr() Stefan Hajnoczi
2013-12-18 17:11 ` Markus Armbruster
2013-12-18 17:49 ` Andreas Färber [this message]
2013-12-18 18:31 ` Andreas Färber
2013-12-19 15:38 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52B1E02D.6010008@suse.de \
--to=afaerber@suse.de \
--cc=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).