[isoltest] Prints bytes result if expectations mismatch.

This commit is contained in:
Erik Kundt 2019-07-21 16:15:02 +02:00
parent 07051f41d2
commit 38285b33d7
3 changed files with 31 additions and 6 deletions

View File

@ -205,3 +205,24 @@ string BytesUtils::formatString(bytes const& _bytes, size_t _cutOff) const
return os.str();
}
string BytesUtils::formatRawBytes(bytes const& _bytes)
{
if (_bytes.empty())
return "[]";
stringstream os;
auto it = _bytes.begin();
for (size_t i = 0; i < _bytes.size(); i += 32)
{
bytes byteRange{it, it + 32};
os << " " << byteRange;
it += 32;
if (it != _bytes.end())
os << endl;
}
return os.str();
}

View File

@ -91,6 +91,11 @@ public:
/// a hexString value.
static std::string formatHexString(bytes const& _bytes);
/// Returns a string representation of given _bytes. Adds a newline
/// every 32 bytes to increase readability.
/// Used to print returned bytes from function calls to the commandline.
static std::string formatRawBytes(bytes const& _bytes);
/// Converts \param _bytes to a soltest-compliant and human-readable
/// string representation of a byte array which is assumed to hold
/// a string value.

View File

@ -218,6 +218,7 @@ string TestFunctionCall::formatBytesParameters(
" does not match the one inferred from ABI."
);
}
_errorReporter.warning("The call to \"" + _signature + "\" returned \n" + BytesUtils::formatRawBytes(_bytes));
/// Prints obtained result if it does not match the expectation
/// and prints the expected result otherwise.
@ -289,14 +290,12 @@ string TestFunctionCall::formatRawParameters(
stringstream os;
for (auto const& param: _params)
{
if (param.format.newline)
os << endl << _linePrefix << "// ";
os << param.rawString;
if (&param != &_params.back())
if (!param.rawString.empty())
{
if (param.format.newline)
os << ",";
else
os << endl << _linePrefix << "// ";
os << param.rawString;
if (&param != &_params.back())
os << ", ";
}
}