[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 01/19] test-cutils: Avoid g_assert in unit tests
|
From: |
Eric Blake |
|
Subject: |
Re: [PATCH v2 01/19] test-cutils: Avoid g_assert in unit tests |
|
Date: |
Fri, 12 May 2023 07:11:40 -0500 |
|
User-agent: |
NeoMutt/20230407 |
On Thu, May 11, 2023 at 09:10:15PM -0500, Eric Blake wrote:
> glib documentation[1] is clear: g_assert() should be avoided in unit
> tests because it is ineffective if G_DISABLE_ASSERT is defined; unit
> tests should stick to constructs based on g_assert_true() instead.
> Note that since commit 262a69f428, we intentionally state that you
> cannot define G_DISABLE_ASSERT that while building qemu; but our code
s/that //
> can be copied to other projects without that restriction, so we should
> be consistent.
>
> For most of the replacements in this patch, using g_assert_cmpstr()
> would be a regression in quality - although it would helpfully display
> the string contents of both pointers on test failure, here, we really
> do care about pointer equality, not just string content equality. But
> when a NULL pointer is expected, g_assert_null works fine.
>
> [1] https://libsoup.org/glib/glib-Testing.html#g-assert
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
> ---
> tests/unit/test-cutils.c | 324 +++++++++++++++++++--------------------
> 1 file changed, 162 insertions(+), 162 deletions(-)
>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
- [PATCH v2 00/19] Fix qemu_strtosz() read-out-of-bounds, Eric Blake, 2023/05/11
- [PATCH v2 01/19] test-cutils: Avoid g_assert in unit tests, Eric Blake, 2023/05/11
- [PATCH v2 02/19] test-cutils: Use g_assert_cmpuint where appropriate, Eric Blake, 2023/05/11
- [PATCH v2 03/19] test-cutils: Test integral qemu_strto* value on failures, Eric Blake, 2023/05/11
- [PATCH v2 08/19] cutils: Allow NULL endptr in parse_uint(), Eric Blake, 2023/05/11
- [PATCH v2 04/19] test-cutils: Test more integer corner cases, Eric Blake, 2023/05/11
- [PATCH v2 10/19] test-cutils: Prepare for upcoming semantic change in qemu_strtosz, Eric Blake, 2023/05/11
- [PATCH v2 05/19] cutils: Fix wraparound parsing in qemu_strtoui, Eric Blake, 2023/05/11