Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Errors for string comparisons to show non-printable control characters as C escape codes #1433
Conversation
| for (size_t i = 0; i < str_size; i++) | ||
| { | ||
| unsigned char c = (unsigned char) buffer_[i]; | ||
| if ((c >= 0x07) && (c <= 0x0D)) |
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?
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?
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?
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?
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.
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.
jgonzalezdr
Nov 16, 2020
Author
Contributor
What do you think about the new refactoring?
What do you think about the new refactoring?
|
Much better. Still a bit large... but good enough for now. Tnx! |
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.