qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] tests: unit: add NULL-pointer check


From: Paolo Bonzini
Subject: Re: [PATCH] tests: unit: add NULL-pointer check
Date: Tue, 6 Sep 2022 08:07:37 +0200



Il mar 6 set 2022, 07:01 Markus Armbruster <armbru@redhat.com> ha scritto:
Next, permit me a few words on writing tests.  For me, a unit test fails
by crashing.  Crashing with a nice message is optional.  The more likely
the failure, the more useful is niceness.  Complete niceness is
impossible --- if we could predict all crashes, we wouldn't need tests.
Trying to push niceness can be overly verbose.  Thus, judgement calls,
and matters of taste.

I agree; however, *relying* on a crash for correctness of the test is not great. Part of the test here is checking that an empty qdict_crumple returns a dictionary and not, say, a list. The newly-added assertion avoids that two wrongs end up making a right: if qobject_check_type somehow failed to identify the dictionary and returned (QDict *) obj, qdict_size would not crash.

Unlikely as it is, it's nicer to spell out the postconditions that the test is checking.

Paolo



Wanting to mollify Coverity is a valid argument.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]