Peter Xu <[email protected]> writes:
> On Wed, Sep 02, 2026 at 07:15:29PM -0300, Fabiano Rosas wrote:
>> Using newlines in the g_test_message is fine. It automatically adds
>> the '#' required by the TAP protocol to the start of each line.
>
> IIUC we have such check not because TAP, but because all these functions
> will append one newline at the end, hence it's not needed. IOW, if it
> applies to g_test_message(), I don't see why it doesn't apply to the rest.
> But maybe there're other reasons?
>
> To make it simpler, maybe we just call a few times g_test_message()?
>
Not sure I understand your point, Peter. I want to be able to print nice
messages in patch 9:
g_test_message("expected vs. found:\n\n%s\n---\n%s:%s", str, t2[match],
t2[match + 1]);
# HMP output mismatch for entry at line 55:
# expected vs. found:
#
# max-bandwidth: 10356305952768 bytes/hour
# ---
# max-bandwidth: 10356305952768 bytes/second
What would be the issue of having newlines here?
>>
>> Relax the regex for this function, but still forbid a trailing newline
>> because it's added automatically and usually not what the user wants.
>>
>> Signed-off-by: Fabiano Rosas <[email protected]>
>> ---
>> scripts/checkpatch.pl | 11 +++++++++--
>> 1 file changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index 03f35e75012..fd4534b3a1e 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -3303,13 +3303,20 @@ sub process {
>> info_vreport|
>> error_report|
>> warn_report|
>> - info_report|
>> - g_test_message}x;
>> + info_report}x;
>>
>> if ($rawline =~ /\b(?:$qemu_error_funcs)\s*\(.*\".*\\n/) {
>> ERROR("Error messages should not contain newlines\n" .
>> $herecurr);
>> }
>>
>> + # No newlines at the end
>> + my $trail_newline_error_funcs = qr{g_test_message}x;
>> +
>> + if ($rawline =~
>> /\b(?:$trail_newline_error_funcs)\(.*\".*\\n\"/) {
>> + ERROR("Error messages should not contain trailing " .
>> + "newlines\n" . $herecurr);
>> + }
>> +
>> # Continue checking for error messages that contains newlines.
>> # This check handles cases where string literals are spread
>> # over multiple lines.
>> --
>> 2.53.0
>>