From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] tests: add test for json-streamer.c error recovery
Date: Thu, 23 Apr 2026 08:57:57 +0200 [thread overview]
Message-ID: <87bjfarwne.fsf@pond.sub.org> (raw)
In-Reply-To: <CABgObfYRLUs96voXsxmSp-2fQD_UV6Yq3reaSYMbrf9gDp+DRA@mail.gmail.com> (Paolo Bonzini's message of "Tue, 21 Apr 2026 23:39:14 +0100")
Paolo Bonzini <pbonzini@redhat.com> writes:
> On Tue, Apr 21, 2026 at 12:29 PM Markus Armbruster <armbru@redhat.com> wrote:
>> > +static void parse_emit(void *opaque, QObject *json, Error *err)
>> > +{
>> > + ParseResult *r = opaque;
>> > +
>>
>> Recommend
>>
>> assert(!json != !err);
>
> Makes sense.
>
>> > +static void test_simple(void)
>> > +{
>> > + check_result("false", 0, QTYPE_QBOOL);
>> > +}
>>
>> This one isn't about error recovery. It's arguably redundant with
>> check-qjson.c's keyword_literal().
>
> Or the other way round. :) They test different APIs which makes both
> of them worthwhile.
See discussion at the end.
>> > +
>> > +static void test_extra_closing_braces(void)
>> > +{
>> > + check_result("}}false", 2, QTYPE_QBOOL);
>> > +}
>>
>> Overlap with check-qjson.c's multiple_values().
>
> Overlapping input but completely different test, because this checks
> for success (after error) whereas multiple_values() checks for an
> error condition. This also shows the difference between the two test
> files and APIs.
>
>> > +
>> > +static void test_bad_dict(void)
>> > +{
>> > + check_result("{ 'abc' }false", 1, QTYPE_QBOOL);
>> > +}
>>
>> Interesting: just one error, because error recovery eats false.
>
> Why would it eat false here? The error is recovered after "{ 'abc' }"
> and then "false" is parsed successfully. One error and one successful
> value, as indicated by the arguments to check_result().
I got confused %-}
>> > +
>> > +static void test_lexer_recovery(void)
>> > +{
>> > + check_result("\f{}", 1, QTYPE_QDICT);
>> > + check_result("\f[]", 1, QTYPE_QLIST);
>> > + check_result("\f:false", 2, QTYPE_QBOOL);
>> > + check_result("\f,false", 2, QTYPE_QBOOL);
>> > +
>> > + /*
>> > + * alphabetic characters do not start a new parsing, this is slightly weird
>> > + * but it keeps the lexer simple and works well for QMP (where valid input
>> > + * is a sequence of dictionaries)
>> > + */
>>
>> Please wrap comment lines a bit earlier for legibility:
>
> 79 characters are Just Fine. While I appreciate careful reviews, and
> I will apply your suggested edit, this is perhaps a bit too much?
I asked nicely, because I do have real trouble reading long lines. It's
not the right margin, it's the width of the text not counting
indentation.
Peace?
>> > + /* same as test_lexer_recovery */
>> > + check_result_error("{[{\ffalse", 1);
>>
>> Really?
>
> Same comment about alphabetic characters not starting a new parsing after \f.
>
>> check-json-parser.c and check-qjson.c both test the JSON parser.
>>
>> check-json-parser.c tests at the json-parser.h level, and focuses on
>> error recovery.
>
> That's what I focused on _for now_, because that's where the push
> parser changes are more tricky, but it doesn't have to be that way.
>
>> check-qjson.c tests one level up at the qjson.h level, where error
>> recovery is not testable.
>>
>> Perhaps the JSON parser tests should all be in one place. This is not a
>> demand :)
>
> Objection, your honor - different APIs, different test files. :)
Separate APIs, yes, but one wraps around the other in a straightforward
manner.
I don't mind having a separate tests for both levels.
Ideally, the test at the lower level would be complete, and the test at
the upper level focused on what's added there.
As is, much functionality is only covered at the upper level. Some is
covered at both.
I wanted to point that out. I could've expressed myself more clearly,
though. Whether and when to clean up this tangle is up for debate!
next prev parent reply other threads:[~2026-04-23 6:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 9:59 [PATCH] tests: add test for json-streamer.c error recovery Paolo Bonzini
2026-04-20 11:53 ` Markus Armbruster
2026-04-20 12:00 ` Paolo Bonzini
2026-04-21 11:18 ` Markus Armbruster
2026-04-21 11:29 ` Markus Armbruster
2026-04-21 22:39 ` Paolo Bonzini
2026-04-23 6:57 ` Markus Armbruster [this message]
2026-04-23 6:55 ` Markus Armbruster
2026-04-23 16:24 ` Paolo Bonzini
2026-04-23 17:30 ` Markus Armbruster
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=87bjfarwne.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.