From 53ce80ce916d3cb1e3b28562cc2a27229e8afea7 Mon Sep 17 00:00:00 2001 From: Frank Benkstein Date: Thu, 11 Oct 2018 19:33:12 +0200 Subject: [PATCH] better output on TestError (#4979) Print a slightly better error message when a TestError fails. --- tests/test.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/test.cpp b/tests/test.cpp index d7357234b..a02547655 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -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() {