Using newlines in error messages is not allowed as per qapi/error.h documentation.
Checkpatch has been enforcing this for the error.h API, but also for g_test_message() which doesn't fall under the qapi/error.h prescription. Using newlines in that function's format string is fine and can help with readability of test code when formatting test results. Note that g_test_message() automatically adds the '#' required by the TAP protocol to the start of each line. Relax the regex for this function, but still forbid a trailing newline because it's added automatically and usually not what the user wants. Reviewed-by: Markus Armbruster <[email protected]> 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 03f35e7501..8fd38868c5 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)\s*\(.*\".*\\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
