]> git.proxmox.com Git - mirror_qemu.git/commit
test-cutils: Avoid g_assert in unit tests
authorEric Blake <eblake@redhat.com>
Fri, 12 May 2023 02:10:15 +0000 (21:10 -0500)
committerEric Blake <eblake@redhat.com>
Fri, 2 Jun 2023 16:24:18 +0000 (11:24 -0500)
commit3a5925922520f934f7b0f96d0c65a041540d7738
treecd4d0f236aaaeadafd835d642c1d6aafe77a7359
parent5cf899e21555d57b9ee1d0a8256f9a2230e88658
test-cutils: Avoid g_assert in unit tests

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 while building qemu; but our code 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>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20230522190441.64278-2-eblake@redhat.com>
tests/unit/test-cutils.c