I have a C++ function which returns a multi-line std::string
. In the test-case for this, I compare each line against the known-value - something like:
std::string known = "good\netc";
std::string output = "bad\netc";
std::vector<std::string> knownvec;
pystring::splitlines(known, knownvec); // splits on \n
std::vector<std::string> outvec;
pystring::splitlines(output, outvec);
CHECK_EQUAL(osvec.size(), resvec.size());
for(unsigned int i = 0; i < std::min(outvec.size(), knownvec.size()); ++i)
CHECK_EQUAL(pystring::strip(outvec[i]), pystring::strip(knownvec[i]));
This works, but say a single new-line is added, all subsequent CHECK_EQUAL assertions fail, which is make the output hard to read
Is there a better way to compare the two strings, ideally in a nice, self-contained way (i.e not linking against giantdifflib, or writing the strings to a file and calling the diff
command!)
[Edit] I'm using OpenImageIO's rather simple unittest.h
The data being compared is mainly either YAML, or colour lookup tables. Here's an example test case - basically a few lines of headers, then lots of numbers:
Version 1
Format any
Type ...
LUT:
Pre {
0.0
0.1
...
1.0
}
3D {
0.0
0.1
...
1.0
}