google / googletest

GoogleTest - Google Testing and Mocking Framework
https://google.github.io/googletest/
BSD 3-Clause "New" or "Revised" License
33.78k stars 10k forks source link

Better exception printing for multi-line exceptions #4387 #4393

Closed abhiota closed 4 months ago

abhiota commented 9 months ago

This makes GTest easier to use, by making its messages slightly more readable. This is clearly nice-to-have. The patch is probably only 15 additional lines of code + test cases. We are happy to provide a patch for it.

For exceptions with multi-line e.what() descriptions, GTest currently prints:

C++ exception with description "Error: 22000
Error while communicating with S3
DETAIL: aws-s3-bucket-name: mybucket
INTERNAL DETAIL: aws-s3-bucket-name: mybucket" thrown in the test body.

Modifications:

C++ exception with description
> Error: 22000
> Error while communicating with S3
> DETAIL: aws-s3-bucket-name: mybucket
> INTERNAL DETAIL: aws-s3-bucket-name: mybucket
thrown in the test body.

The FormatCxxExceptionMessage function will detect if the description contains any newline characters. If it contains no newlines, keep the logic as is it was previously (i.e. print the error message on the same line). If the description contains newlines, print the exception with newlines in it and replace every \n by \n> before printing (of course, with special handling to correctly handle the potential presence/absence of a trailing \n).

google-cla[bot] commented 9 months ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

derekmauro commented 4 months ago

https://github.com/google/googletest/issues/4387#issuecomment-1915528101