Add meaningful test failure messages

pull/737/head
Jeffrey Walton 2018-11-05 21:26:16 -05:00
parent 8b13c2a8d0
commit 5a36cd54bd
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 22 additions and 12 deletions

View File

@ -81,6 +81,7 @@ std::string TrimSpace(std::string str)
static void OutputTestData(const TestData &v) static void OutputTestData(const TestData &v)
{ {
std::cerr << "\n";
for (TestData::const_iterator i = v.begin(); i != v.end(); ++i) for (TestData::const_iterator i = v.begin(); i != v.end(); ++i)
{ {
std::cerr << i->first << ": " << i->second << std::endl; std::cerr << i->first << ": " << i->second << std::endl;
@ -99,9 +100,13 @@ static void SignalUnknownAlgorithmError(const std::string& algType)
throw Exception(Exception::OTHER_ERROR, "Unknown algorithm " + algType + " during validation test"); throw Exception(Exception::OTHER_ERROR, "Unknown algorithm " + algType + " during validation test");
} }
static void SignalTestError() static void SignalTestError(const char* msg = NULLPTR)
{ {
OutputTestData(*s_currentTestData); OutputTestData(*s_currentTestData);
if (msg)
throw Exception(Exception::OTHER_ERROR, msg);
else
throw Exception(Exception::OTHER_ERROR, "Unexpected error during validation test"); throw Exception(Exception::OTHER_ERROR, "Unexpected error during validation test");
} }
@ -115,7 +120,10 @@ const std::string & GetRequiredDatum(const TestData &data, const char *name)
{ {
TestData::const_iterator i = data.find(name); TestData::const_iterator i = data.find(name);
if (i == data.end()) if (i == data.end())
SignalTestError(); {
std::string msg("Required datum \"" + std::string(name) + "\" missing");
SignalTestError(msg.c_str());
}
return i->second; return i->second;
} }
@ -383,7 +391,8 @@ void TestSignatureScheme(TestData &v)
} }
else else
{ {
SignalTestError(); std::string msg("Unknown signature test \"" + test + "\"");
SignalTestError(msg.c_str());
CRYPTOPP_ASSERT(false); CRYPTOPP_ASSERT(false);
} }
} }
@ -429,7 +438,8 @@ void TestAsymmetricCipher(TestData &v)
} }
else else
{ {
SignalTestError(); std::string msg("Unknown asymmetric cipher test \"" + test + "\"");
SignalTestError(msg.c_str());
CRYPTOPP_ASSERT(false); CRYPTOPP_ASSERT(false);
} }
} }
@ -605,8 +615,8 @@ void TestSymmetricCipher(TestData &v, const NameValuePairs &overrideParameters)
} }
else else
{ {
std::cout << "\nunexpected test name\n"; std::string msg("Unknown symmetric cipher test \"" + test + "\"");
SignalTestError(); SignalTestError(msg.c_str());
} }
} }
@ -695,8 +705,8 @@ void TestAuthenticatedSymmetricCipher(TestData &v, const NameValuePairs &overrid
} }
else else
{ {
std::cout << "\nunexpected test name\n"; std::string msg("Unknown authenticated symmetric cipher test \"" + test + "\"");
SignalTestError(); SignalTestError(msg.c_str());
} }
} }
@ -747,8 +757,8 @@ void TestDigestOrMAC(TestData &v, bool testDigest)
} }
else else
{ {
SignalTestError(); std::string msg("Unknown digest or mac test \"" + test + "\"");
CRYPTOPP_ASSERT(false); SignalTestError(msg.c_str());
} }
} }
@ -811,7 +821,7 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
std::string::size_type pos = line.find(':'); std::string::size_type pos = line.find(':');
if (pos == std::string::npos) if (pos == std::string::npos)
SignalTestError(); SignalTestError("Unable to parse name/value pair");
name = TrimSpace(line.substr(0, pos)); name = TrimSpace(line.substr(0, pos));
line = TrimSpace(line.substr(pos + 1)); line = TrimSpace(line.substr(pos + 1));