Sitelet https://web.archive.org/web/20201207074337/https://github.com/cpputest/cpputest/pull/1433
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors for string comparisons to show non-printable control characters as C escape codes #1433

Merged
merged 2 commits into from Nov 18, 2020

Conversation

@jgonzalezdr
Copy link
Contributor

@jgonzalezdr jgonzalezdr commented Nov 13, 2020

When a string comparison (e.g. STRCMP_EQUAL) fails and the string contains non-printable characters (newlines, tabs, or even worse, ANSI color escape codes!) it's a mess to locate in the error log exactly where the comparison failed.

To avoid this, this PR makes cpputest replace non-printable characters with their corresponding C escape cores when printing the error log, making it easier to compare both strings.

@coveralls
Copy link

@coveralls coveralls commented Nov 13, 2020 •

Coverage Status

Coverage increased (+0.0006%) to 99.834% when pulling eff6de1 on jgonzalezdr:printable-text-comparisons into 846b0ad on cpputest:master.

for (size_t i = 0; i < str_size; i++)
{
unsigned char c = (unsigned char) buffer_[i];
if ((c >= 0x07) && (c <= 0x0D))

This comment has been minimized.

@basvodde

basvodde Nov 15, 2020
Member

Can you extract this if in a separate method so it is more clear what this is about... and to remove the duplication with the if below?

This comment has been minimized.

@jgonzalezdr

jgonzalezdr Nov 16, 2020
Author Contributor

I don't get your intention. Do you mean that you'd like the if conditions to be extracted as separate methods (like if (hasShortEscapeCode(c)) ...? Or do ypu want the if/else if/else statements to be extracted to a couple of methods like adjustPrintableSize()/writePrintableChar and in this method just keep the two loops calling these methods?

This comment has been minimized.

@basvodde

basvodde Nov 16, 2020
Member

Start with extracting the condition as they are and cryptic and duplicate. If the function is too long, we can look at extracting other parts too.

This comment has been minimized.

@jgonzalezdr

jgonzalezdr Nov 16, 2020
Author Contributor

What do you think about the new refactoring?

@basvodde
Copy link
Member

@basvodde basvodde commented Nov 18, 2020

Much better. Still a bit large... but good enough for now. Tnx!

@basvodde basvodde merged commit 887621d into cpputest:master Nov 18, 2020
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.0006%) to 99.834%
Details
@jgonzalezdr jgonzalezdr deleted the jgonzalezdr:printable-text-comparisons branch Nov 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.