Skip to content

Commit 80f6a13

Browse files
authored
Merge pull request #13075 from ethereum/add-more-info-to-failed-semantic-tests
Print settings options such evmVersion and optimize in isoltest/soltest failed test logs.
2 parents 01a794d + f15e53c commit 80f6a13

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

test/Common.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,20 @@
2020
#include <iostream>
2121
#include <test/Common.h>
2222
#include <test/EVMHost.h>
23+
#include <test/libsolidity/util/SoltestErrors.h>
2324

2425
#include <libsolutil/Assertions.h>
26+
#include <libsolutil/StringUtils.h>
2527
#include <boost/algorithm/string.hpp>
2628
#include <boost/filesystem.hpp>
2729
#include <boost/program_options.hpp>
30+
#include <range/v3/all.hpp>
2831

2932
namespace fs = boost::filesystem;
3033
namespace po = boost::program_options;
3134

35+
using namespace std;
36+
3237
namespace solidity::test
3338
{
3439

@@ -207,6 +212,41 @@ bool CommonOptions::parse(int argc, char const* const* argv)
207212
return true;
208213
}
209214

215+
string CommonOptions::toString(vector<string> const& _selectedOptions) const
216+
{
217+
if (_selectedOptions.empty())
218+
return "";
219+
220+
auto boolToString = [](bool _value) -> string { return _value ? "true" : "false"; };
221+
// Using std::map to avoid if-else/switch-case block
222+
map<string, string> optionValueMap = {
223+
{"evmVersion", evmVersion().name()},
224+
{"optimize", boolToString(optimize)},
225+
{"useABIEncoderV1", boolToString(useABIEncoderV1)},
226+
{"batch", to_string(selectedBatch + 1) + "/" + to_string(batches)},
227+
{"ewasm", boolToString(ewasm)},
228+
{"enforceCompileToEwasm", boolToString(enforceCompileToEwasm)},
229+
{"enforceGasTest", boolToString(enforceGasTest)},
230+
{"enforceGasTestMinValue", enforceGasTestMinValue.str()},
231+
{"disableSemanticTests", boolToString(disableSemanticTests)},
232+
{"disableSMT", boolToString(disableSMT)},
233+
{"showMessages", boolToString(showMessages)},
234+
{"showMetadata", boolToString(showMetadata)}
235+
};
236+
237+
soltestAssert(ranges::all_of(_selectedOptions, [&optionValueMap](string const& _option) { return optionValueMap.count(_option) > 0; }));
238+
239+
vector<string> optionsWithValues = _selectedOptions |
240+
ranges::views::transform([&optionValueMap](string const& _option) { return _option + "=" + optionValueMap.at(_option); }) |
241+
ranges::to<vector>();
242+
243+
return solidity::util::joinHumanReadable(optionsWithValues);
244+
}
245+
246+
void CommonOptions::printSelectedOptions(ostream& _stream, string const& _linePrefix, vector<string> const& _selectedOptions) const
247+
{
248+
_stream << _linePrefix << "Run Settings: " << toString(_selectedOptions) << endl;
249+
}
210250

211251
langutil::EVMVersion CommonOptions::evmVersion() const
212252
{

test/Common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ struct CommonOptions
8181
// Throws a ConfigException on error
8282
virtual void validate() const;
8383

84+
/// @returns string with a key=value list of the options separated by comma
85+
/// Ex.: "evmVersion=london, optimize=true, useABIEncoderV1=false"
86+
virtual std::string toString(std::vector<std::string> const& _selectedOptions) const;
87+
/// Helper to print the value of settings used
88+
virtual void printSelectedOptions(std::ostream& _stream, std::string const& _linePrefix, std::vector<std::string> const& _selectedOptions) const;
89+
8490
static CommonOptions const& get();
8591
static void setSingleton(std::unique_ptr<CommonOptions const>&& _instance);
8692

test/libsolidity/SemanticTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,14 @@ TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePref
315315
throw;
316316
}
317317
}
318+
319+
if (result != TestResult::Success)
320+
solidity::test::CommonOptions::get().printSelectedOptions(
321+
_stream,
322+
_linePrefix,
323+
{"evmVersion", "optimize", "useABIEncoderV1", "batch"}
324+
);
325+
318326
return result;
319327
}
320328

0 commit comments

Comments
 (0)