From f15e53ce4dd3ba637c9b78a371623e5147c6d673 Mon Sep 17 00:00:00 2001 From: Matheus Aguiar Date: Fri, 27 May 2022 14:55:41 -0300 Subject: [PATCH] Added printSelectedOptions and toString as method of CommonOptions and used the former to print settings in failed semanticTests. --- test/Common.cpp | 40 +++++++++++++++++++++++++++++++ test/Common.h | 6 +++++ test/libsolidity/SemanticTest.cpp | 8 +++++++ 3 files changed, 54 insertions(+) diff --git a/test/Common.cpp b/test/Common.cpp index cbe806876..7cd869934 100644 --- a/test/Common.cpp +++ b/test/Common.cpp @@ -20,15 +20,20 @@ #include #include #include +#include #include +#include #include #include #include +#include namespace fs = boost::filesystem; namespace po = boost::program_options; +using namespace std; + namespace solidity::test { @@ -207,6 +212,41 @@ bool CommonOptions::parse(int argc, char const* const* argv) return true; } +string CommonOptions::toString(vector const& _selectedOptions) const +{ + if (_selectedOptions.empty()) + return ""; + + auto boolToString = [](bool _value) -> string { return _value ? "true" : "false"; }; + // Using std::map to avoid if-else/switch-case block + map optionValueMap = { + {"evmVersion", evmVersion().name()}, + {"optimize", boolToString(optimize)}, + {"useABIEncoderV1", boolToString(useABIEncoderV1)}, + {"batch", to_string(selectedBatch + 1) + "/" + to_string(batches)}, + {"ewasm", boolToString(ewasm)}, + {"enforceCompileToEwasm", boolToString(enforceCompileToEwasm)}, + {"enforceGasTest", boolToString(enforceGasTest)}, + {"enforceGasTestMinValue", enforceGasTestMinValue.str()}, + {"disableSemanticTests", boolToString(disableSemanticTests)}, + {"disableSMT", boolToString(disableSMT)}, + {"showMessages", boolToString(showMessages)}, + {"showMetadata", boolToString(showMetadata)} + }; + + soltestAssert(ranges::all_of(_selectedOptions, [&optionValueMap](string const& _option) { return optionValueMap.count(_option) > 0; })); + + vector optionsWithValues = _selectedOptions | + ranges::views::transform([&optionValueMap](string const& _option) { return _option + "=" + optionValueMap.at(_option); }) | + ranges::to(); + + return solidity::util::joinHumanReadable(optionsWithValues); +} + +void CommonOptions::printSelectedOptions(ostream& _stream, string const& _linePrefix, vector const& _selectedOptions) const +{ + _stream << _linePrefix << "Run Settings: " << toString(_selectedOptions) << endl; +} langutil::EVMVersion CommonOptions::evmVersion() const { diff --git a/test/Common.h b/test/Common.h index d57fe68b6..bd76cd0df 100644 --- a/test/Common.h +++ b/test/Common.h @@ -81,6 +81,12 @@ struct CommonOptions // Throws a ConfigException on error virtual void validate() const; + /// @returns string with a key=value list of the options separated by comma + /// Ex.: "evmVersion=london, optimize=true, useABIEncoderV1=false" + virtual std::string toString(std::vector const& _selectedOptions) const; + /// Helper to print the value of settings used + virtual void printSelectedOptions(std::ostream& _stream, std::string const& _linePrefix, std::vector const& _selectedOptions) const; + static CommonOptions const& get(); static void setSingleton(std::unique_ptr&& _instance); diff --git a/test/libsolidity/SemanticTest.cpp b/test/libsolidity/SemanticTest.cpp index c2c95324c..3ad191cee 100644 --- a/test/libsolidity/SemanticTest.cpp +++ b/test/libsolidity/SemanticTest.cpp @@ -315,6 +315,14 @@ TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePref throw; } } + + if (result != TestResult::Success) + solidity::test::CommonOptions::get().printSelectedOptions( + _stream, + _linePrefix, + {"evmVersion", "optimize", "useABIEncoderV1", "batch"} + ); + return result; }