CxxTest/cxxtest — comment on commit f50d7d67a41ba76c6c2db2e41e1619e0b99beae6
File:  line 0
By sorbits:

The motivation for making them visible would be when testing code like the sample below:

std::string tabs_to_spaces (std::string const& src, size_t tabSize)
{
return src;
}

std::string unix_linefeeds (std::string const& src)
{
return src;
}

class InvisibleCharTests : public CxxTest::TestSuite
{
public:
void test_invisible_char ()
{
TS_ASSERT_EQUALS(tabs_to_spaces("\ttest\n \ttest\n", 4), " test\n test\n");
TS_ASSERT_EQUALS(unix_linefeeds("test\r\ntest\r\n"), "test\ntest\n");
}
};

Without escaping at least `\t` and `\r`, the error output from the above failing tests would look like the correct output was produced (depending on terminal tab size and how it interprets `\r`).

The `\n` is less important to escape, but for example we could do a code indenter where we test how it handles lines with just whitespace. The amount of whitespace on these would also be invisible if `\n` is rendered as an actual newline.

Another reason to escape `\n` is to ensure the error output only takes up a single line — though the importance of this depends on build environment and formatter, e.g. I use the unix output and Makefiles with lots of parallel jobs, so if multiple build jobs output multi-line errors at the same time, I see intermixed output, but this is more a failure of `make`.