better output on TestError (#4979)

Print a slightly better error message when a TestError fails.
This commit is contained in:
Frank Benkstein 2018-10-11 19:33:12 +02:00 committed by Wouter van Oortmerssen
parent 233976c821
commit 53ce80ce91
1 changed files with 24 additions and 5 deletions

View File

@ -1166,16 +1166,35 @@ void FuzzTest2() {
}
// Test that parser errors are actually generated.
void TestError(const char *src, const char *error_substr,
bool strict_json = false) {
void TestError_(const char *src, const char *error_substr, bool strict_json,
const char *file, int line, const char *func) {
flatbuffers::IDLOptions opts;
opts.strict_json = strict_json;
flatbuffers::Parser parser(opts);
TEST_EQ(parser.Parse(src), false); // Must signal error
// Must be the error we're expecting
TEST_NOTNULL(strstr(parser.error_.c_str(), error_substr));
if (parser.Parse(src)) {
TestFail("true", "false",
("parser.Parse(\"" + std::string(src) + "\")").c_str(), file, line,
func);
} else if (!strstr(parser.error_.c_str(), error_substr)) {
TestFail(parser.error_.c_str(), error_substr,
("parser.Parse(\"" + std::string(src) + "\")").c_str(), file, line,
func);
}
}
void TestError_(const char *src, const char *error_substr, const char *file,
int line, const char *func) {
TestError_(src, error_substr, false, file, line, func);
}
#ifdef WIN32
# define TestError(src, ...) \
TestError_(src, __VA_ARGS__, __FILE__, __LINE__, __FUNCTION__)
#else
# define TestError(src, ...) \
TestError_(src, __VA_ARGS__, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#endif
// Test that parsing errors occur as we'd expect.
// Also useful for coverage, making sure these paths are run.
void ErrorTest() {